-
Notifications
You must be signed in to change notification settings - Fork 45
Missing Hashable and Sendable Conformances #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,7 @@ import Crypto | |
import AsyncHTTPClient | ||
import NIOFoundationCompat | ||
|
||
class ChainVerifier { | ||
|
||
actor ChainVerifier { | ||
private static let EXPECTED_CHAIN_LENGTH = 3 | ||
private static let EXPECTED_JWT_SEGMENTS = 3 | ||
private static let EXPECTED_ALGORITHM = "ES256" | ||
|
@@ -28,7 +27,7 @@ class ChainVerifier { | |
self.verifiedPublicKeyCache = [:] | ||
} | ||
|
||
func verify<T: DecodedSignedData>(signedData: String, type: T.Type, onlineVerification: Bool, environment: AppStoreEnvironment) async -> VerificationResult<T> where T: Decodable { | ||
func verify<T: DecodedSignedData>(signedData: String, type: T.Type, onlineVerification: Bool, environment: AppStoreEnvironment) async -> VerificationResult<T> where T: Decodable & Sendable { | ||
let header: JWTHeader; | ||
let decodedBody: T; | ||
do { | ||
|
@@ -120,7 +119,7 @@ class ChainVerifier { | |
return verificationResult | ||
} | ||
|
||
func verifyChainWithoutCaching(leaf: Certificate, intermediate: Certificate, online: Bool, validationTime: Date) async -> X509.VerificationResult { | ||
nonisolated func verifyChainWithoutCaching(leaf: Certificate, intermediate: Certificate, online: Bool, validationTime: Date) async -> X509.VerificationResult { | ||
var verifier = Verifier(rootCertificates: self.store) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
RFC5280Policy(validationTime: validationTime) | ||
AppStoreOIDPolicy() | ||
|
@@ -132,7 +131,7 @@ class ChainVerifier { | |
return await verifier.validate(leafCertificate: leaf, intermediates: intermediateStore) | ||
} | ||
|
||
func getDate() -> Date { | ||
nonisolated func getDate() -> Date { | ||
return Date() | ||
} | ||
Comment on lines
-135
to
136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what the intent on making a separate |
||
} | ||
|
@@ -226,6 +225,10 @@ public enum VerificationResult<T> { | |
case invalid(VerificationError) | ||
} | ||
|
||
extension VerificationResult: Equatable where T: Equatable {} | ||
extension VerificationResult: Hashable where T: Hashable {} | ||
extension VerificationResult: Sendable where T: Sendable {} | ||
|
||
public enum VerificationError: Hashable, Sendable { | ||
case INVALID_JWT_FORMAT | ||
case INVALID_CERTIFICATE | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,9 @@ | |
import Foundation | ||
|
||
///A verifier and decoder class designed to decode signed data from the App Store. | ||
public struct SignedDataVerifier { | ||
public struct SignedDataVerifier: Sendable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
public enum ConfigurationError: Error { | ||
public enum ConfigurationError: Error, Hashable, Sendable { | ||
case INVALID_APP_APPLE_ID | ||
} | ||
|
||
|
@@ -148,7 +148,7 @@ public struct SignedDataVerifier { | |
return appTransactionResult | ||
} | ||
|
||
private func decodeSignedData<T: DecodedSignedData>(signedData: String, type: T.Type) async -> VerificationResult<T> where T : Decodable { | ||
private func decodeSignedData<T: DecodedSignedData>(signedData: String, type: T.Type) async -> VerificationResult<T> where T : Decodable & Sendable { | ||
return await chainVerifier.verify(signedData: signedData, type: type, onlineVerification: self.enableOnlineChecks, environment: self.environment) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
ChainVerifier
is now an actor,T
must beSendable
here.