Skip to content

Commit

Permalink
Merge pull request #8 from niscy-eudiw/fix/access-control
Browse files Browse the repository at this point in the history
Public access control
  • Loading branch information
nsalampasis authored Sep 26, 2023
2 parents 913ce26 + 468b01d commit 3b43ef5
Show file tree
Hide file tree
Showing 27 changed files with 114 additions and 116 deletions.
4 changes: 2 additions & 2 deletions Sources/Builders/ArrayBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import Foundation

@resultBuilder
enum SDJWTArrayBuilder {
static func buildBlock(_ elements: SdElement...) -> [SdElement] {
public enum SDJWTArrayBuilder {
public static func buildBlock(_ elements: SdElement...) -> [SdElement] {
elements.map({$0})
}
}
10 changes: 5 additions & 5 deletions Sources/Builders/SDJWTBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@
import Foundation

@resultBuilder
enum SDJWTBuilder {
static func buildBlock(_ elements: [ClaimRepresentable]) -> SdElement {
public enum SDJWTBuilder {
public static func buildBlock(_ elements: [ClaimRepresentable]) -> SdElement {
return .object(
elements.reduce(into: [:]) { partialResult, claim in
partialResult[claim.key] = claim.value
}
)
}

static func buildBlock(_ elements: ClaimRepresentable...) -> SdElement {
public static func buildBlock(_ elements: ClaimRepresentable...) -> SdElement {
self.buildBlock(elements.map({$0}))
}

static func buildBlock(_ elements: ClaimRepresentable?...) -> SdElement {
public static func buildBlock(_ elements: ClaimRepresentable?...) -> SdElement {
self.buildBlock(elements.compactMap({$0}))
}

static func build(@SDJWTBuilder builder: () throws -> SdElement) rethrows -> SDJWTObject {
public static func build(@SDJWTBuilder builder: () throws -> SdElement) rethrows -> SDJWTObject {
return try builder().asObject ?? {
throw SDJWTError.encodingError
}()
Expand Down
14 changes: 7 additions & 7 deletions Sources/Claim/ClaimRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ import Foundation
import SwiftyJSON

/// Building block for the SD-JWT
protocol ClaimRepresentable: Encodable {
public protocol ClaimRepresentable: Encodable {

var key: String { get set }
var value: SdElement { get set }

func checkKeyValidity() -> Result<Bool, SDJWTError>
}

struct ConstantClaims: ClaimRepresentable {
public struct ConstantClaims: ClaimRepresentable {

// MARK: - Properties

var key: String
var value: SdElement
public var key: String
public var value: SdElement

// MARK: - Lifecycle

private init(_ key: String, value: SdElement) {
public init(_ key: String, value: SdElement) {
self.key = key
self.value = value
}
Expand Down Expand Up @@ -86,7 +86,7 @@ extension ClaimRepresentable {
}

@discardableResult
func checkKeyValidity() -> Result<Bool, SDJWTError> {
public func checkKeyValidity() -> Result<Bool, SDJWTError> {
guard
key != Keys.sd.rawValue,
key != Keys.dots.rawValue else {
Expand All @@ -97,7 +97,7 @@ extension ClaimRepresentable {
}
// MARK: - Encodable

func encode(to encoder: Encoder) throws {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: RawCodingKey.self)
try container.encode(self.value, forKey: .init(string: self.key))
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Claim/ClaimsExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
import SwiftyJSON

typealias ClaimExtractorResult = (digestsFoundOnPayload: [DigestType], recreatedClaims: JSON)
public typealias ClaimExtractorResult = (digestsFoundOnPayload: [DigestType], recreatedClaims: JSON)

class ClaimExtractor {
public class ClaimExtractor {

// MARK: - Properties

Expand Down
14 changes: 7 additions & 7 deletions Sources/Claim/FlatDisclosedClaim.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@
* limitations under the License.
*/

struct FlatDisclosedClaim: ClaimRepresentable {
public struct FlatDisclosedClaim: ClaimRepresentable {

// MARK: - Properties

var key: String
var value: SdElement
public var key: String
public var value: SdElement

// MARK: - Lifecycle

init?(_ key: String, _ flat: Encodable) {
public init?(_ key: String, _ flat: Encodable) {
self.key = key
self.value = SdElement.flat(value: flat)
guard case Result.success(true) = checkKeyValidity() else {
return nil
}
}

init?(_ key: String, _ flat: [Encodable]) {
public init?(_ key: String, _ flat: [Encodable]) {
self.key = key
self.value = SdElement.flat(value: flat)
guard case Result.success(true) = checkKeyValidity() else {
return nil
}
}

init?(_ key: String, _ flat: [String: Encodable]) {
public init?(_ key: String, _ flat: [String: Encodable]) {
self.key = key
self.value = SdElement.flat(value: flat)
guard case Result.success(true) = checkKeyValidity() else {
return nil
}
}

init?(_ key: String, @SDJWTBuilder _ flat: () -> SdElement) {
public init?(_ key: String, @SDJWTBuilder _ flat: () -> SdElement) {
self.key = key
self.value = SdElement.flat(value: flat().asJSON)
guard case Result.success(true) = checkKeyValidity() else {
Expand Down
18 changes: 9 additions & 9 deletions Sources/Claim/ObjectClaim.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* limitations under the License.
*/

struct ObjectClaim: ClaimRepresentable {
public struct ObjectClaim: ClaimRepresentable {

// MARK: - Properties

var key: String
var value: SdElement
public var key: String
public var value: SdElement

// MARK: - Lifecycle

init?(_ key: String, @SDJWTBuilder builder: () -> SdElement) {
public init?(_ key: String, @SDJWTBuilder builder: () -> SdElement) {
self.key = key
guard let object = builder().asObject else {
return nil
Expand All @@ -34,7 +34,7 @@ struct ObjectClaim: ClaimRepresentable {
}
}

init?(_ key: String, value: SdElement) {
public init?(_ key: String, value: SdElement) {
self.key = key
self.value = value
guard case Result.success(true) = checkKeyValidity() else {
Expand All @@ -43,16 +43,16 @@ struct ObjectClaim: ClaimRepresentable {
}
}

struct RecursiveObject: ClaimRepresentable {
public struct RecursiveObject: ClaimRepresentable {

// MARK: - Properties

var key: String
var value: SdElement
public var key: String
public var value: SdElement

// MARK: - Lifecycle

init?(_ key: String, @SDJWTBuilder builder: () -> SdElement) {
public init?(_ key: String, @SDJWTBuilder builder: () -> SdElement) {
self.key = key
guard let object = builder().asObject else {
return nil
Expand Down
12 changes: 6 additions & 6 deletions Sources/Claim/PlainClaim.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@
* limitations under the License.
*/

struct PlainClaim: ClaimRepresentable {
public struct PlainClaim: ClaimRepresentable {

// MARK: - Properties

var key: String
var value: SdElement
public var key: String
public var value: SdElement

// MARK: - Lifecycle

init?(_ key: String, _ plain: Encodable) {
public init?(_ key: String, _ plain: Encodable) {
self.key = key
self.value = SdElement.plain(value: plain)
guard case Result.success(true) = checkKeyValidity() else {
return nil
}
}

init?(_ key: String, _ plain: [Encodable]) {
public init?(_ key: String, _ plain: [Encodable]) {
self.key = key
self.value = SdElement.plain(value: plain)
guard case Result.success(true) = checkKeyValidity() else {
return nil
}
}

init?(_ key: String, _ plain: [String: Encodable]) {
public init?(_ key: String, _ plain: [String: Encodable]) {
self.key = key
self.value = SdElement.plain(value: plain)
guard case Result.success(true) = checkKeyValidity() else {
Expand Down
20 changes: 10 additions & 10 deletions Sources/Claim/SdArrayClaim.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
* limitations under the License.
*/

struct SdArrayClaim: ClaimRepresentable {
public struct SdArrayClaim: ClaimRepresentable {

// MARK: - Properties

var key: String
var value: SdElement
public var key: String
public var value: SdElement

// MARK: - Lifecycle

init?(_ key: String, array: [SdElement]) {
public init?(_ key: String, array: [SdElement]) {
self.key = key
self.value = .array(array)
guard case Result.success(true) = checkKeyValidity() else {
return nil
}
}

init?(_ key: String, @SDJWTArrayBuilder builder: () -> [SdElement]) {
public init?(_ key: String, @SDJWTArrayBuilder builder: () -> [SdElement]) {
self.key = key
self.value = .array(builder())
guard case Result.success(true) = checkKeyValidity() else {
Expand All @@ -40,16 +40,16 @@ struct SdArrayClaim: ClaimRepresentable {
}
}

struct RecursiveSdArrayClaim: ClaimRepresentable {
public struct RecursiveSdArrayClaim: ClaimRepresentable {

// MARK: - Properties

var key: String
var value: SdElement
public var key: String
public var value: SdElement

// MARK: - Lifecycle

init?(_ key: String, array: [SdElement]) {
public init?(_ key: String, array: [SdElement]) {
self.key = key
self.value = .recursiveArray(array)

Expand All @@ -58,7 +58,7 @@ struct RecursiveSdArrayClaim: ClaimRepresentable {
}
}

init?(_ key: String, @SDJWTArrayBuilder builder: () -> [SdElement]) {
public init?(_ key: String, @SDJWTArrayBuilder builder: () -> [SdElement]) {
self.key = key
self.value = .recursiveArray(builder())

Expand Down
6 changes: 3 additions & 3 deletions Sources/Claim/SdElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import Foundation
import SwiftyJSON

typealias SDJWTObject = [String: SdElement]
public typealias SDJWTObject = [String: SdElement]

enum SdElement: Encodable {
public enum SdElement: Encodable {
// Basic Building Blocks
case object([String: SdElement])
case plain(JSON)
Expand Down Expand Up @@ -55,7 +55,7 @@ enum SdElement: Encodable {

// MARK: - Encodable

func encode(to encoder: Encoder) {
public func encode(to encoder: Encoder) {
switch self {
case .object(let object), .recursiveObject(let object):
try? object.encode(to: encoder)
Expand Down
8 changes: 4 additions & 4 deletions Sources/Digest/DigestCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class DigestCreator {

}

enum DigestType: RawRepresentable, Hashable {
public enum DigestType: RawRepresentable, Hashable {

typealias RawValue = DisclosureDigest
public typealias RawValue = DisclosureDigest

case array(DisclosureDigest)
case object(DisclosureDigest)
Expand All @@ -65,7 +65,7 @@ enum DigestType: RawRepresentable, Hashable {
}
}

var rawValue: DisclosureDigest {
public var rawValue: DisclosureDigest {
switch self {
case .array(let disclosureDigest), .object(let disclosureDigest):
return disclosureDigest
Expand All @@ -74,7 +74,7 @@ enum DigestType: RawRepresentable, Hashable {

// MARK: - Lifecycle

init?(rawValue: DisclosureDigest) {
public init?(rawValue: DisclosureDigest) {
let cleanRawValue = rawValue
.replacingOccurrences(of: "\"", with: "")
.replacingOccurrences(of: "[", with: "")
Expand Down
4 changes: 2 additions & 2 deletions Sources/Digest/HashingAlgorithm/HashingAlgorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
import Foundation

typealias Disclosure = String
typealias DisclosureDigest = String
public typealias Disclosure = String
public typealias DisclosureDigest = String

protocol HashingAlgorithm {
var identifier: String { get }
Expand Down
2 changes: 1 addition & 1 deletion Sources/Issuer/JWT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Foundation
import JOSESwift
import SwiftyJSON

struct JWT: JWTRepresentable {
public struct JWT: JWTRepresentable {

// MARK: - Properties

Expand Down
4 changes: 2 additions & 2 deletions Sources/Issuer/SDJWT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Foundation
import SwiftyJSON
import JOSESwift

typealias KBJWT = JWT
public typealias KBJWT = JWT

struct SDJWT {

Expand Down Expand Up @@ -65,7 +65,7 @@ struct SDJWT {
}
}

struct SignedSDJWT {
public struct SignedSDJWT {

// MARK: - Properties

Expand Down
4 changes: 1 addition & 3 deletions Sources/Issuer/SDJWTIssuer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import Foundation
import JOSESwift
import SwiftyJSON

/// `SDJWTIssuer` is a class for issuing and presenting signed SD JSON Web Tokens (SDJWTs).
///
class SDJWTIssuer {
public class SDJWTIssuer {

/// Enum to represent the purpose of the JWT.
enum Purpose {
Expand Down
Loading

0 comments on commit 3b43ef5

Please sign in to comment.