Skip to content
Closed
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
37 changes: 4 additions & 33 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,13 @@

import PackageDescription

// Availability Macros

let availabilityTags: [_Availability] = [
_Availability("SwiftTLS"),
]
let versionNumbers = ["0.1.0"]

// Availability Macro Utilities
enum _OSAvailability: String {
// The OS versions in which `SwiftTLS 0.1.0` APIs first became available.
case alwaysAvailable = "macOS 26, iOS 26, tvOS 26, watchOS 26, visionOS 26"
// Use 10000 for future availability to avoid compiler magic around the 9999 version number but ensure it is greater than 9999"
case future = "macOS 10000, iOS 10000, tvOS 10000, watchOS 10000, visionOS 10000"
}

struct _Availability {
let name: String
let osAvailability: _OSAvailability

init(_ name: String, osAvailability: _OSAvailability = .alwaysAvailable) {
self.name = name
self.osAvailability = osAvailability
}
}
let availabilityMacros: [SwiftSetting] = versionNumbers.flatMap { version in
availabilityTags.map {
.enableExperimentalFeature("AvailabilityMacro=\($0.name) \(version):\($0.osAvailability.rawValue)")
}
}

var packageDependencies = [PackageDescription.Package.Dependency]()
var targetDependencies = [PackageDescription.Target.Dependency]()

