Skip to content

Commit

Permalink
[fix] presentation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dtsiflit committed Oct 16, 2024
1 parent f994123 commit 0dceba3
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Sources/Claim/ClaimsExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion Sources/Issuer/SignedSDJWT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
File renamed without changes.
15 changes: 8 additions & 7 deletions Sources/Utilities/ClaimVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)")
}
}

7 changes: 0 additions & 7 deletions Sources/Utilities/Extensions/String+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
}
Expand Down
6 changes: 2 additions & 4 deletions Tests/Helpers/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func validateObjectResults(factoryResult result: Result<ClaimSet, Error>, 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)
}
Expand Down Expand Up @@ -131,9 +131,7 @@ class MockSaltProvider: SaltProvider {
class TestLogger {
static func log(_ message: String) {
#if DEBUG
// if isRunningTests() {
print(message)
// }
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Issuance/IssuerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()) ?? "")
}
}
6 changes: 3 additions & 3 deletions Tests/SpecExamples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
4 changes: 2 additions & 2 deletions Tests/Verification/SerializerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -57,7 +57,7 @@ final class SerialiserTest: XCTestCase {
ClaimsVerifier()
}.get()

print(verifier)
XCTAssertNotNil(verifier)
}

}

0 comments on commit 0dceba3

Please sign in to comment.