diff --git a/Sources/Crypto/AEADs/AES/GCM/AES-GCM.swift b/Sources/Crypto/AEADs/AES/GCM/AES-GCM.swift index 0070f296f..fecedae73 100644 --- a/Sources/Crypto/AEADs/AES/GCM/AES-GCM.swift +++ b/Sources/Crypto/AEADs/AES/GCM/AES-GCM.swift @@ -21,7 +21,11 @@ import Security typealias AESGCMImpl = OpenSSLAESGCMImpl #endif +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension AES { /// The Advanced Encryption Standard (AES) Galois Counter Mode (GCM) cipher diff --git a/Sources/Crypto/AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift b/Sources/Crypto/AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift index 77b1202c0..415846518 100644 --- a/Sources/Crypto/AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift +++ b/Sources/Crypto/AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift @@ -16,7 +16,11 @@ #else @_implementationOnly import CCryptoBoringSSL import CryptoBoringWrapper +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif enum OpenSSLAESGCMImpl { @inlinable diff --git a/Sources/Crypto/AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift b/Sources/Crypto/AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift index 02ff58ea0..7c2efd7f4 100644 --- a/Sources/Crypto/AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift +++ b/Sources/Crypto/AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift @@ -17,7 +17,11 @@ @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims import CryptoBoringWrapper +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension BoringSSLAEAD { /// Seal a given message. diff --git a/Sources/Crypto/AEADs/ChachaPoly/ChaChaPoly.swift b/Sources/Crypto/AEADs/ChachaPoly/ChaChaPoly.swift index bd24bde3d..fab3b1611 100644 --- a/Sources/Crypto/AEADs/ChachaPoly/ChaChaPoly.swift +++ b/Sources/Crypto/AEADs/ChachaPoly/ChaChaPoly.swift @@ -21,7 +21,11 @@ import Security typealias ChaChaPolyImpl = OpenSSLChaChaPolyImpl #endif +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// An implementation of the ChaCha20-Poly1305 cipher. public enum ChaChaPoly: Cipher { diff --git a/Sources/Crypto/AEADs/Cipher.swift b/Sources/Crypto/AEADs/Cipher.swift index 573b4daea..59b6bdb66 100644 --- a/Sources/Crypto/AEADs/Cipher.swift +++ b/Sources/Crypto/AEADs/Cipher.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif protocol AEADSealedBox { associatedtype Nonce: Sequence diff --git a/Sources/Crypto/AEADs/Nonces.swift b/Sources/Crypto/AEADs/Nonces.swift index 184ff3c0b..e62b4f834 100644 --- a/Sources/Crypto/AEADs/Nonces.swift +++ b/Sources/Crypto/AEADs/Nonces.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif // MARK: - Generated file, do NOT edit // any edits of this file WILL be overwritten and thus discarded // see section `gyb` in `README` for details. diff --git a/Sources/Crypto/AEADs/Nonces.swift.gyb b/Sources/Crypto/AEADs/Nonces.swift.gyb index 19a25bb2a..fe75a01c9 100644 --- a/Sources/Crypto/AEADs/Nonces.swift.gyb +++ b/Sources/Crypto/AEADs/Nonces.swift.gyb @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif // MARK: - Generated file, do NOT edit // any edits of this file WILL be overwritten and thus discarded // see section `gyb` in `README` for details. diff --git a/Sources/Crypto/ASN1/ASN1.swift b/Sources/Crypto/ASN1/ASN1.swift index a1d4c250e..54d854782 100644 --- a/Sources/Crypto/ASN1/ASN1.swift +++ b/Sources/Crypto/ASN1/ASN1.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif // This module implements "just enough" ASN.1. Specifically, we implement exactly enough ASN.1 DER parsing to handle // the following use-cases: diff --git a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Any.swift b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Any.swift index 8bec3361f..df6fa2aaf 100644 --- a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Any.swift +++ b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Any.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension ASN1 { /// An ASN1 ANY represents...well, anything. diff --git a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1BitString.swift b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1BitString.swift index 4f00bf682..212cd499b 100644 --- a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1BitString.swift +++ b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1BitString.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension ASN1 { /// A bitstring is a representation of...well...some bits. diff --git a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Boolean.swift b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Boolean.swift index 43510e916..5a7072167 100644 --- a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Boolean.swift +++ b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Boolean.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension Bool: ASN1ImplicitlyTaggable { static var defaultIdentifier: ASN1.ASN1Identifier { diff --git a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Identifier.swift b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Identifier.swift index 6c98f082f..024783a71 100644 --- a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Identifier.swift +++ b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Identifier.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension ASN1 { /// An `ASN1Identifier` is a representation of the abstract notion of an ASN.1 identifier. Identifiers have a number of properties that relate to both the specific diff --git a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Integer.swift b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Integer.swift index d8101c4e7..c4287eb9e 100644 --- a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Integer.swift +++ b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Integer.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// A protocol that represents any internal object that can present itself as an INTEGER, or be parsed from /// an INTEGER. diff --git a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Null.swift b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Null.swift index 83fb8646f..9017987bf 100644 --- a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Null.swift +++ b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Null.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension ASN1 { /// An ASN1 NULL represents nothing. diff --git a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1OctetString.swift b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1OctetString.swift index f7e1336d6..624d5ae43 100644 --- a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1OctetString.swift +++ b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1OctetString.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension ASN1 { /// An octet string is a representation of a string of octets. diff --git a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Strings.swift b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Strings.swift index f2fc25bd9..27f36f1a9 100644 --- a/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Strings.swift +++ b/Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Strings.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension ASN1 { /// A UTF8String is roughly what it sounds like. We note that all the string types are encoded as implicitly tagged diff --git a/Sources/Crypto/ASN1/Basic ASN1 Types/GeneralizedTime.swift b/Sources/Crypto/ASN1/Basic ASN1 Types/GeneralizedTime.swift index d4c117498..4dc667c58 100644 --- a/Sources/Crypto/ASN1/Basic ASN1 Types/GeneralizedTime.swift +++ b/Sources/Crypto/ASN1/Basic ASN1 Types/GeneralizedTime.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension ASN1 { struct GeneralizedTime: ASN1ImplicitlyTaggable, Hashable { diff --git a/Sources/Crypto/ASN1/Basic ASN1 Types/ObjectIdentifier.swift b/Sources/Crypto/ASN1/Basic ASN1 Types/ObjectIdentifier.swift index e7af81e5a..cec9f15c7 100644 --- a/Sources/Crypto/ASN1/Basic ASN1 Types/ObjectIdentifier.swift +++ b/Sources/Crypto/ASN1/Basic ASN1 Types/ObjectIdentifier.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension ASN1 { /// An Object Identifier is a representation of some kind of object: really any kind of object. diff --git a/Sources/Crypto/ASN1/ECDSASignature.swift b/Sources/Crypto/ASN1/ECDSASignature.swift index 5b901e515..6cf7bd200 100644 --- a/Sources/Crypto/ASN1/ECDSASignature.swift +++ b/Sources/Crypto/ASN1/ECDSASignature.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension ASN1 { /// An ECDSA signature is laid out as follows: diff --git a/Sources/Crypto/ASN1/PEMDocument.swift b/Sources/Crypto/ASN1/PEMDocument.swift index 9e0c2b6a0..094c024b5 100644 --- a/Sources/Crypto/ASN1/PEMDocument.swift +++ b/Sources/Crypto/ASN1/PEMDocument.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension ASN1 { /// A PEM document is some data, and a discriminator type that is used to advertise the content. diff --git a/Sources/Crypto/ASN1/PKCS8PrivateKey.swift b/Sources/Crypto/ASN1/PKCS8PrivateKey.swift index b247776e5..95890c2a1 100644 --- a/Sources/Crypto/ASN1/PKCS8PrivateKey.swift +++ b/Sources/Crypto/ASN1/PKCS8PrivateKey.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension ASN1 { // A PKCS#8 private key is one of two formats, depending on the version: diff --git a/Sources/Crypto/ASN1/SEC1PrivateKey.swift b/Sources/Crypto/ASN1/SEC1PrivateKey.swift index 5236a05c3..30198c39c 100644 --- a/Sources/Crypto/ASN1/SEC1PrivateKey.swift +++ b/Sources/Crypto/ASN1/SEC1PrivateKey.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension ASN1 { // For private keys, SEC 1 uses: diff --git a/Sources/Crypto/ASN1/SubjectPublicKeyInfo.swift b/Sources/Crypto/ASN1/SubjectPublicKeyInfo.swift index 826c0478f..bc45f9ce7 100644 --- a/Sources/Crypto/ASN1/SubjectPublicKeyInfo.swift +++ b/Sources/Crypto/ASN1/SubjectPublicKeyInfo.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension ASN1 { struct SubjectPublicKeyInfo: ASN1ImplicitlyTaggable { diff --git a/Sources/Crypto/Digests/Digest.swift b/Sources/Crypto/Digests/Digest.swift index 7ebd8c978..79fa724b4 100644 --- a/Sources/Crypto/Digests/Digest.swift +++ b/Sources/Crypto/Digests/Digest.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// A type that represents the output of a hash. public protocol Digest: Hashable, ContiguousBytes, CustomStringConvertible, Sequence where Element == UInt8 { diff --git a/Sources/Crypto/Digests/HashFunctions.swift b/Sources/Crypto/Digests/HashFunctions.swift index 24a28d1a1..c06e17838 100644 --- a/Sources/Crypto/Digests/HashFunctions.swift +++ b/Sources/Crypto/Digests/HashFunctions.swift @@ -20,7 +20,11 @@ typealias DigestImpl = CoreCryptoDigestImpl typealias DigestImpl = OpenSSLDigestImpl #endif +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// A type that performs cryptographically secure hashing. /// diff --git a/Sources/Crypto/HPKE/Ciphersuite/HPKE-AEAD.swift b/Sources/Crypto/HPKE/Ciphersuite/HPKE-AEAD.swift index af63f5623..c7675b055 100644 --- a/Sources/Crypto/HPKE/Ciphersuite/HPKE-AEAD.swift +++ b/Sources/Crypto/HPKE/Ciphersuite/HPKE-AEAD.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension HPKE { diff --git a/Sources/Crypto/HPKE/Ciphersuite/HPKE-Ciphersuite.swift b/Sources/Crypto/HPKE/Ciphersuite/HPKE-Ciphersuite.swift index 81de87a4e..97a726e4f 100644 --- a/Sources/Crypto/HPKE/Ciphersuite/HPKE-Ciphersuite.swift +++ b/Sources/Crypto/HPKE/Ciphersuite/HPKE-Ciphersuite.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension HPKE { diff --git a/Sources/Crypto/HPKE/Ciphersuite/HPKE-KDF.swift b/Sources/Crypto/HPKE/Ciphersuite/HPKE-KDF.swift index b8bb0f35b..e1654efaf 100644 --- a/Sources/Crypto/HPKE/Ciphersuite/HPKE-KDF.swift +++ b/Sources/Crypto/HPKE/Ciphersuite/HPKE-KDF.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension HPKE { /// The key derivation functions to use in HPKE. diff --git a/Sources/Crypto/HPKE/Ciphersuite/HPKE-KexKeyDerivation.swift b/Sources/Crypto/HPKE/Ciphersuite/HPKE-KexKeyDerivation.swift index c3135e54b..ee8aab8f2 100644 --- a/Sources/Crypto/HPKE/Ciphersuite/HPKE-KexKeyDerivation.swift +++ b/Sources/Crypto/HPKE/Ciphersuite/HPKE-KexKeyDerivation.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif private let suiteIDLabel = Data("KEM".utf8) diff --git a/Sources/Crypto/HPKE/Ciphersuite/HPKE-LabeledExtract.swift b/Sources/Crypto/HPKE/Ciphersuite/HPKE-LabeledExtract.swift index bd7f4e29c..1d718dd10 100644 --- a/Sources/Crypto/HPKE/Ciphersuite/HPKE-LabeledExtract.swift +++ b/Sources/Crypto/HPKE/Ciphersuite/HPKE-LabeledExtract.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif private let protocolLabel = Data("HPKE-v1".utf8) private let eaePRKLabel = Data("eae_prk".utf8) diff --git a/Sources/Crypto/HPKE/Ciphersuite/HPKE-Utils.swift b/Sources/Crypto/HPKE/Ciphersuite/HPKE-Utils.swift index 01cae7183..20d4830fb 100644 --- a/Sources/Crypto/HPKE/Ciphersuite/HPKE-Utils.swift +++ b/Sources/Crypto/HPKE/Ciphersuite/HPKE-Utils.swift @@ -14,7 +14,22 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#if canImport(Glibc) +import Glibc +#elseif canImport(Musl) +import Musl +#elseif os(Windows) +import CRT +#elseif canImport(Android) +import Android +#else +import Darwin.C +#endif +#else import Foundation +#endif internal func I2OSP(value: Int, outputByteCount: Int) -> Data { precondition(outputByteCount > 0, "Cannot I2OSP with no output length.") diff --git a/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/DHKEM.swift b/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/DHKEM.swift index 52fe85cef..3737c57cb 100644 --- a/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/DHKEM.swift +++ b/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/DHKEM.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// A type that ``HPKE`` uses to encode the public key. public protocol HPKEPublicKeySerialization { diff --git a/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/HPKE-KEM-Curve25519.swift b/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/HPKE-KEM-Curve25519.swift index 2c03eb94b..ffcd6f075 100644 --- a/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/HPKE-KEM-Curve25519.swift +++ b/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/HPKE-KEM-Curve25519.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension Curve25519.KeyAgreement.PrivateKey: HPKEDiffieHellmanPrivateKeyGeneration {} diff --git a/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/HPKE-NIST-EC-KEMs.swift b/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/HPKE-NIST-EC-KEMs.swift index 9a8d8f090..ac18b056b 100644 --- a/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/HPKE-NIST-EC-KEMs.swift +++ b/Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/HPKE-NIST-EC-KEMs.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif diff --git a/Sources/Crypto/HPKE/Ciphersuite/KEM/HPKE-KEM.swift b/Sources/Crypto/HPKE/Ciphersuite/KEM/HPKE-KEM.swift index 4faee587c..218a66f6e 100644 --- a/Sources/Crypto/HPKE/Ciphersuite/KEM/HPKE-KEM.swift +++ b/Sources/Crypto/HPKE/Ciphersuite/KEM/HPKE-KEM.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension HPKE { /// The key encapsulation mechanisms to use in HPKE. diff --git a/Sources/Crypto/HPKE/HPKE-Errors.swift b/Sources/Crypto/HPKE/HPKE-Errors.swift index cc83de29f..a09f00922 100644 --- a/Sources/Crypto/HPKE/HPKE-Errors.swift +++ b/Sources/Crypto/HPKE/HPKE-Errors.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension HPKE { /// Hybrid public key encryption (HPKE) errors that CryptoKit uses. diff --git a/Sources/Crypto/HPKE/HPKE.swift b/Sources/Crypto/HPKE/HPKE.swift index 49e80872b..3306a3726 100644 --- a/Sources/Crypto/HPKE/HPKE.swift +++ b/Sources/Crypto/HPKE/HPKE.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// A container for hybrid public key encryption (HPKE) operations. /// diff --git a/Sources/Crypto/HPKE/Key Schedule/HPKE-Context.swift b/Sources/Crypto/HPKE/Key Schedule/HPKE-Context.swift index a018c063c..26fceea67 100644 --- a/Sources/Crypto/HPKE/Key Schedule/HPKE-Context.swift +++ b/Sources/Crypto/HPKE/Key Schedule/HPKE-Context.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension HPKE { struct Context { diff --git a/Sources/Crypto/HPKE/Key Schedule/HPKE-KeySchedule.swift b/Sources/Crypto/HPKE/Key Schedule/HPKE-KeySchedule.swift index dda34b0a7..b27eb4d00 100644 --- a/Sources/Crypto/HPKE/Key Schedule/HPKE-KeySchedule.swift +++ b/Sources/Crypto/HPKE/Key Schedule/HPKE-KeySchedule.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension HPKE { internal struct KeySchedule { diff --git a/Sources/Crypto/KEM/KEM.swift b/Sources/Crypto/KEM/KEM.swift index c66243ebf..ed5326c89 100644 --- a/Sources/Crypto/KEM/KEM.swift +++ b/Sources/Crypto/KEM/KEM.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// A Key Encapsulation Mechanism public enum KEM { diff --git a/Sources/Crypto/Key Agreement/DH.swift b/Sources/Crypto/Key Agreement/DH.swift index a39bbd479..0b6182f8c 100644 --- a/Sources/Crypto/Key Agreement/DH.swift +++ b/Sources/Crypto/Key Agreement/DH.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// A Diffie-Hellman Key Agreement Key public protocol DiffieHellmanKeyAgreement { diff --git a/Sources/Crypto/Key Agreement/ECDH.swift b/Sources/Crypto/Key Agreement/ECDH.swift index 03c47769d..2a1fc0509 100644 --- a/Sources/Crypto/Key Agreement/ECDH.swift +++ b/Sources/Crypto/Key Agreement/ECDH.swift @@ -22,7 +22,11 @@ typealias NISTCurvePublicKeyImpl = OpenSSLNISTCurvePublicKeyImpl typealias NISTCurvePrivateKeyImpl = OpenSSLNISTCurvePrivateKeyImpl #endif +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif // MARK: - Generated file, do NOT edit // any edits of this file WILL be overwritten and thus discarded diff --git a/Sources/Crypto/Key Agreement/ECDH.swift.gyb b/Sources/Crypto/Key Agreement/ECDH.swift.gyb index d4aae6b7a..a1d944a5a 100644 --- a/Sources/Crypto/Key Agreement/ECDH.swift.gyb +++ b/Sources/Crypto/Key Agreement/ECDH.swift.gyb @@ -22,7 +22,11 @@ typealias NISTCurvePublicKeyImpl = OpenSSLNISTCurvePublicKeyImpl typealias NISTCurvePrivateKeyImpl = OpenSSLNISTCurvePrivateKeyImpl #endif +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif // MARK: - Generated file, do NOT edit // any edits of this file WILL be overwritten and thus discarded diff --git a/Sources/Crypto/Key Derivation/HKDF.swift b/Sources/Crypto/Key Derivation/HKDF.swift index 25a0c2f29..8954cfda8 100644 --- a/Sources/Crypto/Key Derivation/HKDF.swift +++ b/Sources/Crypto/Key Derivation/HKDF.swift @@ -14,7 +14,22 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#if canImport(Glibc) +import Glibc +#elseif canImport(Musl) +import Musl +#elseif os(Windows) +import CRT +#elseif canImport(Android) +import Android +#else +import Darwin.C +#endif +#else import Foundation +#endif #if canImport(Android) import Android #endif diff --git a/Sources/Crypto/Key Wrapping/AESWrap.swift b/Sources/Crypto/Key Wrapping/AESWrap.swift index fbc0ba768..1888be9ec 100644 --- a/Sources/Crypto/Key Wrapping/AESWrap.swift +++ b/Sources/Crypto/Key Wrapping/AESWrap.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif #if !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API typealias AESWRAPImpl = CoreCryptoAESWRAPImpl diff --git a/Sources/Crypto/Key Wrapping/BoringSSL/AESWrap_boring.swift b/Sources/Crypto/Key Wrapping/BoringSSL/AESWrap_boring.swift index 2f6320191..2c8ce0d78 100644 --- a/Sources/Crypto/Key Wrapping/BoringSSL/AESWrap_boring.swift +++ b/Sources/Crypto/Key Wrapping/BoringSSL/AESWrap_boring.swift @@ -15,7 +15,11 @@ @_exported import CryptoKit #else @_implementationOnly import CCryptoBoringSSL +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif enum BoringSSLAESWRAPImpl { static func wrap(key: SymmetricKey, keyToWrap: SymmetricKey) throws -> Data { diff --git a/Sources/Crypto/Keys/EC/BoringSSL/Ed25519_boring.swift b/Sources/Crypto/Keys/EC/BoringSSL/Ed25519_boring.swift index db9bef53d..fb871d6df 100644 --- a/Sources/Crypto/Keys/EC/BoringSSL/Ed25519_boring.swift +++ b/Sources/Crypto/Keys/EC/BoringSSL/Ed25519_boring.swift @@ -16,7 +16,11 @@ #else @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif // For signing and verifying, we use BoringSSL's Ed25519, not the X25519 stuff. extension Curve25519.Signing { diff --git a/Sources/Crypto/Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift b/Sources/Crypto/Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift index eb09526ae..fb30c99ef 100644 --- a/Sources/Crypto/Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift +++ b/Sources/Crypto/Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift @@ -17,7 +17,11 @@ @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims import CryptoBoringWrapper +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif @usableFromInline protocol OpenSSLSupportedNISTCurve { diff --git a/Sources/Crypto/Keys/EC/BoringSSL/X25519Keys_boring.swift b/Sources/Crypto/Keys/EC/BoringSSL/X25519Keys_boring.swift index 492ff2cee..88ea0a9d9 100644 --- a/Sources/Crypto/Keys/EC/BoringSSL/X25519Keys_boring.swift +++ b/Sources/Crypto/Keys/EC/BoringSSL/X25519Keys_boring.swift @@ -16,7 +16,11 @@ #else @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension Curve25519.KeyAgreement { @usableFromInline diff --git a/Sources/Crypto/Keys/EC/Ed25519Keys.swift b/Sources/Crypto/Keys/EC/Ed25519Keys.swift index bc3aecdb2..fb002a289 100644 --- a/Sources/Crypto/Keys/EC/Ed25519Keys.swift +++ b/Sources/Crypto/Keys/EC/Ed25519Keys.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension Curve25519.Signing { static var keyByteCount: Int { diff --git a/Sources/Crypto/Keys/EC/NISTCurvesKeys.swift b/Sources/Crypto/Keys/EC/NISTCurvesKeys.swift index fb16fa07b..4aad7cf47 100644 --- a/Sources/Crypto/Keys/EC/NISTCurvesKeys.swift +++ b/Sources/Crypto/Keys/EC/NISTCurvesKeys.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit diff --git a/Sources/Crypto/Keys/EC/X25519Keys.swift b/Sources/Crypto/Keys/EC/X25519Keys.swift index 2ea9dce1d..4979ff9f9 100644 --- a/Sources/Crypto/Keys/EC/X25519Keys.swift +++ b/Sources/Crypto/Keys/EC/X25519Keys.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension Curve25519.KeyAgreement { static var keyByteCount: Int { diff --git a/Sources/Crypto/Keys/Symmetric/SymmetricKeys.swift b/Sources/Crypto/Keys/Symmetric/SymmetricKeys.swift index 8bb9022ad..c42b0aabb 100644 --- a/Sources/Crypto/Keys/Symmetric/SymmetricKeys.swift +++ b/Sources/Crypto/Keys/Symmetric/SymmetricKeys.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// The sizes that a symmetric cryptographic key can take. /// diff --git a/Sources/Crypto/Message Authentication Codes/HMAC/HMAC.swift b/Sources/Crypto/Message Authentication Codes/HMAC/HMAC.swift index 5ef71a555..deb02cdca 100644 --- a/Sources/Crypto/Message Authentication Codes/HMAC/HMAC.swift +++ b/Sources/Crypto/Message Authentication Codes/HMAC/HMAC.swift @@ -14,7 +14,22 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#if canImport(Glibc) +import Glibc +#elseif canImport(Musl) +import Musl +#elseif os(Windows) +import CRT +#elseif canImport(Android) +import Android +#else +import Darwin.C +#endif +#else import Foundation +#endif /// A hash-based message authentication algorithm. /// diff --git a/Sources/Crypto/Message Authentication Codes/MACFunctions.swift b/Sources/Crypto/Message Authentication Codes/MACFunctions.swift index a9222a0ca..4c94193c2 100644 --- a/Sources/Crypto/Message Authentication Codes/MACFunctions.swift +++ b/Sources/Crypto/Message Authentication Codes/MACFunctions.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif protocol MACAlgorithm { associatedtype Key diff --git a/Sources/Crypto/Message Authentication Codes/MessageAuthenticationCode.swift b/Sources/Crypto/Message Authentication Codes/MessageAuthenticationCode.swift index 0820072c5..2b8d87a13 100644 --- a/Sources/Crypto/Message Authentication Codes/MessageAuthenticationCode.swift +++ b/Sources/Crypto/Message Authentication Codes/MessageAuthenticationCode.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// A type that represents a message authentication code. public protocol MessageAuthenticationCode: Hashable, ContiguousBytes, CustomStringConvertible, Sequence where Element == UInt8 { diff --git a/Sources/Crypto/Signatures/BoringSSL/ECDSASignature_boring.swift b/Sources/Crypto/Signatures/BoringSSL/ECDSASignature_boring.swift index 73ab53195..e480df05e 100644 --- a/Sources/Crypto/Signatures/BoringSSL/ECDSASignature_boring.swift +++ b/Sources/Crypto/Signatures/BoringSSL/ECDSASignature_boring.swift @@ -17,7 +17,11 @@ @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims import CryptoBoringWrapper +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// A wrapper around BoringSSL's ECDSA_SIG with some lifetime management. class ECDSASignature { diff --git a/Sources/Crypto/Signatures/BoringSSL/ECDSA_boring.swift b/Sources/Crypto/Signatures/BoringSSL/ECDSA_boring.swift index ff367031b..18fa0d1ea 100644 --- a/Sources/Crypto/Signatures/BoringSSL/ECDSA_boring.swift +++ b/Sources/Crypto/Signatures/BoringSSL/ECDSA_boring.swift @@ -16,7 +16,11 @@ #else @_implementationOnly import CCryptoBoringSSL import CryptoBoringWrapper +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension Data { init( diff --git a/Sources/Crypto/Signatures/BoringSSL/EdDSA_boring.swift b/Sources/Crypto/Signatures/BoringSSL/EdDSA_boring.swift index f6219b47b..afd5b51ea 100644 --- a/Sources/Crypto/Signatures/BoringSSL/EdDSA_boring.swift +++ b/Sources/Crypto/Signatures/BoringSSL/EdDSA_boring.swift @@ -16,7 +16,11 @@ #else @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension Curve25519.Signing.PublicKey { // We do this to enable inlinability on these methods. diff --git a/Sources/Crypto/Signatures/ECDSA.swift b/Sources/Crypto/Signatures/ECDSA.swift index 4056f1933..049b713b6 100644 --- a/Sources/Crypto/Signatures/ECDSA.swift +++ b/Sources/Crypto/Signatures/ECDSA.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif // MARK: - Generated file, do NOT edit // any edits of this file WILL be overwritten and thus discarded // see section `gyb` in `README` for details. diff --git a/Sources/Crypto/Signatures/ECDSA.swift.gyb b/Sources/Crypto/Signatures/ECDSA.swift.gyb index f297738f4..05ed8e3c4 100644 --- a/Sources/Crypto/Signatures/ECDSA.swift.gyb +++ b/Sources/Crypto/Signatures/ECDSA.swift.gyb @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif // MARK: - Generated file, do NOT edit // any edits of this file WILL be overwritten and thus discarded // see section `gyb` in `README` for details. diff --git a/Sources/Crypto/Signatures/Ed25519.swift b/Sources/Crypto/Signatures/Ed25519.swift index bcec7a600..670b243ca 100644 --- a/Sources/Crypto/Signatures/Ed25519.swift +++ b/Sources/Crypto/Signatures/Ed25519.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif protocol DigestValidator { associatedtype Signature diff --git a/Sources/Crypto/Signatures/Signature.swift b/Sources/Crypto/Signatures/Signature.swift index 33a5c7f70..2f36ce5bd 100644 --- a/Sources/Crypto/Signatures/Signature.swift +++ b/Sources/Crypto/Signatures/Signature.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif protocol SignatureVerification { func verifySignature(signature: Data, data: Data) throws -> Bool diff --git a/Sources/Crypto/Util/BoringSSL/SafeCompare_boring.swift b/Sources/Crypto/Util/BoringSSL/SafeCompare_boring.swift index af93dc8d1..e769535bc 100644 --- a/Sources/Crypto/Util/BoringSSL/SafeCompare_boring.swift +++ b/Sources/Crypto/Util/BoringSSL/SafeCompare_boring.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// This function performs a safe comparison between two buffers of bytes. It exists as a temporary shim until we refactor /// some of the usage sites to pass better data structures to us. diff --git a/Sources/Crypto/Util/PrettyBytes.swift b/Sources/Crypto/Util/PrettyBytes.swift index 7610e5c0d..5b34bf383 100644 --- a/Sources/Crypto/Util/PrettyBytes.swift +++ b/Sources/Crypto/Util/PrettyBytes.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif enum ByteHexEncodingErrors: Error { case incorrectHexValue diff --git a/Sources/Crypto/Util/SafeCompare.swift b/Sources/Crypto/Util/SafeCompare.swift index 916c19085..cbe520239 100644 --- a/Sources/Crypto/Util/SafeCompare.swift +++ b/Sources/Crypto/Util/SafeCompare.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif internal func safeCompare(_ lhs: LHS, _ rhs: RHS) -> Bool { #if !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API diff --git a/Sources/Crypto/Util/SecureBytes.swift b/Sources/Crypto/Util/SecureBytes.swift index 7bfcb98ab..aee6205a3 100644 --- a/Sources/Crypto/Util/SecureBytes.swift +++ b/Sources/Crypto/Util/SecureBytes.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif private let emptyStorage:SecureBytes.Backing = SecureBytes.Backing.createEmpty() diff --git a/Sources/Crypto/Util/Zeroization.swift b/Sources/Crypto/Util/Zeroization.swift index 54f760141..8622723b6 100644 --- a/Sources/Crypto/Util/Zeroization.swift +++ b/Sources/Crypto/Util/Zeroization.swift @@ -14,7 +14,11 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif protocol Zeroization { mutating func zeroize() diff --git a/Sources/CryptoBoringWrapper/AEAD/BoringSSLAEAD.swift b/Sources/CryptoBoringWrapper/AEAD/BoringSSLAEAD.swift index 7ef217157..64af28b32 100644 --- a/Sources/CryptoBoringWrapper/AEAD/BoringSSLAEAD.swift +++ b/Sources/CryptoBoringWrapper/AEAD/BoringSSLAEAD.swift @@ -14,7 +14,12 @@ @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims + +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// An abstraction over a BoringSSL AEAD public enum BoringSSLAEAD { diff --git a/Sources/CryptoBoringWrapper/Util/ArbitraryPrecisionInteger.swift b/Sources/CryptoBoringWrapper/Util/ArbitraryPrecisionInteger.swift index ebf60ba17..edf74e40a 100644 --- a/Sources/CryptoBoringWrapper/Util/ArbitraryPrecisionInteger.swift +++ b/Sources/CryptoBoringWrapper/Util/ArbitraryPrecisionInteger.swift @@ -16,7 +16,11 @@ #else @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// A wrapper around the OpenSSL BIGNUM object that is appropriately lifetime managed, /// and that provides better Swift types for this object. diff --git a/Sources/CryptoBoringWrapper/Util/FiniteFieldArithmeticContext.swift b/Sources/CryptoBoringWrapper/Util/FiniteFieldArithmeticContext.swift index 32ae2083e..8790189d7 100644 --- a/Sources/CryptoBoringWrapper/Util/FiniteFieldArithmeticContext.swift +++ b/Sources/CryptoBoringWrapper/Util/FiniteFieldArithmeticContext.swift @@ -15,7 +15,11 @@ @_exported import CryptoKit #else @_implementationOnly import CCryptoBoringSSL +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// A context for performing mathematical operations on ArbitraryPrecisionIntegers over a finite field. /// diff --git a/Sources/_CryptoExtras/AES/AES_CBC.swift b/Sources/_CryptoExtras/AES/AES_CBC.swift index 3363ddbd5..7c2ba8b22 100644 --- a/Sources/_CryptoExtras/AES/AES_CBC.swift +++ b/Sources/_CryptoExtras/AES/AES_CBC.swift @@ -13,7 +13,11 @@ //===----------------------------------------------------------------------===// import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension AES { /// The Advanced Encryption Standard (AES) Cipher Block Chaining (CBC) cipher diff --git a/Sources/_CryptoExtras/AES/AES_CFB.swift b/Sources/_CryptoExtras/AES/AES_CFB.swift index c11ade316..9d37d8c93 100644 --- a/Sources/_CryptoExtras/AES/AES_CFB.swift +++ b/Sources/_CryptoExtras/AES/AES_CFB.swift @@ -13,7 +13,11 @@ //===----------------------------------------------------------------------===// import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif @usableFromInline typealias AESCFBImpl = OpenSSLAESCFBImpl diff --git a/Sources/_CryptoExtras/AES/AES_CTR.swift b/Sources/_CryptoExtras/AES/AES_CTR.swift index 0972e6c6c..17b71aee3 100644 --- a/Sources/_CryptoExtras/AES/AES_CTR.swift +++ b/Sources/_CryptoExtras/AES/AES_CTR.swift @@ -13,7 +13,11 @@ //===----------------------------------------------------------------------===// import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif @usableFromInline typealias AESCTRImpl = OpenSSLAESCTRImpl diff --git a/Sources/_CryptoExtras/AES/AES_GCM_SIV.swift b/Sources/_CryptoExtras/AES/AES_GCM_SIV.swift index 8bce512cc..1ed739457 100644 --- a/Sources/_CryptoExtras/AES/AES_GCM_SIV.swift +++ b/Sources/_CryptoExtras/AES/AES_GCM_SIV.swift @@ -16,7 +16,11 @@ import Crypto @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims import CryptoBoringWrapper +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// Types associated with the AES GCM SIV algorithm extension AES.GCM { diff --git a/Sources/_CryptoExtras/AES/Block Function.swift b/Sources/_CryptoExtras/AES/Block Function.swift index 3db5f73d3..a7948bd3f 100644 --- a/Sources/_CryptoExtras/AES/Block Function.swift +++ b/Sources/_CryptoExtras/AES/Block Function.swift @@ -16,7 +16,11 @@ import Crypto @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims import CryptoBoringWrapper +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension AES { private static let blockSize = 128 / 8 diff --git a/Sources/_CryptoExtras/AES/BoringSSL/AES_CFB_boring.swift b/Sources/_CryptoExtras/AES/BoringSSL/AES_CFB_boring.swift index 578302840..1448dab76 100644 --- a/Sources/_CryptoExtras/AES/BoringSSL/AES_CFB_boring.swift +++ b/Sources/_CryptoExtras/AES/BoringSSL/AES_CFB_boring.swift @@ -14,7 +14,12 @@ @_implementationOnly import CCryptoBoringSSL import Crypto + +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif @usableFromInline enum OpenSSLAESCFBImpl { diff --git a/Sources/_CryptoExtras/AES/BoringSSL/AES_CTR_boring.swift b/Sources/_CryptoExtras/AES/BoringSSL/AES_CTR_boring.swift index 8ec43c7cc..c3c5f400f 100644 --- a/Sources/_CryptoExtras/AES/BoringSSL/AES_CTR_boring.swift +++ b/Sources/_CryptoExtras/AES/BoringSSL/AES_CTR_boring.swift @@ -14,7 +14,12 @@ @_implementationOnly import CCryptoBoringSSL import Crypto + +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif @usableFromInline enum OpenSSLAESCTRImpl { diff --git a/Sources/_CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift b/Sources/_CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift index 8312db7a5..c657e3457 100644 --- a/Sources/_CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift +++ b/Sources/_CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift @@ -18,7 +18,12 @@ @_implementationOnly import CCryptoBoringSSLShims import Crypto import CryptoBoringWrapper + +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension BoringSSLAEAD { /// Seal a given message. diff --git a/Sources/_CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift b/Sources/_CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift index e4684c392..6bca1ff14 100644 --- a/Sources/_CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift +++ b/Sources/_CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift @@ -16,7 +16,12 @@ @_implementationOnly import CCryptoBoringSSLShims import Crypto import CryptoBoringWrapper + +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif enum OpenSSLChaCha20CTRImpl { static func encrypt( diff --git a/Sources/_CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift b/Sources/_CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift index 449bd7a05..2bf2947d7 100644 --- a/Sources/_CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift +++ b/Sources/_CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift @@ -16,7 +16,11 @@ @_implementationOnly import CCryptoBoringSSLShims import Crypto import CryptoBoringWrapper +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif typealias ChaCha20CTRImpl = OpenSSLChaCha20CTRImpl diff --git a/Sources/_CryptoExtras/ECToolbox/BoringSSL/ECToolbox_boring.swift b/Sources/_CryptoExtras/ECToolbox/BoringSSL/ECToolbox_boring.swift index de2868915..d9b66a99e 100644 --- a/Sources/_CryptoExtras/ECToolbox/BoringSSL/ECToolbox_boring.swift +++ b/Sources/_CryptoExtras/ECToolbox/BoringSSL/ECToolbox_boring.swift @@ -13,7 +13,12 @@ //===----------------------------------------------------------------------===// import Crypto import CryptoBoringWrapper + +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// NOTE: This protocol is different from `Crypto.OpenSSLSupportedNISTCurve` module and has additional requirements to /// support ECToolbox. It is (re-)defined here because its counterpart in the Crypto module is only conditionally diff --git a/Sources/_CryptoExtras/ECToolbox/ECToolbox.swift b/Sources/_CryptoExtras/ECToolbox/ECToolbox.swift index 8d4366a64..7bcc3f863 100644 --- a/Sources/_CryptoExtras/ECToolbox/ECToolbox.swift +++ b/Sources/_CryptoExtras/ECToolbox/ECToolbox.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif #if canImport(Darwin) && !CRYPTO_IN_SWIFTPM typealias SupportedCurveDetailsImpl = CorecryptoSupportedNISTCurve diff --git a/Sources/_CryptoExtras/H2G/HashToField.swift b/Sources/_CryptoExtras/H2G/HashToField.swift index 9c8b0fd01..59db76291 100644 --- a/Sources/_CryptoExtras/H2G/HashToField.swift +++ b/Sources/_CryptoExtras/H2G/HashToField.swift @@ -11,7 +11,22 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#if canImport(Glibc) +import Glibc +#elseif canImport(Musl) +import Musl +#elseif os(Windows) +import CRT +#elseif canImport(Android) +import Android +#else +import Darwin.C +#endif +#else import Foundation +#endif import Crypto extension Data { diff --git a/Sources/_CryptoExtras/Key Derivation/KDF.swift b/Sources/_CryptoExtras/Key Derivation/KDF.swift index f07413e77..f27c3a617 100644 --- a/Sources/_CryptoExtras/Key Derivation/KDF.swift +++ b/Sources/_CryptoExtras/Key Derivation/KDF.swift @@ -12,11 +12,15 @@ // //===----------------------------------------------------------------------===// import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else #if canImport(Darwin) || swift(>=5.9.1) import Foundation #else @preconcurrency import Foundation #endif +#endif /// A container for Key Detivation Function algorithms. public enum KDF: Sendable { diff --git a/Sources/_CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_boring.swift b/Sources/_CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_boring.swift index e19ceefdd..f7940dcb3 100644 --- a/Sources/_CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_boring.swift +++ b/Sources/_CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_boring.swift @@ -14,7 +14,11 @@ import Crypto #if canImport(Darwin) || swift(>=5.9.1) +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif #else @preconcurrency import Foundation #endif diff --git a/Sources/_CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_commoncrypto.swift b/Sources/_CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_commoncrypto.swift index 61bad9f95..a44380f8e 100644 --- a/Sources/_CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_commoncrypto.swift +++ b/Sources/_CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_commoncrypto.swift @@ -13,11 +13,15 @@ //===----------------------------------------------------------------------===// import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else #if canImport(Darwin) || swift(>=5.9.1) import Foundation #else @preconcurrency import Foundation #endif +#endif #if canImport(CommonCrypto) @_implementationOnly import CommonCrypto diff --git a/Sources/_CryptoExtras/Key Derivation/PBKDF2/PBKDF2.swift b/Sources/_CryptoExtras/Key Derivation/PBKDF2/PBKDF2.swift index 3a8556537..e3dd9aaec 100644 --- a/Sources/_CryptoExtras/Key Derivation/PBKDF2/PBKDF2.swift +++ b/Sources/_CryptoExtras/Key Derivation/PBKDF2/PBKDF2.swift @@ -12,11 +12,15 @@ // //===----------------------------------------------------------------------===// import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else #if canImport(Darwin) || swift(>=5.9.1) import Foundation #else @preconcurrency import Foundation #endif +#endif #if canImport(CommonCrypto) fileprivate typealias BackingPBKDF2 = CommonCryptoPBKDF2 diff --git a/Sources/_CryptoExtras/Key Derivation/Scrypt/BoringSSL/Scrypt_boring.swift b/Sources/_CryptoExtras/Key Derivation/Scrypt/BoringSSL/Scrypt_boring.swift index 00520ea19..11ed1316e 100644 --- a/Sources/_CryptoExtras/Key Derivation/Scrypt/BoringSSL/Scrypt_boring.swift +++ b/Sources/_CryptoExtras/Key Derivation/Scrypt/BoringSSL/Scrypt_boring.swift @@ -16,11 +16,26 @@ @_implementationOnly import CCryptoBoringSSLShims import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#if canImport(Glibc) +import Glibc +#elseif canImport(Musl) +import Musl +#elseif os(Windows) +import CRT +#elseif canImport(Android) +import Android +#else +import Darwin.C +#endif +#else #if canImport(Darwin) || swift(>=5.9.1) import Foundation #else @preconcurrency import Foundation #endif +#endif #if canImport(Android) import Android diff --git a/Sources/_CryptoExtras/Key Derivation/Scrypt/Scrypt.swift b/Sources/_CryptoExtras/Key Derivation/Scrypt/Scrypt.swift index cae5f773e..8b66e0b00 100644 --- a/Sources/_CryptoExtras/Key Derivation/Scrypt/Scrypt.swift +++ b/Sources/_CryptoExtras/Key Derivation/Scrypt/Scrypt.swift @@ -12,11 +12,15 @@ // //===----------------------------------------------------------------------===// import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else #if canImport(Darwin) || swift(>=5.9.1) import Foundation #else @preconcurrency import Foundation #endif +#endif fileprivate typealias BackingScrypt = BoringSSLScrypt diff --git a/Sources/_CryptoExtras/OPRFs/OPRF.swift b/Sources/_CryptoExtras/OPRFs/OPRF.swift index e61dcaa10..db030e6b1 100644 --- a/Sources/_CryptoExtras/OPRFs/OPRF.swift +++ b/Sources/_CryptoExtras/OPRFs/OPRF.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Crypto /// (Verifiable Partly-)Oblivious Pseudorandom Functions diff --git a/Sources/_CryptoExtras/OPRFs/OPRFClient.swift b/Sources/_CryptoExtras/OPRFs/OPRFClient.swift index bf20458d6..e921a63c0 100644 --- a/Sources/_CryptoExtras/OPRFs/OPRFClient.swift +++ b/Sources/_CryptoExtras/OPRFs/OPRFClient.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif @available(macOS 10.15, iOS 13.2, tvOS 13.2, watchOS 6.1, *) extension OPRF { diff --git a/Sources/_CryptoExtras/OPRFs/OPRFServer.swift b/Sources/_CryptoExtras/OPRFs/OPRFServer.swift index cf858f7fe..38bdaa4d8 100644 --- a/Sources/_CryptoExtras/OPRFs/OPRFServer.swift +++ b/Sources/_CryptoExtras/OPRFs/OPRFServer.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Crypto @available(macOS 10.15, iOS 13.2, tvOS 13.2, watchOS 6.1, *) diff --git a/Sources/_CryptoExtras/OPRFs/VOPRF+API.swift b/Sources/_CryptoExtras/OPRFs/VOPRF+API.swift index f2285c777..11acfab1f 100644 --- a/Sources/_CryptoExtras/OPRFs/VOPRF+API.swift +++ b/Sources/_CryptoExtras/OPRFs/VOPRF+API.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif // MARK: - P384 + VPORF (P384-SHA384) extension P384 { diff --git a/Sources/_CryptoExtras/OPRFs/VOPRFClient.swift b/Sources/_CryptoExtras/OPRFs/VOPRFClient.swift index 8687e3bba..fc6232ff5 100644 --- a/Sources/_CryptoExtras/OPRFs/VOPRFClient.swift +++ b/Sources/_CryptoExtras/OPRFs/VOPRFClient.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif @available(macOS 10.15, iOS 13.2, tvOS 13.2, watchOS 6.1, *) extension OPRF { diff --git a/Sources/_CryptoExtras/OPRFs/VOPRFServer.swift b/Sources/_CryptoExtras/OPRFs/VOPRFServer.swift index c5de9040f..f04eeab9b 100644 --- a/Sources/_CryptoExtras/OPRFs/VOPRFServer.swift +++ b/Sources/_CryptoExtras/OPRFs/VOPRFServer.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Crypto @available(macOS 10.15, iOS 13.2, tvOS 13.2, watchOS 6.1, *) diff --git a/Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift b/Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift index cf866dce9..7b7ad47ab 100644 --- a/Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift +++ b/Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Crypto import CryptoBoringWrapper diff --git a/Sources/_CryptoExtras/RSA/RSA.swift b/Sources/_CryptoExtras/RSA/RSA.swift index a7d5652c0..957e74ecb 100644 --- a/Sources/_CryptoExtras/RSA/RSA.swift +++ b/Sources/_CryptoExtras/RSA/RSA.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Crypto import CryptoBoringWrapper import SwiftASN1 diff --git a/Sources/_CryptoExtras/RSA/RSA_boring.swift b/Sources/_CryptoExtras/RSA/RSA_boring.swift index 1baf9b400..942487ad3 100644 --- a/Sources/_CryptoExtras/RSA/RSA_boring.swift +++ b/Sources/_CryptoExtras/RSA/RSA_boring.swift @@ -17,7 +17,23 @@ @_implementationOnly import CCryptoBoringSSLShims import Crypto import CryptoBoringWrapper + +#if canImport(FoundationEssentials) +import FoundationEssentials +#if canImport(Glibc) +import Glibc +#elseif canImport(Musl) +import Musl +#elseif os(Windows) +import CRT +#elseif canImport(Android) +import Android +#else +import Darwin.C +#endif +#else import Foundation +#endif internal struct BoringSSLRSAPublicKey: Sendable { private var backing: Backing diff --git a/Sources/_CryptoExtras/RSA/RSA_security.swift b/Sources/_CryptoExtras/RSA/RSA_security.swift index 114012de6..d9c4ceb0e 100644 --- a/Sources/_CryptoExtras/RSA/RSA_security.swift +++ b/Sources/_CryptoExtras/RSA/RSA_security.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Crypto #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API diff --git a/Sources/_CryptoExtras/Util/BoringSSLHelpers.swift b/Sources/_CryptoExtras/Util/BoringSSLHelpers.swift index 49f929a8a..6b861e2eb 100644 --- a/Sources/_CryptoExtras/Util/BoringSSLHelpers.swift +++ b/Sources/_CryptoExtras/Util/BoringSSLHelpers.swift @@ -15,7 +15,11 @@ // NOTE: This file is unconditionally compiled because RSABSSA is implemented using BoringSSL on all platforms. @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Crypto internal enum BIOHelper { diff --git a/Sources/_CryptoExtras/Util/I2OSP.swift b/Sources/_CryptoExtras/Util/I2OSP.swift index d3d201533..8e73e5085 100644 --- a/Sources/_CryptoExtras/Util/I2OSP.swift +++ b/Sources/_CryptoExtras/Util/I2OSP.swift @@ -11,7 +11,22 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#if canImport(Glibc) +import Glibc +#elseif canImport(Musl) +import Musl +#elseif os(Windows) +import CRT +#elseif canImport(Android) +import Android +#else +import Darwin.C +#endif +#else import Foundation +#endif func I2OSP(value: Int, outputByteCount: Int) -> Data { precondition(outputByteCount > 0, "Cannot I2OSP with no output length.") diff --git a/Sources/_CryptoExtras/Util/PEMDocument.swift b/Sources/_CryptoExtras/Util/PEMDocument.swift index 49ac67b98..0ec501560 100644 --- a/Sources/_CryptoExtras/Util/PEMDocument.swift +++ b/Sources/_CryptoExtras/Util/PEMDocument.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Crypto enum ASN1 { diff --git a/Sources/_CryptoExtras/Util/PrettyBytes.swift b/Sources/_CryptoExtras/Util/PrettyBytes.swift index 7610e5c0d..5b34bf383 100644 --- a/Sources/_CryptoExtras/Util/PrettyBytes.swift +++ b/Sources/_CryptoExtras/Util/PrettyBytes.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif enum ByteHexEncodingErrors: Error { case incorrectHexValue diff --git a/Sources/_CryptoExtras/ZKPs/DLEQ.swift b/Sources/_CryptoExtras/ZKPs/DLEQ.swift index ff748f85f..0e4843f45 100644 --- a/Sources/_CryptoExtras/ZKPs/DLEQ.swift +++ b/Sources/_CryptoExtras/ZKPs/DLEQ.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Crypto /// A DLEQ Proof as described in https://cfrg.github.io/draft-irtf-cfrg-voprf/draft-irtf-cfrg-voprf.html#name-generateproof diff --git a/Sources/crypto-shasum/main.swift b/Sources/crypto-shasum/main.swift index b80d29d8c..dae3e6059 100644 --- a/Sources/crypto-shasum/main.swift +++ b/Sources/crypto-shasum/main.swift @@ -11,6 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + import Foundation import Crypto diff --git a/Tests/CryptoTests/Authenticated Encryption/AES-GCM-Runner.swift b/Tests/CryptoTests/Authenticated Encryption/AES-GCM-Runner.swift index 8e3e6c240..074e7e504 100644 --- a/Tests/CryptoTests/Authenticated Encryption/AES-GCM-Runner.swift +++ b/Tests/CryptoTests/Authenticated Encryption/AES-GCM-Runner.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import XCTest #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API diff --git a/Tests/CryptoTests/Authenticated Encryption/ChaChaPoly-Runner.swift b/Tests/CryptoTests/Authenticated Encryption/ChaChaPoly-Runner.swift index 4ecc17388..eca04a890 100644 --- a/Tests/CryptoTests/Authenticated Encryption/ChaChaPoly-Runner.swift +++ b/Tests/CryptoTests/Authenticated Encryption/ChaChaPoly-Runner.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import XCTest #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API diff --git a/Tests/CryptoTests/ECDH/BoringSSL/ASN1.swift b/Tests/CryptoTests/ECDH/BoringSSL/ASN1.swift index 2b2457b84..8a5e1f675 100644 --- a/Tests/CryptoTests/ECDH/BoringSSL/ASN1.swift +++ b/Tests/CryptoTests/ECDH/BoringSSL/ASN1.swift @@ -1,3 +1,5 @@ +import XCTest + //===----------------------------------------------------------------------===// // // This source file is part of the SwiftCrypto open source project @@ -11,8 +13,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation -import XCTest +#endif #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API // Skip tests that require @testable imports of CryptoKit. diff --git a/Tests/CryptoTests/ECDH/BoringSSL/secpECDH_Runner_boring.swift b/Tests/CryptoTests/ECDH/BoringSSL/secpECDH_Runner_boring.swift index ef6cd8da8..dc68ee962 100644 --- a/Tests/CryptoTests/ECDH/BoringSSL/secpECDH_Runner_boring.swift +++ b/Tests/CryptoTests/ECDH/BoringSSL/secpECDH_Runner_boring.swift @@ -1,3 +1,5 @@ +import XCTest + //===----------------------------------------------------------------------===// // // This source file is part of the SwiftCrypto open source project @@ -11,8 +13,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation -import XCTest +#endif #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API // Skip tests that require @testable imports of CryptoKit. diff --git a/Tests/CryptoTests/ECDH/X25519-Runner.swift b/Tests/CryptoTests/ECDH/X25519-Runner.swift index c03bd7b8b..41deb8702 100644 --- a/Tests/CryptoTests/ECDH/X25519-Runner.swift +++ b/Tests/CryptoTests/ECDH/X25519-Runner.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import XCTest #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API diff --git a/Tests/CryptoTests/ECDH/secpECDH_Runner.swift b/Tests/CryptoTests/ECDH/secpECDH_Runner.swift index aa89bbbde..e03efa1d5 100644 --- a/Tests/CryptoTests/ECDH/secpECDH_Runner.swift +++ b/Tests/CryptoTests/ECDH/secpECDH_Runner.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import XCTest #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API diff --git a/Tests/CryptoTests/HPKE/HPKETests-TestVectors.swift b/Tests/CryptoTests/HPKE/HPKETests-TestVectors.swift index 56e941416..52a750a13 100644 --- a/Tests/CryptoTests/HPKE/HPKETests-TestVectors.swift +++ b/Tests/CryptoTests/HPKE/HPKETests-TestVectors.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import XCTest #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API diff --git a/Tests/CryptoTests/HPKE/HPKETests.swift b/Tests/CryptoTests/HPKE/HPKETests.swift index cca6397ca..fd2b74ea3 100644 --- a/Tests/CryptoTests/HPKE/HPKETests.swift +++ b/Tests/CryptoTests/HPKE/HPKETests.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import XCTest #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API diff --git a/Tests/CryptoTests/Key Derivation/ECprivateKeysFromSeeds.swift b/Tests/CryptoTests/Key Derivation/ECprivateKeysFromSeeds.swift index 06ebe89e3..ef4d0cef2 100644 --- a/Tests/CryptoTests/Key Derivation/ECprivateKeysFromSeeds.swift +++ b/Tests/CryptoTests/Key Derivation/ECprivateKeysFromSeeds.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import XCTest #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API diff --git a/Tests/CryptoTests/Signatures/ECDSA/ECDSASignatureTests.swift b/Tests/CryptoTests/Signatures/ECDSA/ECDSASignatureTests.swift index c60b33170..23acf1c85 100644 --- a/Tests/CryptoTests/Signatures/ECDSA/ECDSASignatureTests.swift +++ b/Tests/CryptoTests/Signatures/ECDSA/ECDSASignatureTests.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import XCTest #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API diff --git a/Tests/CryptoTests/Utils/PrettyBytes.swift b/Tests/CryptoTests/Utils/PrettyBytes.swift index 7610e5c0d..5b34bf383 100644 --- a/Tests/CryptoTests/Utils/PrettyBytes.swift +++ b/Tests/CryptoTests/Utils/PrettyBytes.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif enum ByteHexEncodingErrors: Error { case incorrectHexValue diff --git a/Tests/CryptoTests/Utils/RFCVector.swift b/Tests/CryptoTests/Utils/RFCVector.swift index edf5540c2..ce09b655c 100644 --- a/Tests/CryptoTests/Utils/RFCVector.swift +++ b/Tests/CryptoTests/Utils/RFCVector.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// This is a not-very-performant decoder of the RFC formatted test vectors. /// diff --git a/Tests/CryptoTests/Utils/SplitData.swift b/Tests/CryptoTests/Utils/SplitData.swift index e0c17e48f..37283d85e 100644 --- a/Tests/CryptoTests/Utils/SplitData.swift +++ b/Tests/CryptoTests/Utils/SplitData.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Dispatch // A testing utility that creates one contiguous and one discontiguous representation of the given Data. diff --git a/Tests/_CryptoExtrasTests/AES Block Function Tests.swift b/Tests/_CryptoExtrasTests/AES Block Function Tests.swift index 776962d45..926cc04fc 100644 --- a/Tests/_CryptoExtrasTests/AES Block Function Tests.swift +++ b/Tests/_CryptoExtrasTests/AES Block Function Tests.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import XCTest import Crypto import _CryptoExtras diff --git a/Tests/_CryptoExtrasTests/AES-GCM-SIV-Runner.swift b/Tests/_CryptoExtrasTests/AES-GCM-SIV-Runner.swift index 227e73c3c..6cfa781f3 100644 --- a/Tests/_CryptoExtrasTests/AES-GCM-SIV-Runner.swift +++ b/Tests/_CryptoExtrasTests/AES-GCM-SIV-Runner.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import XCTest import Crypto import _CryptoExtras diff --git a/Tests/_CryptoExtrasTests/AES_CBCTests.swift b/Tests/_CryptoExtrasTests/AES_CBCTests.swift index b42131c69..b2ba34eaa 100644 --- a/Tests/_CryptoExtrasTests/AES_CBCTests.swift +++ b/Tests/_CryptoExtrasTests/AES_CBCTests.swift @@ -13,7 +13,11 @@ //===----------------------------------------------------------------------===// import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import _CryptoExtras import XCTest diff --git a/Tests/_CryptoExtrasTests/AES_CTRTests.swift b/Tests/_CryptoExtrasTests/AES_CTRTests.swift index e154b9b4a..2206967f9 100644 --- a/Tests/_CryptoExtrasTests/AES_CTRTests.swift +++ b/Tests/_CryptoExtrasTests/AES_CTRTests.swift @@ -13,7 +13,11 @@ //===----------------------------------------------------------------------===// import Crypto +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif @testable import _CryptoExtras import XCTest diff --git a/Tests/_CryptoExtrasTests/ChaCha20CTRTests.swift b/Tests/_CryptoExtrasTests/ChaCha20CTRTests.swift index b86bfcaac..fde4a79fc 100644 --- a/Tests/_CryptoExtrasTests/ChaCha20CTRTests.swift +++ b/Tests/_CryptoExtrasTests/ChaCha20CTRTests.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import XCTest import Crypto import _CryptoExtras diff --git a/Tests/_CryptoExtrasTests/TestRSAEncryption.swift b/Tests/_CryptoExtrasTests/TestRSAEncryption.swift index 63ad1e0f3..b6d45c3b6 100644 --- a/Tests/_CryptoExtrasTests/TestRSAEncryption.swift +++ b/Tests/_CryptoExtrasTests/TestRSAEncryption.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import XCTest import Crypto import _CryptoExtras diff --git a/Tests/_CryptoExtrasTests/TestRSASigning.swift b/Tests/_CryptoExtrasTests/TestRSASigning.swift index 07da7c127..7bbb2cf1a 100644 --- a/Tests/_CryptoExtrasTests/TestRSASigning.swift +++ b/Tests/_CryptoExtrasTests/TestRSASigning.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import XCTest import Crypto import CryptoBoringWrapper diff --git a/Tests/_CryptoExtrasTests/Utils/BytesUtil.swift b/Tests/_CryptoExtrasTests/Utils/BytesUtil.swift index 5cc8abc76..4e774b83a 100644 --- a/Tests/_CryptoExtrasTests/Utils/BytesUtil.swift +++ b/Tests/_CryptoExtrasTests/Utils/BytesUtil.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import XCTest enum ByteHexEncodingErrors: Error { diff --git a/Tests/_CryptoExtrasTests/Utils/RFCVector.swift b/Tests/_CryptoExtrasTests/Utils/RFCVector.swift index 2684a51c0..d4fd55ed5 100644 --- a/Tests/_CryptoExtrasTests/Utils/RFCVector.swift +++ b/Tests/_CryptoExtrasTests/Utils/RFCVector.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif /// This is a not-very-performant decoder of the RFC formatted test vectors. /// diff --git a/Tests/_CryptoExtrasTests/Utils/SplitData.swift b/Tests/_CryptoExtrasTests/Utils/SplitData.swift index 4b1d19307..040d9cd7a 100644 --- a/Tests/_CryptoExtrasTests/Utils/SplitData.swift +++ b/Tests/_CryptoExtrasTests/Utils/SplitData.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif import Dispatch // A testing utility that creates one contiguous and one discontiguous representation of the given Data.