var settings: [SwiftSetting]? = [
var settings: [SwiftSetting] = [
// Add build settings here
.enableExperimentalFeature("Lifetimes"),
.enableExperimentalFeature("AnyAppleOSAvailability"),
]

#if os(Linux)
Expand Down Expand Up @@ -89,12 +60,12 @@ let package = Package(
.target(
name: "SwiftTLS",
dependencies: targetDependencies,
swiftSettings: availabilityMacros + (settings ?? [])
swiftSettings: settings
),
.testTarget(
name: "SwiftTLSTests",
dependencies: ["SwiftTLS"],
swiftSettings: availabilityMacros + (settings ?? [])
swiftSettings: settings
),
]
)
12 changes: 6 additions & 6 deletions Sources/ArraySpanUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension Array where Element == UInt8 {
/// Creates an array by copying the bytes of the given raw span.
///
Expand All @@ -27,7 +27,7 @@ extension Array where Element == UInt8 {
}
}

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension InlineArray where Element == UInt8 {
/// Creates an inline array by copying the bytes of the given raw span.
///
Expand All @@ -42,7 +42,7 @@ extension InlineArray where Element == UInt8 {
}
}

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension Hasher {
mutating func combine(bytes: RawSpan) {
bytes.withUnsafeBytes { buffer in
Expand All @@ -51,7 +51,7 @@ extension Hasher {
}
}

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension InlineArray where Element: Equatable {
static func ==(lhs: Self, rhs: Self) -> Bool {
for i in lhs.indices {
Expand All @@ -64,7 +64,7 @@ extension InlineArray where Element: Equatable {
}
}

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension OutputRawSpan {
/// Appends the contents of the given raw span to this output span.
mutating func append(contentsOf bytes: RawSpan) {
Expand All @@ -74,7 +74,7 @@ extension OutputRawSpan {
}
}

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension RawSpan {
subscript(index: Int) -> UInt8 {
unsafeLoad(fromByteOffset: index, as: UInt8.self)
Expand Down
8 changes: 4 additions & 4 deletions Sources/ByteBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension Data {
///
/// This is not a truly hardened version of NIO's ByteBuffer. It lacks some flexibility, but it's
/// good enough for what we need.
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
struct ByteBuffer {
private var backingData: Data
private(set) var readerIndex: Data.Index
Expand Down Expand Up @@ -218,7 +218,7 @@ struct ByteBuffer {
}
}

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension ByteBuffer {
@discardableResult
mutating func writeVariableLengthVector<LengthField: FixedWidthInteger>(
Expand Down Expand Up @@ -283,7 +283,7 @@ extension ByteBuffer {
}
}

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension ByteBuffer: Hashable {
static func ==(lhs: ByteBuffer, rhs: ByteBuffer) -> Bool {
return lhs.readableBytesView == rhs.readableBytesView
Expand All @@ -294,7 +294,7 @@ extension ByteBuffer: Hashable {
}
}

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension ByteBuffer {
/// Execute the given `body` function with an input buffer that can access
/// the readable part of the byte buffer. Bytes consumed from the input
Expand Down
28 changes: 14 additions & 14 deletions Sources/Callbacks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation

// Result type for async computations applied to the handshaker.
@_spi(SwiftTLSProtocol)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public struct PendingAsyncResult: Sendable {
enum AsyncResult {
case certificate(CertificateResult)
Expand All @@ -43,7 +43,7 @@ public struct PendingAsyncResult: Sendable {

// List of opaque certificate data.
@_spi(SwiftTLSProtocol)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public struct CertificateList: Sendable, Hashable {
public var type: CertificateType
public var entries: [Data]
Expand All @@ -56,7 +56,7 @@ public struct CertificateList: Sendable, Hashable {

// Information offered by the client during the handshake.
@_spi(SwiftTLSProtocol)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public struct PeerOffer: Sendable, Hashable {
public var certificateTypes: [CertificateType]
public var signatureAlgorithms: [UInt16]
Expand All @@ -74,7 +74,7 @@ public struct PeerOffer: Sendable, Hashable {
// The result waiting indicates asynchronous work in the callback.
// The reason given for an unavailable certificate will be logged.
@_spi(SwiftTLSProtocol)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public enum CertificateResult: Sendable, Hashable {
case available(CertificateList)
case unavailable(reason: String)
Expand All @@ -83,7 +83,7 @@ public enum CertificateResult: Sendable, Hashable {

// Information passed into the callback.
@_spi(SwiftTLSProtocol)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public struct CertificateInfo: Sendable {
public var peerOffer: PeerOffer
public var deliverResult: (@Sendable (CertificateResult) -> Void)?
Expand All @@ -99,13 +99,13 @@ public struct CertificateInfo: Sendable {
// Note: This callback must either return a result directly (available, unavailable)
// or return waiting and call `deliverResult` with the pending result.
@_spi(SwiftTLSProtocol)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public typealias CertificateCallback = @Sendable (CertificateInfo) -> CertificateResult

// The result waiting indicates asynchronous work in the callback.
// The reason given for an unavailable signature will be logged.
@_spi(SwiftTLSProtocol)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public enum SignatureResult: Sendable, Hashable {
case available(signature: Data, algorithm: UInt16)
case unavailable(reason: String)
Expand All @@ -114,7 +114,7 @@ public enum SignatureResult: Sendable, Hashable {

// Information passed into the callback.
@_spi(SwiftTLSProtocol)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public struct SignatureInfo: Sendable {
public var transcriptHash: Data
public var peerOffer: PeerOffer
Expand All @@ -132,12 +132,12 @@ public struct SignatureInfo: Sendable {
// Note: This callback must either return a result directly (available, unavailable)
// or return waiting and call `deliverResult` with the pending result.
@_spi(SwiftTLSProtocol)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public typealias SignatureCallback = @Sendable (SignatureInfo) -> SignatureResult

// Bundles the callbacks for the server to customize the certificate messages.
@_spi(SwiftTLSProtocol)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public struct AsyncAuthenticator: Sendable {
public var supportedCertificateTypes: [CertificateType]
public var getCertificateChain: CertificateCallback
Expand All @@ -157,7 +157,7 @@ public struct AsyncAuthenticator: Sendable {
// Waiting indicates ongoing asynchronous work in the callback.
// The reason given for an invalid verification will be logged.
@_spi(SwiftTLSProtocol)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public enum VerificationResult: Sendable, Hashable {
case valid
case invalid(reason: String)
Expand All @@ -166,7 +166,7 @@ public enum VerificationResult: Sendable, Hashable {

// Information to verify the certificates and signature presented by the peer.
@_spi(SwiftTLSProtocol)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public struct VerificationInfo: Sendable {
public var certificates: CertificateList
public var signatureAlgorithm: UInt16
Expand All @@ -191,11 +191,11 @@ public struct VerificationInfo: Sendable {
// Note: This callback must either return a result directly (valid, invalid)
// or return waiting and call `deliverResult` with the pending result.
@_spi(SwiftTLSProtocol)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public typealias VerificationCallback = @Sendable (VerificationInfo) -> VerificationResult

@_spi(SwiftTLSProtocol)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public struct AsyncVerifier: Sendable {
public var availableCertificateTypes: [CertificateType]
public var verifyHandshake: VerificationCallback
Expand Down
10 changes: 5 additions & 5 deletions Sources/Cryptography/KeyScheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private let logger = Logger(label: "com.apple.security.swifttls.SessionKeyManage

// Wrapper around SessionKeyManager that only exposes functions a client should
// need to call to help avoid invalid transitions.
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
struct ClientSessionKeyManager<HF: HashFunction> {
private var sessionKeyManager: SessionKeyManager<HF>

Expand Down Expand Up @@ -135,7 +135,7 @@ struct ClientSessionKeyManager<HF: HashFunction> {

// Wrapper around SessionKeyManager that only exposes functions a server should
// need to call to help avoid invalid transitions.
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
struct ServerSessionKeyManager<HF: HashFunction> {
private var sessionKeyManager: SessionKeyManager<HF>

Expand Down Expand Up @@ -220,7 +220,7 @@ struct ServerSessionKeyManager<HF: HashFunction> {
/// The TLS 1.3 key schedule builds out a ratchet of keys and secrets for various purposes.
/// This object encapsulates the current state in the key schedule and provides access to the
/// various secrets for the rest of the code to use.
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
fileprivate struct SessionKeyManager<HF: HashFunction> {

/// The running state of the key manager.
Expand Down Expand Up @@ -523,7 +523,7 @@ fileprivate struct SessionKeyManager<HF: HashFunction> {
}
}

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension SessionKeyManager {
fileprivate enum State {
/// The dialogue has not yet begun; no keying material is available.
Expand Down Expand Up @@ -561,7 +561,7 @@ extension SessionKeyManager {
}
}

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension SessionKeyManager.State {
fileprivate struct EarlySecret {
/// The current state of the transcript hash.
Expand Down
14 changes: 7 additions & 7 deletions Sources/Cryptography/PrivateKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import CryptoKit
/// A generic wrapper over the supported private-key types.
///
/// Loosely based on the implementation in Swift Certificates.
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
struct PrivateKey {
var backing: BackingPrivateKey

Expand Down Expand Up @@ -94,10 +94,10 @@ struct PrivateKey {
}
}

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension PrivateKey: Hashable {}

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension PrivateKey: CustomStringConvertible {
var description: String {
switch self.backing {
Expand All @@ -115,13 +115,13 @@ extension PrivateKey: CustomStringConvertible {


@_spi(SwiftTLSOptions)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public typealias SwiftTLSSignatureScheme = UInt16

/// A callback that accepts the bytes to sign and the negotiated TLS signature scheme,
/// and returns the signature, or `nil` when signing fails.
@_spi(SwiftTLSOptions)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public typealias SwiftTLSRefKeySignCallback = (Data, SwiftTLSSignatureScheme) -> Data?

/// The underlying key types supported by `SwiftTLSOpaqueReferenceKey`.
Expand All @@ -132,7 +132,7 @@ enum SwiftTLSOpaqueReferenceKeyType: Sendable {
/// A generic private-key type that lets a caller produce signatures over data using any key
/// the caller can access.
@_spi(SwiftTLSOptions)
@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
public struct SwiftTLSOpaqueReferenceKey {
let publicKey: PublicKey
let sign: SwiftTLSRefKeySignCallback
Expand Down Expand Up @@ -167,7 +167,7 @@ public struct SwiftTLSOpaqueReferenceKey {
}
}

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension PrivateKey {
enum BackingPrivateKey: Hashable {
case p256(P256.Signing.PrivateKey)
Expand Down
6 changes: 3 additions & 3 deletions Sources/Cryptography/PublicKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ extension PublicKey {
}
}

@available(SwiftTLS 0.1.0, *)
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
extension PublicKey: Hashable {}

@available(SwiftTLS 0.1.0, *)
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
extension PublicKey: Sendable {}

@available(SwiftTLS 0.1.0, *)
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
extension PublicKey: CustomStringConvertible {
var description: String {
switch self.backing {
Expand Down
2 changes: 1 addition & 1 deletion Sources/DataUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import Foundation
#endif

@available(SwiftTLS 0.1.0, *)
@available(anyAppleOS 26, *)
extension Data {
/// Creates a `Data` instance by copying the raw bytes from the given span.
init(copying bytes: RawSpan) {
Expand Down
Loading
Loading