Skip to content

Commit e271765

Browse files
committed
Change CloudFrontSignerError from enum to struct
Uses a private enum code with static properties for better ABI stability and future extensibility without breaking API changes.
1 parent 8d889f7 commit e271765

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

Sources/SotoSignerCloudFront/CloudFrontSigner+Internal.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ extension CloudFrontSigner {
3131
/// - `/` → `~`
3232
///
3333
/// Note: This is NOT standard base64url (RFC 4648 §5) — CloudFront uses `~` for `/`
34-
/// and `_` for padding `=`, which differs from base64url's `_` for `/` with stripped padding.
35-
/// Therefore `base64EncodedString(options: .base64URLAlphabet)` cannot be used here.
34+
/// and `_` for padding `=`, which differs from base64url's `_` for `/` with padding kept.
35+
/// While `.base64URLAlphabet` (macOS 26.4+) could be used as a starting point with
36+
/// two additional replacements (`_` → `~`, `=` → `_`), it offers no simplification
37+
/// over the current approach and requires a newer deployment target.
3638
static func cloudFrontBase64Encode(_ data: Data) -> String {
3739
let base64 = data.base64EncodedString()
3840
var result = ""

Sources/SotoSignerCloudFront/CloudFrontSignerError.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,24 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
/// Errors that can occur during CloudFront signing operations
16-
public enum CloudFrontSignerError: Error, Sendable {
17-
/// The provided PEM data could not be parsed as an RSA private key
18-
case invalidPrivateKey
16+
public struct CloudFrontSignerError: Error, Sendable, Equatable {
17+
18+
private enum Code: String, Sendable {
19+
case invalidPrivateKey
20+
case invalidURL
21+
case signingFailed
22+
}
23+
24+
private let code: Code
25+
26+
private init(_ code: Code) {
27+
self.code = code
28+
}
29+
30+
/// The provided PEM/DER data could not be parsed as an RSA private key
31+
public static let invalidPrivateKey = CloudFrontSignerError(.invalidPrivateKey)
1932
/// The URL string is not valid
20-
case invalidURL
33+
public static let invalidURL = CloudFrontSignerError(.invalidURL)
2134
/// The signing operation failed
22-
case signingFailed
35+
public static let signingFailed = CloudFrontSignerError(.signingFailed)
2336
}

0 commit comments

Comments
 (0)