Skip to content

Adopt FoundationEssentials instead of Foundation where available #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/Crypto/AEADs/AES/GCM/AES-GCM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
#else
@_implementationOnly import CCryptoBoringSSL
import CryptoBoringWrapper
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

enum OpenSSLAESGCMImpl {
@inlinable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/AEADs/ChachaPoly/ChaChaPoly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/AEADs/Cipher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/AEADs/Nonces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/AEADs/Nonces.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/ASN1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Any.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/Basic ASN1 Types/ASN1BitString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Boolean.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Identifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Integer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Null.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/Basic ASN1 Types/ASN1OctetString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/Basic ASN1 Types/GeneralizedTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/Basic ASN1 Types/ObjectIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/ECDSASignature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/PEMDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/PKCS8PrivateKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/SEC1PrivateKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/ASN1/SubjectPublicKeyInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/Digests/Digest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/Digests/HashFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/HPKE/Ciphersuite/HPKE-AEAD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/HPKE/Ciphersuite/HPKE-Ciphersuite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/HPKE/Ciphersuite/HPKE-KDF.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/HPKE/Ciphersuite/HPKE-KexKeyDerivation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/HPKE/Ciphersuite/HPKE-LabeledExtract.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions Sources/Crypto/HPKE/Ciphersuite/HPKE-Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
4 changes: 4 additions & 0 deletions Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/DHKEM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading