From 0dceba3f7f4cd07233eeef0b3ca10592e8d4d51f Mon Sep 17 00:00:00 2001 From: dtsiflit Date: Wed, 16 Oct 2024 16:31:48 +0300 Subject: [PATCH] [fix] presentation updates --- Sources/Claim/ClaimsExtractor.swift | 4 ++-- Sources/Issuer/SignedSDJWT.swift | 1 - Sources/{ => Types}/Types.swift | 0 Sources/Utilities/ClaimVisitor.swift | 15 ++++++++------- .../Utilities/Extensions/String+Extension.swift | 7 ------- Tests/Helpers/Utilities.swift | 6 ++---- Tests/Issuance/IssuerTests.swift | 2 +- Tests/SpecExamples.swift | 6 +++--- Tests/Verification/SerializerTest.swift | 4 ++-- 9 files changed, 18 insertions(+), 27 deletions(-) rename Sources/{ => Types}/Types.swift (100%) diff --git a/Sources/Claim/ClaimsExtractor.swift b/Sources/Claim/ClaimsExtractor.swift index 1c86d14..2fbc44f 100644 --- a/Sources/Claim/ClaimsExtractor.swift +++ b/Sources/Claim/ClaimsExtractor.swift @@ -63,12 +63,12 @@ public class ClaimExtractor { if let disclosure = digestsOfDisclosures[foundDigest] { let currentJsonPointer = "/" + (currentPath + [foundDisclosure.key]).joined(separator: "/") - // visitor?.call(key: foundDisclosure.key, disclosure: foundDisclosure.value.stringValue + " " + foundDigest + " " + d + " " + currentJsonPointer) visitor?.call( pointer: .init( pointer: currentJsonPointer ), - disclosure: disclosure + disclosure: disclosure, + value: foundDisclosure.value.string ) } foundDigests.append(.object(foundDigest)) diff --git a/Sources/Issuer/SignedSDJWT.swift b/Sources/Issuer/SignedSDJWT.swift index 7483d47..2211f93 100644 --- a/Sources/Issuer/SignedSDJWT.swift +++ b/Sources/Issuer/SignedSDJWT.swift @@ -234,7 +234,6 @@ private extension SignedSDJWT { func recreateClaimsAndDisclosuresPerClaim(visitor: Visitor?) throws -> (JSON, DisclosuresPerClaim) { let claims = try recreateClaims(visitor: visitor) - print(claims) return ( claims.recreatedClaims, diff --git a/Sources/Types.swift b/Sources/Types/Types.swift similarity index 100% rename from Sources/Types.swift rename to Sources/Types/Types.swift diff --git a/Sources/Utilities/ClaimVisitor.swift b/Sources/Utilities/ClaimVisitor.swift index 16261cd..8b71636 100644 --- a/Sources/Utilities/ClaimVisitor.swift +++ b/Sources/Utilities/ClaimVisitor.swift @@ -16,7 +16,11 @@ import Foundation public protocol ClaimVisitor: Sendable { - func call(pointer: JSONPointer, disclosure: Disclosure) + func call( + pointer: JSONPointer, + disclosure: Disclosure, + value: String? + ) } public final class Visitor: ClaimVisitor { @@ -31,7 +35,8 @@ public final class Visitor: ClaimVisitor { public func call( pointer: JSONPointer, - disclosure: Disclosure + disclosure: Disclosure, + value: String? = nil ) { // Ensure that the path (pointer) does not already exist in disclosuresPerClaim guard disclosuresPerClaim[pointer] == nil else { @@ -40,17 +45,13 @@ public final class Visitor: ClaimVisitor { // Calculate claimDisclosures let claimDisclosures: [Disclosure] = { - let containerPath = pointer.parent() // Assuming pointer has a parent() method + let containerPath = pointer.parent() let containerDisclosures = containerPath.flatMap { disclosuresPerClaim[$0] } ?? [] - return containerDisclosures + [disclosure] }() // Insert the claimDisclosures only if the pointer doesn't already exist disclosuresPerClaim[pointer] = disclosuresPerClaim[pointer] ?? claimDisclosures - - - print("Visitor: \(pointer.pointer) \(disclosure)") } } diff --git a/Sources/Utilities/Extensions/String+Extension.swift b/Sources/Utilities/Extensions/String+Extension.swift index 47d572d..de830f4 100644 --- a/Sources/Utilities/Extensions/String+Extension.swift +++ b/Sources/Utilities/Extensions/String+Extension.swift @@ -81,26 +81,22 @@ extension String { // Decode the Base64-encoded string guard let keyData = Data(base64Encoded: keyString) else { - print("Invalid Base64 string") return nil } // First, try RSA if let secKey = String.createSecKey(from: keyData, keyType: kSecAttrKeyTypeRSA) { - print("Key identified as RSA.") return secKey } // If RSA fails, try EC if let secKey = String.createSecKey(from: keyData, keyType: kSecAttrKeyTypeEC) { - print("Key identified as EC.") return secKey } // Add more key types if needed (e.g., DSA, etc.) // If neither RSA nor EC works, return nil - print("Unable to identify key type.") return nil } @@ -122,9 +118,6 @@ extension String { if let secKey = SecKeyCreateWithData(keyData as CFData, attributes as CFDictionary, &error) { return secKey } else { - if let err = error?.takeRetainedValue() { - print("Error creating SecKey: \(err.localizedDescription)") - } return nil } } diff --git a/Tests/Helpers/Utilities.swift b/Tests/Helpers/Utilities.swift index 548c570..f95cfa8 100644 --- a/Tests/Helpers/Utilities.swift +++ b/Tests/Helpers/Utilities.swift @@ -65,8 +65,8 @@ func validateObjectResults(factoryResult result: Result, expect TestLogger.log("==============================") disclosures .compactMap { $0.base64URLDecode()} - .forEach {print($0)} - print("==============================") + .forEach { TestLogger.log($0) } + TestLogger.log("==============================") if numberOfDecoys == 0 && decoysLimit == 0 { XCTAssert(disclosures.count == expectedDigests) } @@ -131,9 +131,7 @@ class MockSaltProvider: SaltProvider { class TestLogger { static func log(_ message: String) { #if DEBUG -// if isRunningTests() { print(message) -// } #endif } diff --git a/Tests/Issuance/IssuerTests.swift b/Tests/Issuance/IssuerTests.swift index cd83691..bbd61ba 100644 --- a/Tests/Issuance/IssuerTests.swift +++ b/Tests/Issuance/IssuerTests.swift @@ -66,6 +66,6 @@ final class IssuerTest: XCTestCase { jwTpayload: payload) let jwt = try JWT(header: DefaultJWSHeaderImpl(algorithm: .ES256), payload: JSON(envelopedFormat.data)) - print(jwt.payload) + TestLogger.log((try? jwt.payload.toJSONString()) ?? "") } } diff --git a/Tests/SpecExamples.swift b/Tests/SpecExamples.swift index 0d46e8d..b8e22fb 100644 --- a/Tests/SpecExamples.swift +++ b/Tests/SpecExamples.swift @@ -124,12 +124,12 @@ final class SpecExamples: XCTestCase { } let output = factory.createSDJWTPayload(sdJwtObject: complex.asObject) - let digestCount = try XCTUnwrap(try? output.get().value.findDigestCount()) + let _ = try XCTUnwrap(try? output.get().value.findDigestCount()) validateObjectResults(factoryResult: output, expectedDigests: 16) try output.get().disclosures.forEach { disclosure in - print(disclosure.base64URLDecode()) + TestLogger.log(disclosure.base64URLDecode() ?? "") } - let findDigest = try? XCTUnwrap(output.get()) + let _ = try? XCTUnwrap(output.get()) } } diff --git a/Tests/Verification/SerializerTest.swift b/Tests/Verification/SerializerTest.swift index e8e75bc..212afa4 100644 --- a/Tests/Verification/SerializerTest.swift +++ b/Tests/Verification/SerializerTest.swift @@ -36,7 +36,7 @@ final class SerialiserTest: XCTestCase { let serialisedString = try testSerializerWhenSerializedFormatIsSelected_ThenExpectSerialisedFormattedSignedSDJWT() let parser = CompactParser() let jwt = try parser.getSignedSdJwt(serialisedString: serialisedString).toSDJWT() - print(jwt.disclosures) + TestLogger.log(jwt.disclosures.joined(separator: ", ")) } func testSerialiseWhenChosingEnvelopeFormat_AppylingNoKeyBinding_ThenExpectACorrectJWT() throws { @@ -57,7 +57,7 @@ final class SerialiserTest: XCTestCase { ClaimsVerifier() }.get() - print(verifier) + XCTAssertNotNil(verifier) } }