Skip to content

Commit

Permalink
[86] Ignore [String] JWK parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierLowmiller authored and Daniel committed Oct 18, 2018
1 parent b6094a3 commit cfdbf05
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
16 changes: 8 additions & 8 deletions JOSESwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,18 @@
65E733CD1FEBE9670009EAC6 /* JWK */ = {
isa = PBXGroup;
children = (
65E733D21FEBFDB30009EAC6 /* JWKtoJSONTests.swift */,
65E733D41FEC031B0009EAC6 /* JWKRSAKeysTests.swift */,
65826AB320286B3A00AFFC46 /* JWKRSAEncodingTests.swift */,
65A103A0202B03BB00D22BF5 /* ASN1DERParsingTests.swift */,
6514ADCA2031DD27008A4DD3 /* ASN1DEREncodingTests.swift */,
6546D605203580C6007217FB /* JWKRSADecodingTests.swift */,
65A103A0202B03BB00D22BF5 /* ASN1DERParsingTests.swift */,
65A103A2202B0CDF00D22BF5 /* DataRSAPublicKeyTests.swift */,
658261482029E2D200B594ED /* SecKeyRSAPublicKeyTests.swift */,
6546D605203580C6007217FB /* JWKRSADecodingTests.swift */,
65826AB320286B3A00AFFC46 /* JWKRSAEncodingTests.swift */,
65E733D41FEC031B0009EAC6 /* JWKRSAKeysTests.swift */,
6536560A2035DC3900A3AC3B /* JWKSetCodingTests.swift */,
653656062035D6C700A3AC3B /* JWKSetCollectionTests.swift */,
65E733D21FEBFDB30009EAC6 /* JWKtoJSONTests.swift */,
65684A4C2031935200E56C68 /* RSAPublicKeyToDataTests.swift */,
65684A4E2031971A00E56C68 /* RSAPublicKeyToSecKeyTests.swift */,
653656062035D6C700A3AC3B /* JWKSetCollectionTests.swift */,
6536560A2035DC3900A3AC3B /* JWKSetCodingTests.swift */,
658261482029E2D200B594ED /* SecKeyRSAPublicKeyTests.swift */,
6506D9E820F4CA2000F34DD8 /* SymmetricKeyTests.swift */,
);
name = JWK;
Expand Down
5 changes: 5 additions & 0 deletions JOSESwift/Sources/JWKParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public enum JWKParameter: String, CodingKey {
case X509CertificateChain = "x5c"
case X509CertificateSHA1Thumbprint = "x5t"
case X509CertificateSHA256Thumbprint = "x5t#S256"

static let nonStringParameters: [JWKParameter] = [
.keyOperations,
.X509CertificateChain
]
}

/// RSA specific JWK parameters.
Expand Down
4 changes: 2 additions & 2 deletions JOSESwift/Sources/RSAKeyCodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extension RSAPublicKey: Decodable {

// Other common parameters are optional.
var parameters: [String: String] = [:]
for key in commonParameters.allKeys {
for key in commonParameters.allKeys where !JWKParameter.nonStringParameters.contains(key) {
parameters[key.rawValue] = try commonParameters.decode(String.self, forKey: key)
}

Expand Down Expand Up @@ -119,7 +119,7 @@ extension RSAPrivateKey: Decodable {

// Other common parameters are optional.
var parameters: [String: String] = [:]
for key in commonParameters.allKeys {
for key in commonParameters.allKeys where !JWKParameter.nonStringParameters.contains(key) {
parameters[key.rawValue] = try commonParameters.decode(String.self, forKey: key)
}

Expand Down
28 changes: 28 additions & 0 deletions Tests/JWKRSADecodingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,32 @@ class JWKRSADecodingTests: CryptoTestCase {
XCTFail()
}


func testBuildingJWKSetShouldNotFailIfCertificatesArePresent() {
// Given
let json = """
{
"keys": [{
"kty": "RSA",
"e": "AQAB",
"use": "enc",
"x5t": "eGydA5CgawshHa8ULkMyn5gl9eI",
"kid": "kid-12345",
"x5c": ["Y2VydGlmaWNhdGUxMjM0NWRhdGEx"],
"n": "4r7_nnmRn9hppkfxt8p"
}, {
"kty": "RSA",
"e": "AQAB",
"use": "sig",
"x5t": "gpYbURn6jaHwNX9xhE2MGCIXPd0",
"kid": "kid-12346",
"x5c": ["Y2VydGlmaWNhdGUxMjM0NWRhdGEy"],
"n": "rTZj4tESZaNMpwsj"
}]
}
""".data(using: .utf8)!

// Then
XCTAssertNoThrow(try JWKSet(data: json))
}
}

0 comments on commit cfdbf05

Please sign in to comment.