diff --git a/Sources/X509/Verifier/RFC5280/URIConstraints.swift b/Sources/X509/Verifier/RFC5280/URIConstraints.swift index a2c3f523..ac83fd37 100644 --- a/Sources/X509/Verifier/RFC5280/URIConstraints.swift +++ b/Sources/X509/Verifier/RFC5280/URIConstraints.swift @@ -12,8 +12,15 @@ // //===----------------------------------------------------------------------===// -import CoreFoundation import Foundation +#if os(Windows) +import WinSDK +#elseif os(Linux) || os(Android) +import Glibc +import CoreFoundation +#elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS) +import Darwin +#endif extension NameConstraintsPolicy { /// Validates that a URI name matches a name constraint. @@ -58,14 +65,22 @@ extension NameConstraintsPolicy { extension String { @inlinable var isIPAddress: Bool { +#if os(Windows) + var v4: IN_ADDR = IN_ADDR() + var v6: IN6_ADDR = IN6_ADDR() + return self.withCString(encodedAs: UTF16.self) { + return InetPtonW(AF_INET, $0, &v4) == 1 || + InetPtonW(AF_INET6, $0, &v6) == 1 + } +#else // We need some scratch space to let inet_pton write into. var ipv4Addr = in_addr() var ipv6Addr = in6_addr() - return self.withCString { ptr in return inet_pton(AF_INET, ptr, &ipv4Addr) == 1 || inet_pton(AF_INET6, ptr, &ipv6Addr) == 1 } +#endif } }