Skip to content

Commit

Permalink
Merge branch 'tim/untkr' into 'master'
Browse files Browse the repository at this point in the history
maint(BREAKING): Remove remaining TKR prefixes in Swift types

See merge request TankerHQ/sdk-ios!254
  • Loading branch information
tux3 committed Jun 19, 2024
2 parents 3e29314 + 81dca32 commit 14c5a8d
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 44 deletions.
3 changes: 2 additions & 1 deletion Tanker/Headers/Storage/TKRDatastoreError.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion Tanker/Headers/Storage/TKRDatastoreOnConflict.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ typedef NS_ENUM(NSUInteger, TKRDatastoreOnConflict) {
TKRDatastoreOnConflictFail = 0,
TKRDatastoreOnConflictIgnore = 1,
TKRDatastoreOnConflictReplace = 2,
};
} NS_SWIFT_NAME(DatastoreOnConflict);
9 changes: 0 additions & 9 deletions Tanker/Headers/TKRCompletionHandlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion Tanker/Headers/TKRError.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 2 additions & 1 deletion Tanker/Headers/TKRLogEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Tanker/Headers/TKRVerificationMethodType.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ typedef NS_ENUM(NSUInteger, TKRVerificationMethodType) {
TKRVerificationMethodTypeE2ePassphrase,
TKRVerificationMethodTypePreverifiedOIDC,
TKRVerificationMethodTypeOIDCAuthorizationCode,
};
} NS_SWIFT_NAME(VerificationMethodType);
1 change: 1 addition & 0 deletions Tanker/Headers/Utils/TKRUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion Tanker/Sources/TKRStatus.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation

@objc public enum TKRStatus: UInt {
@objc(TKRStatus)
public enum Status: UInt {
case stopped
case ready
case identityRegistrationNeeded
Expand Down
20 changes: 10 additions & 10 deletions Tanker/Sources/TKRTanker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
])
}
Expand All @@ -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();
Expand All @@ -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?)
Expand Down Expand Up @@ -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?)
Expand Down Expand Up @@ -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?)
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions Tanker/Sources/TKRVerification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Tanker/Sources/Utils/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func resolvePromise(_ fut: OpaquePointer?, _ arg: UnsafeMutableRawPointer?) -> U
}

DispatchQueue.main.async(execute: {
let adapter = Unmanaged<AnyObject>.fromOpaque(arg!).takeRetainedValue() as! TKRAdapter;
let adapter = Unmanaged<AnyObject>.fromOpaque(arg!).takeRetainedValue() as! Adapter;
adapter(ptrValue, maybeErr);
});
return nil;
Expand All @@ -43,4 +43,4 @@ public func unwrapAndFreeExpected(_ expected: OpaquePointer) throws -> UnsafeMut
tanker_future_destroy(expected);

return ptr;
}
}
1 change: 1 addition & 0 deletions Tanker/Tests/TKRTestAdmin.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#import <PromiseKit/PromiseKit.h>

NS_SWIFT_NAME(TestAdmin)
@interface TKRTestAdmin : NSObject

// MARK: Class methods
Expand Down
6 changes: 3 additions & 3 deletions Tanker/Tests/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions Tanker/Tests/UnitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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";
})
}
Expand All @@ -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;
})
}
}
Expand Down

0 comments on commit 14c5a8d

Please sign in to comment.