Skip to content

Commit

Permalink
Merge pull request #24 from niscy-eudiw/feature/swift-6-0-0-update
Browse files Browse the repository at this point in the history
Swift 6.0 update
  • Loading branch information
dtsiflit authored Oct 14, 2024
2 parents cb01a49 + 2b60fad commit 02ce0c9
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ on:
tags: [ v* ]
jobs:
build:
runs-on: "macos-13"
runs-on: "macos-14"
steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '14.3.1'
xcode-version: '16.0'
- uses: actions/checkout@v4
- run:
fastlane tests
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.8
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
7 changes: 4 additions & 3 deletions Sources/Claim/Claim.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
* limitations under the License.
*/
import Foundation
@preconcurrency import SwiftyJSON

public struct Claim {
public struct Claim: Sendable {
public let id: ClaimId
public let format: String
public let jsonObject: JSONObject
public let jsonObject: JSON

public init(
id: ClaimId,
format: String,
jsonObject: JSONObject
jsonObject: JSON
) {
self.id = id
self.format = format
Expand Down
11 changes: 7 additions & 4 deletions Sources/Matching/Matcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private extension PresentationMatcher {
with field: Field
) -> CandidateField {
for path in field.paths {
let json = claim.jsonObject.toJSONString()
let json = try? claim.jsonObject.toJSONString()
if let values = json?.query(values: path)?.compactMap({ $0 }),
let value = values.first as? String,
filter(
Expand All @@ -157,12 +157,15 @@ private extension PresentationMatcher {

// Note: the JSONSchema validation library does not support
// date validation as of 0.6.0
if let date = filter["format"] as? String, date == "date" {
if let date = filter["format"].string, date == "date" {
return value.isValidDate()
}

do {
let result = try JSONSchema.validate(value, schema: filter)
let result = try JSONSchema.validate(
value,
schema: filter.dictionaryObject ?? [:]
)
return result.valid

} catch {
Expand Down Expand Up @@ -236,7 +239,7 @@ extension PresentationMatcher: EvaluatorType {
candidateClaims: InputDescriptorEvaluationPerClaim,
notMatchingClaims: InputDescriptorEvaluationPerClaim
) -> Match {
if let submissionRequirements = definition.submissionRequirements {
if definition.submissionRequirements != nil {
return .notMatched(details: [:])

} else {
Expand Down
14 changes: 6 additions & 8 deletions Sources/PresentationDefinition/Field.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
* limitations under the License.
*/
import Foundation
import SwiftyJSON

public struct Field: Codable, Hashable {
public let paths: [String]
public let filter: JSONObject?
public let filter: JSON?
public let purpose: String?
public let intentToRetain: Bool?
public let optional: Bool?
Expand All @@ -30,7 +31,7 @@ public struct Field: Codable, Hashable {

public init(
paths: [String],
filter: JSONObject?,
filter: JSON?,
purpose: String?,
intentToRetain: Bool?,
optional: Bool?) {
Expand All @@ -44,7 +45,7 @@ public struct Field: Codable, Hashable {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
paths = try container.decode([String].self, forKey: .path)
filter = try? container.decode(JSONObject.self, forKey: .filter)
filter = try? container.decode(JSON.self, forKey: .filter)
purpose = try? container.decode(String.self, forKey: .purpose)
intentToRetain = try? container.decode(Bool.self, forKey: .intentToRetain)
optional = try? container.decode(Bool.self, forKey: .optional)
Expand All @@ -62,11 +63,8 @@ public struct Field: Codable, Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(paths)
if let filter = filter {
for (key, value) in filter {
for (key, _) in filter {
hasher.combine(key)
if let value = value as? String {
hasher.combine(value)
}
}
}
hasher.combine(purpose)
Expand All @@ -77,6 +75,6 @@ public struct Field: Codable, Hashable {
return lhs.paths == rhs.paths &&
lhs.purpose == rhs.purpose &&
lhs.intentToRetain == rhs.intentToRetain &&
lhs.filter ?? JSONObject() == rhs.filter ?? JSONObject()
lhs.filter ?? JSON() == rhs.filter ?? JSON()
}
}
3 changes: 2 additions & 1 deletion Sources/PresentationDefinition/PresentationAliases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* limitations under the License.
*/
import Foundation
import SwiftyJSON

public typealias Filter = JSONObject
public typealias Filter = JSON
public typealias ClaimId = String
public typealias Purpose = String
public typealias Name = String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
import Foundation
import SwiftyJSON

public enum PresentationDefinitionSource {
case passByValue(presentationDefinition: PresentationDefinition)
Expand All @@ -22,17 +23,17 @@ public enum PresentationDefinitionSource {
}

public extension PresentationDefinitionSource {
init(authorizationRequestObject: JSONObject) throws {
if let presentationDefinitionObject = authorizationRequestObject[Constants.PRESENTATION_DEFINITION] as? JSONObject {
init(authorizationRequestObject: JSON) throws {
if let presentationDefinitionObject = authorizationRequestObject[Constants.PRESENTATION_DEFINITION].dictionary {

let jsonData = try JSONSerialization.data(withJSONObject: presentationDefinitionObject, options: [])
let presentationDefinition = try JSONDecoder().decode(PresentationDefinition.self, from: jsonData)

self = .passByValue(presentationDefinition: presentationDefinition)
} else if let uri = authorizationRequestObject[Constants.PRESENTATION_DEFINITION_URI] as? String,
} else if let uri = authorizationRequestObject[Constants.PRESENTATION_DEFINITION_URI].string,
let uri = URL(string: uri) {
self = .fetchByReference(url: uri)
} else if let scope = authorizationRequestObject[Constants.SCOPE] as? String,
} else if let scope = authorizationRequestObject[Constants.SCOPE].string,
!scope.components(separatedBy: " ").isEmpty {
self = .implied(scope: scope.components(separatedBy: " "))

Expand Down
31 changes: 31 additions & 0 deletions Sources/Support/Encodable+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2023 European Commission
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Foundation

extension Encodable {
func toJSONString(outputFormatting: JSONEncoder.OutputFormatting = .prettyPrinted) throws -> String {
let encoder = JSONEncoder()
encoder.outputFormatting = outputFormatting

let jsonData = try encoder.encode(self)

if let jsonString = String(data: jsonData, encoding: .utf8) {
return jsonString
} else {
throw PresentationError.invalidFormat
}
}
}
2 changes: 0 additions & 2 deletions Sources/Support/JSONCodingKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
import Foundation

public typealias JSONObject = [String: Any]

public struct JSONCodingKeys: CodingKey {
public var stringValue: String

Expand Down
8 changes: 5 additions & 3 deletions Tests/EntitiesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/
import XCTest
import SwiftyJSON

@testable import PresentationExchange

class EntitiesTests: XCTestCase {
Expand Down Expand Up @@ -262,7 +264,7 @@ class AuthorizationRequestUnprocessedDataTests: XCTestCase {
final class PresentationDefinitionSourceTests: XCTestCase {

func testInitFromAuthorizationRequestObjectWithPresentationDefinitionUri() throws {
let authorizationRequestObject: JSONObject = [
let authorizationRequestObject: JSON = [
"presentation_definition_uri": "https://example.com/presentation-definition"
]

Expand All @@ -277,7 +279,7 @@ final class PresentationDefinitionSourceTests: XCTestCase {
}

func testInitFromAuthorizationRequestObjectWithScope() throws {
let authorizationRequestObject: JSONObject = [
let authorizationRequestObject: JSON = [
"scope": "openid email profile"
]

Expand All @@ -292,7 +294,7 @@ final class PresentationDefinitionSourceTests: XCTestCase {
}

func testInitFromAuthorizationRequestObjectWithInvalidPresentationDefinition() {
let authorizationRequestObject: JSONObject = [:]
let authorizationRequestObject: JSON = [:]

XCTAssertThrowsError(try PresentationDefinitionSource(authorizationRequestObject: authorizationRequestObject)) { error in
XCTAssertEqual(error as? PresentationError, PresentationError.invalidPresentationDefinition)
Expand Down

0 comments on commit 02ce0c9

Please sign in to comment.