Skip to content

Commit 20e5668

Browse files
committed
Refactor Domain with RFC 1035 and 1123 extensions
- Split Domain implementation into separate RFC extension files - Add Domain+RFC1035.swift for RFC 1035 support - Add Domain+RFC1123.swift for RFC 1123 support - Update main Domain.swift implementation
1 parent 6f03d9d commit 20e5668

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Foundation
2+
import RFC_1035
3+
4+
extension Domain {
5+
// Forward conversion already exists in Domain.swift
6+
// public init(rfc1035: RFC_1035.Domain) throws
7+
}
8+
9+
extension RFC_1035.Domain {
10+
/// Initialize from Domain
11+
///
12+
/// Enables round-trip conversion between Domain and RFC_1035.Domain.
13+
///
14+
/// - Parameter domain: The Domain to convert
15+
/// - Throws: If the Domain doesn't have a valid RFC 1035 representation
16+
public init(_ domain: Domain) throws {
17+
guard let rfc1035 = domain.rfc1035 else {
18+
throw Domain.DomainError.conversionFailure
19+
}
20+
self = rfc1035
21+
}
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Foundation
2+
import RFC_1123
3+
4+
extension Domain {
5+
// Forward conversion already exists in Domain.swift
6+
// public init(rfc1123: RFC_1123.Domain)
7+
}
8+
9+
extension RFC_1123.Domain {
10+
/// Initialize from Domain
11+
///
12+
/// Enables round-trip conversion between Domain and RFC_1123.Domain.
13+
///
14+
/// - Parameter domain: The Domain to convert
15+
/// - Returns: The RFC 1123 domain representation
16+
/// - Note: Since RFC_5321.Domain is RFC_1123.Domain, this always succeeds
17+
public init(_ domain: Domain) {
18+
// RFC 5321 uses RFC 1123 domains directly, so we can always get an RFC 1123 representation
19+
self = domain.rfc5321
20+
}
21+
}

Sources/Domain/Domain.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,19 @@ extension Domain {
5252
}
5353

5454
/// Initialize from RFC1123
55-
public init(rfc1123: RFC_1123.Domain) throws {
55+
/// Note: RFC 5321 reuses RFC 1123 domain definitions, so this conversion is infallible
56+
public init(rfc1123: RFC_1123.Domain) {
5657
self.rfc1035 = nil // RFC1123 may not be RFC1035 compliant
5758
self.rfc1123 = rfc1123
58-
self.rfc5321 = try {
59-
guard let domain = try? RFC_5321.Domain(rfc1123.name) else {
60-
throw DomainError.conversionFailure
61-
}
62-
return domain
63-
}()
59+
// RFC 5321 uses RFC 1123 domains directly (type alias), so this is safe
60+
self.rfc5321 = rfc1123
6461
}
6562

6663
/// Initialize from RFC_5321.Domain
64+
/// Note: RFC_5321.Domain is actually a type alias for RFC_1123.Domain
6765
public init(rfc5321: RFC_5321.Domain) {
6866
self.rfc1035 = nil // RFC_5321.Domain may not be RFC1035 compliant
69-
self.rfc1123 = nil // RFC_5321.Domain may not be RFC1123 compliant
67+
self.rfc1123 = rfc5321 // RFC 5321 uses RFC 1123 domains
7068
self.rfc5321 = rfc5321
7169
}
7270
}

0 commit comments

Comments
 (0)