forked from vapor/jwt-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP: port required Katalysis changes to latest vapor/jwt-kit version (4.0.1) Check the TODO in Source/JWTKit Some tests are failing * fix tests and todos * remove key ops * small fixes * fixes * fixed a warning, and removed stuff * cleanup * more cleanup * small fix * small fix * add initializers for keys * add JWKS initializer * apply fixes * make parameters property public * make static funcs public * fix ecdsa key decoding * fix bug and add test * dirty fix applied * improve api * cleanup * cleanup * cleanup * remove warning * fix encoding label for ecdsa keys * fix KeyType to match official spec * update all algorithm and curve labels to specification * fix test since spec update * make convenience init public Co-authored-by: Alex Tran Qui <[email protected]>
- Loading branch information
1 parent
8abeddb
commit 6055fe8
Showing
11 changed files
with
296 additions
and
63 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Foundation | ||
import CJWTKitBoringSSL | ||
|
||
class BigNumber { | ||
let c: UnsafeMutablePointer<BIGNUM>?; | ||
|
||
public init() { | ||
self.c = CJWTKitBoringSSL_BN_new(); | ||
} | ||
|
||
init(_ ptr: OpaquePointer) { | ||
self.c = UnsafeMutablePointer<BIGNUM>(ptr); | ||
} | ||
|
||
deinit { | ||
CJWTKitBoringSSL_BN_free(self.c); | ||
} | ||
|
||
public static func convert(_ bnBase64: String) -> BigNumber? { | ||
guard let data = Data(base64Encoded: bnBase64) else { | ||
return nil | ||
} | ||
|
||
let c = data.withUnsafeBytes { (p: UnsafeRawBufferPointer) -> OpaquePointer in | ||
return OpaquePointer(CJWTKitBoringSSL_BN_bin2bn(p.baseAddress?.assumingMemoryBound(to: UInt8.self), p.count, nil)) | ||
} | ||
return BigNumber(c) | ||
} | ||
|
||
public func toBase64(_ size: Int = 1000) -> String { | ||
let pBuffer = UnsafeMutablePointer<UInt8>.allocate(capacity: size) | ||
defer { pBuffer.deallocate() } | ||
|
||
let actualBytes = Int(CJWTKitBoringSSL_BN_bn2bin(self.c, pBuffer)) | ||
let data = Data(bytes: pBuffer, count: actualBytes) | ||
return data.base64EncodedString() | ||
} | ||
} |
Oops, something went wrong.