-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from eu-digital-identity-wallet/develop
Develop
- Loading branch information
Showing
22 changed files
with
382 additions
and
178 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
Sources/MdocDataModel18013/DeviceEngagement/ConnectionMethodHttp.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// ConnectionMethodHttp.swift | ||
// ScytalesDigitalWallet | ||
|
||
import Foundation | ||
import SwiftCBOR | ||
|
||
public struct ConnectionMethodHttp { | ||
public let uriWebsite: String | ||
|
||
public static let METHOD_TYPE: UInt64 = 4 | ||
static let METHOD_MAX_VERSION: UInt64 = 1 | ||
static let OPTION_KEY_URI_WEBSITE: UInt64 = 0 | ||
|
||
// Creates a new connection method for REST API. @param uriWebsite the URL for the website. | ||
init(_ uriWebsite: String) { | ||
self.uriWebsite = uriWebsite | ||
} | ||
} | ||
|
||
extension ConnectionMethodHttp: CBORDecodable { | ||
public init?(cbor: CBOR) { | ||
guard case let .array(arr) = cbor, arr.count == 3 else { return nil } | ||
guard case let .unsignedInt(type) = arr[0], case let .unsignedInt(version) = arr[1] else { return nil } // throw AppError.cbor("First two items are not numbers") } | ||
guard case let .map(options) = arr[2] else { return nil } // throw AppError.cbor("Third item is not a map") } | ||
guard type == Self.METHOD_TYPE else { return nil } // throw AppError.cbor("Unexpected method type \(type)") } | ||
guard version <= Self.METHOD_MAX_VERSION else { return nil } //throw AppError.cbor("Unsupported options version \(version)") } | ||
guard case let .utf8String(url) = options[.unsignedInt(Self.OPTION_KEY_URI_WEBSITE)] else { return nil } // throw AppError.cbor("Options does not contain uri of website") } | ||
self.init(url) | ||
} | ||
} | ||
|
||
extension ConnectionMethodHttp: CBOREncodable { | ||
public func toCBOR(options: CBOROptions) -> CBOR { | ||
.array([.unsignedInt(Self.METHOD_TYPE), .unsignedInt(Self.METHOD_MAX_VERSION), .map([.unsignedInt(Self.OPTION_KEY_URI_WEBSITE): .utf8String(uriWebsite)])]) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
Sources/MdocDataModel18013/DeviceEngagement/OriginInfoWebsite.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// OriginInfoWebsite.swift | ||
// ScytalesDigitalWallet | ||
|
||
import Foundation | ||
import SwiftCBOR | ||
|
||
public struct OriginInfoWebsite { | ||
public static let ENGAGEMENT_VERSION_1_1 = "1.1" | ||
// * The constant used to specify how the current engagement structure is delivered. | ||
static let CAT_DELIVERY: UInt64 = 0 | ||
// * The constant used to specify how the other party engagement structure has been received. | ||
static let CAT_RECEIVE: UInt64 = 1 | ||
static let TYPE: UInt64 = 100 | ||
private let mCat: UInt64 | ||
private let mBaseUrl: String | ||
public init(baseUrl: String, cat: UInt64 = 1) { | ||
mCat = cat | ||
mBaseUrl = baseUrl | ||
} | ||
} | ||
|
||
extension OriginInfoWebsite: CBOREncodable { | ||
public func toCBOR(options: CBOROptions) -> CBOR { | ||
.map(["cat": .unsignedInt(mCat), "type": .unsignedInt(Self.TYPE), "Details": .map(["baseUrl": .utf8String(mBaseUrl)])]) | ||
} | ||
} | ||
|
||
extension OriginInfoWebsite: CBORDecodable { | ||
public init?(cbor: CBOR) { | ||
guard case let .map(tS) = cbor else { return nil } // throw AppError.cbor("Top-level CBOR is not an map")} | ||
guard case let .unsignedInt(nsCat) = tS["cat"] else { return nil } // throw AppError.cbor("cat not found")}; | ||
guard case let .map(nsDetails) = tS["Details"], case let .utf8String(nsUrl) = nsDetails["baseUrl"] else { return nil } //throw AppError.cbor("CBOR does not contain a url field")}; | ||
self.init(baseUrl: nsUrl, cat: nsCat) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.