diff --git a/Tanker/Headers/Storage/TKRDatastoreError.h b/Tanker/Headers/Storage/TKRDatastoreError.h index 4536848..291cd4e 100644 --- a/Tanker/Headers/Storage/TKRDatastoreError.h +++ b/Tanker/Headers/Storage/TKRDatastoreError.h @@ -8,6 +8,7 @@ typedef NS_ENUM(NSUInteger, TKRDatastoreError) { TKRDatastoreErrorDatabaseCorrupt = 5, TKRDatastoreErrorDatabaseTooRecent = 6, TKRDatastoreErrorConstraintFailed = 7, -}; +} NS_SWIFT_NAME(DatastoreError); +NS_SWIFT_NAME(DatastoreErrorDomain) FOUNDATION_EXPORT NSString* const TKRDatastoreErrorDomain; diff --git a/Tanker/Headers/Storage/TKRDatastoreOnConflict.h b/Tanker/Headers/Storage/TKRDatastoreOnConflict.h index 6bb757d..50a9ce8 100644 --- a/Tanker/Headers/Storage/TKRDatastoreOnConflict.h +++ b/Tanker/Headers/Storage/TKRDatastoreOnConflict.h @@ -2,4 +2,4 @@ typedef NS_ENUM(NSUInteger, TKRDatastoreOnConflict) { TKRDatastoreOnConflictFail = 0, TKRDatastoreOnConflictIgnore = 1, TKRDatastoreOnConflictReplace = 2, -}; +} NS_SWIFT_NAME(DatastoreOnConflict); diff --git a/Tanker/Headers/TKRCompletionHandlers.h b/Tanker/Headers/TKRCompletionHandlers.h index 4476278..f420cd9 100644 --- a/Tanker/Headers/TKRCompletionHandlers.h +++ b/Tanker/Headers/TKRCompletionHandlers.h @@ -53,15 +53,6 @@ typedef void (^TKRDecryptedStringHandler)(NSString* _Nullable decryptedString, N */ typedef void (^TKRErrorHandler)(NSError* _Nullable err); -/*! - @typedef TKRDeviceIDHandler - @brief Block which will be called with a device ID. - - @param deviceID the deviceID, or nil if an error occurred. - @param err the error which occurred, or nil. - */ -typedef void (^TKRDeviceIDHandler)(NSString* _Nullable deviceID, NSError* _Nullable err); - /*! @typedef TKRNonceHandler @brief Block which will be called with Nonce. diff --git a/Tanker/Headers/TKRError.h b/Tanker/Headers/TKRError.h index ee3683a..af6a208 100644 --- a/Tanker/Headers/TKRError.h +++ b/Tanker/Headers/TKRError.h @@ -19,6 +19,7 @@ typedef NS_ENUM(NSInteger, TKRError) { TKRErrorConflict = 13, TKRErrorUpgradeRequired = 14, TKRErrorIdentityAlreadyAttached = 15, -}; +} NS_SWIFT_NAME(Error); +NS_SWIFT_NAME(ErrorDomain) FOUNDATION_EXPORT NSString* const TKRErrorDomain; diff --git a/Tanker/Headers/TKRLogEntry.h b/Tanker/Headers/TKRLogEntry.h index 6529e46..ce12fa5 100644 --- a/Tanker/Headers/TKRLogEntry.h +++ b/Tanker/Headers/TKRLogEntry.h @@ -5,8 +5,9 @@ typedef NS_ENUM(NSUInteger, TKRLogLevel) { TKRLogLevelInfo, TKRLogLevelWarning, TKRLogLevelError -}; +} NS_SWIFT_NAME(LogLevel); +NS_SWIFT_NAME(LogEntry) @interface TKRLogEntry : NSObject @property NSString* category; diff --git a/Tanker/Headers/TKRVerificationMethodType.h b/Tanker/Headers/TKRVerificationMethodType.h index 004a603..8f7e2cd 100644 --- a/Tanker/Headers/TKRVerificationMethodType.h +++ b/Tanker/Headers/TKRVerificationMethodType.h @@ -15,4 +15,4 @@ typedef NS_ENUM(NSUInteger, TKRVerificationMethodType) { TKRVerificationMethodTypeE2ePassphrase, TKRVerificationMethodTypePreverifiedOIDC, TKRVerificationMethodTypeOIDCAuthorizationCode, -}; +} NS_SWIFT_NAME(VerificationMethodType); diff --git a/Tanker/Headers/Utils/TKRUtils.h b/Tanker/Headers/Utils/TKRUtils.h index 740ca76..5845f2a 100644 --- a/Tanker/Headers/Utils/TKRUtils.h +++ b/Tanker/Headers/Utils/TKRUtils.h @@ -22,6 +22,7 @@ @end // Internal block used to wrap C futures +NS_SWIFT_NAME(Adapter) typedef void (^TKRAdapter)(NSNumber* _Nullable ptrValue, NSError* _Nullable err); void TKR_runOnMainQueue(void (^_Nonnull block)(void)); diff --git a/Tanker/Sources/TKRStatus.swift b/Tanker/Sources/TKRStatus.swift index 035c1a2..2965d02 100644 --- a/Tanker/Sources/TKRStatus.swift +++ b/Tanker/Sources/TKRStatus.swift @@ -1,6 +1,7 @@ import Foundation -@objc public enum TKRStatus: UInt { +@objc(TKRStatus) +public enum Status: UInt { case stopped case ready case identityRegistrationNeeded diff --git a/Tanker/Sources/TKRTanker.swift b/Tanker/Sources/TKRTanker.swift index eabda74..9dec6ba 100644 --- a/Tanker/Sources/TKRTanker.swift +++ b/Tanker/Sources/TKRTanker.swift @@ -19,7 +19,7 @@ public extension Tanker { @objc static func prehashPassword(_ password: String) throws -> String { if password.isEmpty { - throw NSError(domain: "TKRErrorDomain", code: TKRError.invalidArgument.rawValue, userInfo: [ + throw NSError(domain: "TKRErrorDomain", code: Error.invalidArgument.rawValue, userInfo: [ NSLocalizedDescriptionKey: "Cannot hash empty password" ]) } @@ -39,12 +39,12 @@ public extension Tanker { } @objc - func start(identity: String, completionHandler handler: @escaping (_ status: TKRStatus, _ error: NSError?) -> ()) { - let adapter: TKRAdapter = {(status: NSNumber?, error: (any Error)?) in + func start(identity: String, completionHandler handler: @escaping (_ status: Status, _ error: NSError?) -> ()) { + let adapter: Adapter = {(status: NSNumber?, error: (any Swift.Error)?) in if (error != nil) { - handler(TKRStatus(rawValue: 0)!, error as NSError?); + handler(Status(rawValue: 0)!, error as NSError?); } else { - handler(TKRStatus(rawValue: status!.uintValue)!, nil); + handler(Status(rawValue: status!.uintValue)!, nil); } }; let bridgeRetainedAdapter = Unmanaged.passRetained(adapter as AnyObject).toOpaque(); @@ -67,7 +67,7 @@ public extension Tanker { func registerIdentity(verification: Verification, options: VerificationOptions, completionHandler handler: @escaping (_ sessionToken: String?, _ error: NSError?) -> ()) { - let adapter: TKRAdapter = {(tokenPtrVal: NSNumber?, error: (any Error)?) in + let adapter: Adapter = {(tokenPtrVal: NSNumber?, error: (any Swift.Error)?) in let tokenPtr = UnsafeRawPointer(bitPattern: tokenPtrVal?.uintValue ?? 0) if (error != nil || tokenPtr == nil) { handler(nil, error as NSError?) @@ -104,7 +104,7 @@ public extension Tanker { func verifyIdentity(verification: Verification, options: VerificationOptions, completionHandler handler: @escaping (_ sessionToken: String?, _ error: NSError?) -> ()) { - let adapter: TKRAdapter = {(tokenPtrVal: NSNumber?, error: (any Error)?) in + let adapter: Adapter = {(tokenPtrVal: NSNumber?, error: (any Swift.Error)?) in let tokenPtr = UnsafeRawPointer(bitPattern: tokenPtrVal?.uintValue ?? 0) if (error != nil || tokenPtr == nil) { handler(nil, error as NSError?) @@ -141,7 +141,7 @@ public extension Tanker { func setVerificationMethod(verification: Verification, options: VerificationOptions, completionHandler handler: @escaping (_ sessionToken: String?, _ error: NSError?) -> ()) { - let adapter: TKRAdapter = {(tokenPtrVal: NSNumber?, error: (any Error)?) in + let adapter: Adapter = {(tokenPtrVal: NSNumber?, error: (any Swift.Error)?) in let tokenPtr = UnsafeRawPointer(bitPattern: tokenPtrVal?.uintValue ?? 0) if (error != nil || tokenPtr == nil) { handler(nil, error as NSError?) @@ -169,7 +169,7 @@ public extension Tanker { @objc func verifyProvisionalIdentity(verification: Verification, completionHandler handler: @escaping (_ error: NSError?) -> ()) { - let adapter: TKRAdapter = {(_unused: NSNumber?, error: (any Error)?) in + let adapter: Adapter = {(_unused: NSNumber?, error: (any Swift.Error)?) in handler(error as NSError?) } let bridgeRetainedAdapter = Unmanaged.passRetained(adapter as AnyObject).toOpaque() @@ -188,7 +188,7 @@ public extension Tanker { func authenticateWithIDP(providerID: String, cookie: String, completionHandler handler: @escaping (_ verification: Verification?, _ error: NSError?) -> ()) { - let adapter: TKRAdapter = {(verifPtrValue: NSNumber?, error: (any Error)?) in + let adapter: Adapter = {(verifPtrValue: NSNumber?, error: (any Swift.Error)?) in if (error != nil) { handler(nil, error as NSError?) } else { diff --git a/Tanker/Sources/TKRVerification.swift b/Tanker/Sources/TKRVerification.swift index 5834a13..21a1469 100644 --- a/Tanker/Sources/TKRVerification.swift +++ b/Tanker/Sources/TKRVerification.swift @@ -79,37 +79,37 @@ extension VerificationData { verif.version = Self.C_VERIFICATION_VERSION; switch self { case .passphrase(let passphrase): - verif.verification_method_type = UInt8(TKRVerificationMethodType.passphrase.rawValue); + verif.verification_method_type = UInt8(VerificationMethodType.passphrase.rawValue); verif.passphrase = (passphrase as NSString).utf8String; case .e2ePassphrase(let passphrase): - verif.verification_method_type = UInt8(TKRVerificationMethodType.e2ePassphrase.rawValue); + verif.verification_method_type = UInt8(VerificationMethodType.e2ePassphrase.rawValue); verif.e2e_passphrase = (passphrase as NSString).utf8String; case .verificationKey(let key): - verif.verification_method_type = UInt8(TKRVerificationMethodType.verificationKey.rawValue); + verif.verification_method_type = UInt8(VerificationMethodType.verificationKey.rawValue); verif.verification_key = (key.value as NSString).utf8String; case .email(let emailVerif): - verif.verification_method_type = UInt8(TKRVerificationMethodType.email.rawValue); + verif.verification_method_type = UInt8(VerificationMethodType.email.rawValue); verif.email_verification.email = (emailVerif.email as NSString).utf8String; verif.email_verification.verification_code = (emailVerif.verificationCode as NSString).utf8String; case .oidcIDToken(let token): - verif.verification_method_type = UInt8(TKRVerificationMethodType.oidcidToken.rawValue); + verif.verification_method_type = UInt8(VerificationMethodType.oidcidToken.rawValue); verif.oidc_id_token = (token as NSString).utf8String; case .phoneNumber(let phoneVerif): - verif.verification_method_type = UInt8(TKRVerificationMethodType.phoneNumber.rawValue); + verif.verification_method_type = UInt8(VerificationMethodType.phoneNumber.rawValue); verif.phone_number_verification.phone_number = (phoneVerif.phoneNumber as NSString).utf8String; verif.phone_number_verification.verification_code = (phoneVerif.verificationCode as NSString).utf8String; case .preverifiedEmail(let email): - verif.verification_method_type = UInt8(TKRVerificationMethodType.preverifiedEmail.rawValue); + verif.verification_method_type = UInt8(VerificationMethodType.preverifiedEmail.rawValue); verif.preverified_email = (email as NSString).utf8String; case .preverifiedPhoneNumber(let phoneNumber): - verif.verification_method_type = UInt8(TKRVerificationMethodType.preverifiedPhoneNumber.rawValue); + verif.verification_method_type = UInt8(VerificationMethodType.preverifiedPhoneNumber.rawValue); verif.preverified_phone_number = (phoneNumber as NSString).utf8String; case .preverifiedOIDC(let oidcVerif): - verif.verification_method_type = UInt8(TKRVerificationMethodType.preverifiedOIDC.rawValue); + verif.verification_method_type = UInt8(VerificationMethodType.preverifiedOIDC.rawValue); verif.preverified_oidc_verification.subject = (oidcVerif.subject as NSString).utf8String; verif.preverified_oidc_verification.provider_id = (oidcVerif.providerID as NSString).utf8String; case .oidcAuthorizationCode(let oidcVerif): - verif.verification_method_type = UInt8(TKRVerificationMethodType.oidcAuthorizationCode.rawValue); + verif.verification_method_type = UInt8(VerificationMethodType.oidcAuthorizationCode.rawValue); verif.oidc_authorization_code_verification.provider_id = (oidcVerif.providerID as NSString).utf8String; verif.oidc_authorization_code_verification.authorization_code = (oidcVerif.authorizationCode as NSString).utf8String; verif.oidc_authorization_code_verification.state = (oidcVerif.state as NSString).utf8String; diff --git a/Tanker/Sources/Utils/Utils.swift b/Tanker/Sources/Utils/Utils.swift index f76f1bf..156a4ab 100644 --- a/Tanker/Sources/Utils/Utils.swift +++ b/Tanker/Sources/Utils/Utils.swift @@ -26,7 +26,7 @@ func resolvePromise(_ fut: OpaquePointer?, _ arg: UnsafeMutableRawPointer?) -> U } DispatchQueue.main.async(execute: { - let adapter = Unmanaged.fromOpaque(arg!).takeRetainedValue() as! TKRAdapter; + let adapter = Unmanaged.fromOpaque(arg!).takeRetainedValue() as! Adapter; adapter(ptrValue, maybeErr); }); return nil; @@ -43,4 +43,4 @@ public func unwrapAndFreeExpected(_ expected: OpaquePointer) throws -> UnsafeMut tanker_future_destroy(expected); return ptr; -} \ No newline at end of file +} diff --git a/Tanker/Tests/TKRTestAdmin.h b/Tanker/Tests/TKRTestAdmin.h index 94b4ee2..4b8e5ea 100644 --- a/Tanker/Tests/TKRTestAdmin.h +++ b/Tanker/Tests/TKRTestAdmin.h @@ -2,6 +2,7 @@ #import +NS_SWIFT_NAME(TestAdmin) @interface TKRTestAdmin : NSObject // MARK: Class methods diff --git a/Tanker/Tests/TestHelpers.swift b/Tanker/Tests/TestHelpers.swift index a62d01b..f79e59d 100644 --- a/Tanker/Tests/TestHelpers.swift +++ b/Tanker/Tests/TestHelpers.swift @@ -47,7 +47,7 @@ func createTankerOptions(url: String, appID: String) -> TankerOptions func startAndRegister(_ tanker: Tanker, _ identity: String, _ verification: Verification) { let err = hangWithResolver({ (resolver: _!) in - tanker.start(withIdentity: identity, completionHandler: { (status: TKRStatus, err: Error?) in + tanker.start(withIdentity: identity, completionHandler: { (status: Status, err: Swift.Error?) in if (err != nil) { resolver(err); } else { @@ -62,7 +62,7 @@ func startAndRegister(_ tanker: Tanker, _ identity: String, _ verification: Veri func start(_ tanker: Tanker, _ identity: String) { let err = hangWithResolver({ (resolver: _!) in - tanker.start(withIdentity: identity, completionHandler: { (status: TKRStatus, err: Error?) in + tanker.start(withIdentity: identity, completionHandler: { (status: Status, err: Swift.Error?) in if (err == nil) { expect(status) == .ready; } @@ -99,7 +99,7 @@ class TankerFunctionalQuickSpec: QuickSpec { ] ]; - let admin = TKRTestAdmin( + let admin = TestAdmin( url: getEnv("TANKER_MANAGEMENT_API_URL"), appManagementToken: getEnv("TANKER_MANAGEMENT_API_ACCESS_TOKEN"), environmentName: getEnv("TANKER_MANAGEMENT_API_DEFAULT_ENVIRONMENT_NAME") diff --git a/Tanker/Tests/UnitTests.swift b/Tanker/Tests/UnitTests.swift index 9a145a9..3b2bd71 100644 --- a/Tanker/Tests/UnitTests.swift +++ b/Tanker/Tests/UnitTests.swift @@ -14,8 +14,8 @@ class UnitTests: QuickSpec { expect { let _: String = try Tanker.prehashPassword("") }.to(throwError { (error: NSError) in - expect(error.domain).to(equal(TKRErrorDomain)); - expect(error.code) == TKRError.invalidArgument.rawValue; + expect(error.domain).to(equal(ErrorDomain)); + expect(error.code) == Error.invalidArgument.rawValue; expect(error.localizedDescription) == "Cannot hash empty password"; }) } @@ -39,8 +39,8 @@ class UnitTests: QuickSpec { tankerOptions.appID = ",,"; expect { try Tanker(options:tankerOptions) }.to(throwError { (error: NSError) in - expect(error.domain).to(equal(TKRErrorDomain)); - expect(error.code) == TKRError.invalidArgument.rawValue; + expect(error.domain).to(equal(ErrorDomain)); + expect(error.code) == Error.invalidArgument.rawValue; }) } }