diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..a1ef0ca --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +5.0.2 diff --git a/Package@swift-4.swift b/Package@swift-4.swift new file mode 100644 index 0000000..d95cdd3 --- /dev/null +++ b/Package@swift-4.swift @@ -0,0 +1,32 @@ +// swift-tools-version:4.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + + +import PackageDescription + +let package = Package( + name: "Kitura-CredentialsJWT", + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "CredentialsJWT", + targets: ["CredentialsJWT"] + ) + ], + dependencies: [ + .package(url: "https://github.com/IBM-Swift/Kitura-Credentials.git", from: "2.4.0"), + .package(url: "https://github.com/IBM-Swift/Swift-JWT.git", from: "3.1.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "CredentialsJWT", + dependencies: ["Credentials", "SwiftJWT"] + ), +// .testTarget( +// name: "CredentialsJWTTests", +// dependencies: ["CredentialsJWT"] +// ) + ] +) diff --git a/Sources/CredentialsJWT/AnyHashableMetatype.swift b/Sources/CredentialsJWT/AnyHashableMetatype.swift index 8680689..95b2776 100644 --- a/Sources/CredentialsJWT/AnyHashableMetatype.swift +++ b/Sources/CredentialsJWT/AnyHashableMetatype.swift @@ -25,7 +25,13 @@ struct AnyHashableMetatype: Hashable { self.base = base } + #if swift(>=4.2) func hash(into hasher: inout Hasher) { hasher.combine(ObjectIdentifier(base)) } + #else + var hashValue: Int { + return ObjectIdentifier(base).hashValue + } + #endif } diff --git a/Sources/CredentialsJWT/TypeSafeJWT.swift b/Sources/CredentialsJWT/TypeSafeJWT.swift index 47478d0..ef3d341 100644 --- a/Sources/CredentialsJWT/TypeSafeJWT.swift +++ b/Sources/CredentialsJWT/TypeSafeJWT.swift @@ -89,7 +89,7 @@ extension JWT: TypeSafeCredentials { } private static var usersCache: NSCache> { - let key = String(reflecting: Self.self) + let key = String(reflecting: JWT.self) if let usersCache = TypeSafeJWTCache.cacheForType[key] { return usersCache } else { @@ -134,13 +134,13 @@ extension JWT: TypeSafeCredentials { onSuccess(jwt) } - static func getFromCache(token: String) -> Self? { + static func getFromCache(token: String) -> JWT? { #if os(Linux) let key = NSString(string: token) #else let key = token as NSString #endif - guard let cacheElement = Self.usersCache.object(forKey: key) else { + guard let cacheElement = JWT.usersCache.object(forKey: key) else { Log.debug("Cached token not found: \(token)") return nil } @@ -155,13 +155,13 @@ extension JWT: TypeSafeCredentials { return cacheElement.userProfile } - static func saveInCache(profile: Self, token: String) { + static func saveInCache(profile: JWT, token: String) { #if os(Linux) let key = NSString(string: token) #else let key = token as NSString #endif - Self.usersCache.setObject(JWTCacheElement(profile: profile), forKey: key) + JWT.usersCache.setObject(JWTCacheElement(profile: profile), forKey: key) Log.debug("Token added to cache: \(token)") } }