Skip to content

Commit dd2446b

Browse files
committed
Convert Policy from enum to struct with static factory methods
1 parent d93e3d9 commit dd2446b

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

Sources/SotoSignerCloudFront/CloudFrontSigner+SignedCookies.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension CloudFrontSigner {
2929
/// - date: Date that cookies are valid from, defaults to now
3030
/// - Returns: The cookie values to set in `Set-Cookie` headers
3131
public func signedCookies(url: String, policy: Policy, date: Date = Date()) throws -> SignedCookies {
32-
switch policy {
32+
switch policy._wrapped {
3333
case .canned(let expires):
3434
return try signedCookiesCanned(url: url, expires: expires, date: date)
3535
case .custom(let customPolicy):

Sources/SotoSignerCloudFront/CloudFrontSigner+SignedURL.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension CloudFrontSigner {
2929
/// - date: Date that URL is valid from, defaults to now
3030
/// - Returns: The complete signed URL
3131
public func signedURL(url: String, policy: Policy, date: Date = Date()) throws -> String {
32-
switch policy {
32+
switch policy._wrapped {
3333
case .canned(let expires):
3434
return try signedURLCanned(url: url, expires: expires, date: date)
3535
case .custom(let customPolicy):

Sources/SotoSignerCloudFront/CloudFrontSigner.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,23 @@ public struct CloudFrontSigner: Sendable {
5858
}
5959

6060
/// The signing policy to use for URL or cookie generation.
61-
public enum Policy: Sendable {
61+
public struct Policy: Sendable {
62+
enum _Policy: Sendable {
63+
case canned(expires: TimeAmount)
64+
case custom(CustomPolicy)
65+
}
66+
67+
let _wrapped: _Policy
68+
6269
/// A canned policy that restricts access to a single resource with an expiration.
63-
case canned(expires: TimeAmount)
70+
public static func canned(expires: TimeAmount) -> Policy {
71+
Policy(_wrapped: .canned(expires: expires))
72+
}
73+
6474
/// A custom policy supporting wildcards, IP restrictions, and optional start times.
65-
case custom(CustomPolicy)
75+
public static func custom(_ customPolicy: CustomPolicy) -> Policy {
76+
Policy(_wrapped: .custom(customPolicy))
77+
}
6678
}
6779

6880
/// The cookie values needed for CloudFront signed cookies

0 commit comments

Comments
 (0)