Skip to content

Commit

Permalink
chore: Reimplemented synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
amosavian committed May 1, 2024
1 parent 329f300 commit d37087e
Show file tree
Hide file tree
Showing 10 changed files with 490 additions and 343 deletions.
4 changes: 1 addition & 3 deletions Sources/JWSETKit/Base/ProtectedContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ extension TypedProtectedWebContainer {
}

public subscript<T>(dynamicMember keyPath: KeyPath<Container, T>) -> T {
get {
value[keyPath: keyPath]
}
value[keyPath: keyPath]
}

public subscript<T>(dynamicMember keyPath: WritableKeyPath<Container, T>) -> T {
Expand Down
2 changes: 1 addition & 1 deletion Sources/JWSETKit/Cryptography/Algorithms/Algorithms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public struct JSONWebKeyCurve: StringRepresentable {
}

extension JSONWebKeyCurve {
private static let keySizes: ReadWriteLockedValue<[Self: Int]> = [
private static let keySizes: PthreadReadWriteLockedValue<[Self: Int]> = [
.p256: 32, .ed25519: 32, .x25519: 32,
.p384: 48,
.p521: 66,
Expand Down
4 changes: 2 additions & 2 deletions Sources/JWSETKit/Cryptography/Algorithms/Compression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public struct JSONWebCompressionAlgorithm: StringRepresentable {

extension JSONWebCompressionAlgorithm {
#if canImport(Compression)
private static let compressors: ReadWriteLockedValue<[Self: any JSONWebCompressor.Type]> = [
private static let compressors: PthreadReadWriteLockedValue<[Self: any JSONWebCompressor.Type]> = [
.deflate: AppleCompressor<DeflateCompressionCodec>.self,
]
#else
private static let compressors: ReadWriteLockedValue<[Self: any JSONWebCompressor.Type]> = [:]
private static let compressors: PthreadReadWriteLockedValue<[Self: any JSONWebCompressor.Type]> = [:]
#endif

/// Returns provided compressor for this algorithm.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct JSONWebContentEncryptionAlgorithm: JSONWebAlgorithm {
}

extension JSONWebContentEncryptionAlgorithm {
private static let keyRegistryClasses: ReadWriteLockedValue<[Self: any JSONWebSealingKey.Type]> = [
private static let keyRegistryClasses: PthreadReadWriteLockedValue<[Self: any JSONWebSealingKey.Type]> = [
.aesEncryptionGCM128: JSONWebKeyAESGCM.self,
.aesEncryptionGCM192: JSONWebKeyAESGCM.self,
.aesEncryptionGCM256: JSONWebKeyAESGCM.self,
Expand All @@ -31,7 +31,7 @@ extension JSONWebContentEncryptionAlgorithm {
.aesEncryptionCBC256SHA512: JSONWebKeyAESCBCHMAC.self,
]

private static let keyLengths: ReadWriteLockedValue<[Self: SymmetricKeySize]> = [
private static let keyLengths: PthreadReadWriteLockedValue<[Self: SymmetricKeySize]> = [
.aesEncryptionGCM128: .bits128,
.aesEncryptionGCM192: .bits192,
.aesEncryptionGCM256: .bits256,
Expand Down
12 changes: 6 additions & 6 deletions Sources/JWSETKit/Cryptography/Algorithms/KeyEncryption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension JSONWebKeyEncryptionAlgorithm {
_ cek: inout Data
) throws -> Void

private static let keyRegistryClasses: ReadWriteLockedValue < [Self: (public: any JSONWebEncryptingKey.Type, private: any JSONWebDecryptingKey.Type)]> = [
private static let keyRegistryClasses: PthreadReadWriteLockedValue < [Self: (public: any JSONWebEncryptingKey.Type, private: any JSONWebDecryptingKey.Type)]> = [
.direct: (JSONWebDirectKey.self, JSONWebDirectKey.self),
.aesKeyWrap128: (JSONWebKeyAESKW.self, JSONWebKeyAESKW.self),
.aesKeyWrap192: (JSONWebKeyAESKW.self, JSONWebKeyAESKW.self),
Expand All @@ -58,7 +58,7 @@ extension JSONWebKeyEncryptionAlgorithm {
.ecdhEphemeralStaticAESKeyWrap256: (JSONWebKeyAESKW.self, JSONWebKeyAESKW.self),
]

private static let keyTypes: ReadWriteLockedValue<[Self: JSONWebKeyType]> = [
private static let keyTypes: PthreadReadWriteLockedValue<[Self: JSONWebKeyType]> = [
.direct: .symmetric,
.aesKeyWrap128: .symmetric,
.aesKeyWrap192: .symmetric,
Expand All @@ -80,7 +80,7 @@ extension JSONWebKeyEncryptionAlgorithm {
.ecdhEphemeralStaticAESKeyWrap256: .symmetric,
]

private static let keyLengths: ReadWriteLockedValue<[Self: Int]> = [
private static let keyLengths: PthreadReadWriteLockedValue<[Self: Int]> = [
.aesKeyWrap128: SymmetricKeySize.bits128.bitCount,
.aesKeyWrap192: SymmetricKeySize.bits192.bitCount,
.aesKeyWrap256: SymmetricKeySize.bits256.bitCount,
Expand All @@ -100,7 +100,7 @@ extension JSONWebKeyEncryptionAlgorithm {
.ecdhEphemeralStaticAESKeyWrap256: SymmetricKeySize.bits256.bitCount,
]

private static let hashFunctions: ReadWriteLockedValue<[Self: any HashFunction.Type]> = [
private static let hashFunctions: PthreadReadWriteLockedValue<[Self: any HashFunction.Type]> = [
.aesKeyWrap128: SHA256.self,
.aesKeyWrap192: SHA384.self,
.aesKeyWrap256: SHA512.self,
Expand All @@ -116,7 +116,7 @@ extension JSONWebKeyEncryptionAlgorithm {
.ecdhEphemeralStaticAESKeyWrap256: SHA256.self,
]

private static let encryptedKeyHandlers: ReadWriteLockedValue<[Self: EncryptedKeyHandler]> = [
private static let encryptedKeyHandlers: PthreadReadWriteLockedValue<[Self: EncryptedKeyHandler]> = [
.aesGCM128KeyWrap: aesGCMKeyWrapEncryptedKey,
.aesGCM192KeyWrap: aesGCMKeyWrapEncryptedKey,
.aesGCM256KeyWrap: aesGCMKeyWrapEncryptedKey,
Expand All @@ -129,7 +129,7 @@ extension JSONWebKeyEncryptionAlgorithm {
.ecdhEphemeralStaticAESKeyWrap256: ecdhEsEncryptedKey,
]

private static let decryptionMutators: ReadWriteLockedValue<[Self: DecryptionMutatorHandler]> = [
private static let decryptionMutators: PthreadReadWriteLockedValue<[Self: DecryptionMutatorHandler]> = [
.direct: directDecryptionMutator,
.aesGCM128KeyWrap: aesgcmDecryptionMutator,
.aesGCM192KeyWrap: aesgcmDecryptionMutator,
Expand Down
8 changes: 4 additions & 4 deletions Sources/JWSETKit/Cryptography/Algorithms/Signature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct JSONWebSignatureAlgorithm: JSONWebAlgorithm {
}

extension JSONWebSignatureAlgorithm {
private static let keyRegistryClasses: ReadWriteLockedValue < [Self: (public: any JSONWebValidatingKey.Type, private: any JSONWebSigningKey.Type)]> = [
private static let keyRegistryClasses: PthreadReadWriteLockedValue < [Self: (public: any JSONWebValidatingKey.Type, private: any JSONWebSigningKey.Type)]> = [
.none: (JSONWebDirectKey.self, JSONWebDirectKey.self),
.hmacSHA256: (JSONWebKeyHMAC<SHA256>.self, JSONWebKeyHMAC<SHA256>.self),
.hmacSHA384: (JSONWebKeyHMAC<SHA384>.self, JSONWebKeyHMAC<SHA384>.self),
Expand All @@ -39,7 +39,7 @@ extension JSONWebSignatureAlgorithm {
.rsaSignaturePKCS1v15SHA512: (JSONWebRSAPublicKey.self, JSONWebRSAPrivateKey.self),
]

private static let keyTypes: ReadWriteLockedValue<[Self: JSONWebKeyType]> = [
private static let keyTypes: PthreadReadWriteLockedValue<[Self: JSONWebKeyType]> = [
.none: .empty,
.hmacSHA256: .symmetric,
.hmacSHA384: .symmetric,
Expand All @@ -56,12 +56,12 @@ extension JSONWebSignatureAlgorithm {
.rsaSignaturePKCS1v15SHA512: .rsa,
]

private static let curves: ReadWriteLockedValue<[Self: JSONWebKeyCurve]> = [
private static let curves: PthreadReadWriteLockedValue<[Self: JSONWebKeyCurve]> = [
.ecdsaSignatureP256SHA256: .p256, .ecdsaSignatureP384SHA384: .p384,
.ecdsaSignatureP521SHA512: .p521, .eddsaSignature: .ed25519,
]

private static let hashFunctions: ReadWriteLockedValue<[Self: any HashFunction.Type]> = [
private static let hashFunctions: PthreadReadWriteLockedValue<[Self: any HashFunction.Type]> = [
.hmacSHA256: SHA256.self,
.hmacSHA384: SHA384.self,
.hmacSHA512: SHA512.self,
Expand Down
2 changes: 1 addition & 1 deletion Sources/JWSETKit/Cryptography/KeyParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ enum JSONWebKeyCertificateChainSpecializer: JSONWebKeySpecializer {
}

extension AnyJSONWebKey {
static let specializers: ReadWriteLockedValue<[any JSONWebKeySpecializer.Type]> = [
static let specializers: PthreadReadWriteLockedValue<[any JSONWebKeySpecializer.Type]> = [
JSONWebKeyRSASpecializer.self,
JSONWebKeyEllipticCurveSpecializer.self,
JSONWebKeyCurve25519Specializer.self,
Expand Down
Loading

0 comments on commit d37087e

Please sign in to comment.