Skip to content

Commit a92e738

Browse files
committed
Refactored
1 parent e722946 commit a92e738

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Sources/JWT.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public enum Algorithm: CustomStringConvertible {
1919
case hs512(Data)
2020

2121
/// RSA using SHA-256 hash algorithm
22-
case rs256(PrivateKey)
22+
case rs256(Data)
2323

2424
// RSA using SHA-512 hash algorithm
25-
case rs512(PrivateKey)
25+
case rs512(Data)
2626

2727
public var description: String {
2828
switch self {
@@ -56,7 +56,10 @@ public enum Algorithm: CustomStringConvertible {
5656
return base64encode(Data(bytes: result))
5757
}
5858

59-
func signRSA(_ privateKey: PrivateKey, digestType: Signature.DigestType) throws -> String {
59+
func signRS(_ key: Data, digestType: Signature.DigestType) throws -> String {
60+
61+
let keyString = String.init(data: key, encoding: .utf8)
62+
let privateKey = try PrivateKey(pemEncoded: keyString)
6063

6164
let clear = try ClearMessage(string: message, using: .utf8)
6265

@@ -80,8 +83,11 @@ public enum Algorithm: CustomStringConvertible {
8083
case .hs512(let key):
8184
return signHS(key, variant: .sha512)
8285

83-
case .rsa256(let privateKey):
84-
return try signRSA(privateKey, digestType: .sha256)
86+
case .rs256(let key):
87+
return try signRS(privateKey, digestType: .sha256)
88+
89+
case .rs512(let key):
90+
return try signRS(privateKey, digestType: .sha512)
8591

8692
}
8793
}

0 commit comments

Comments
 (0)