Skip to content

Commit

Permalink
Add Sendables annotation to Crypto Extras (#211)
Browse files Browse the repository at this point in the history
Motivation

Add Sendable annotations to Crypto Extras to reflect current sandability
so that downstream packages can implement sendable conformance.

Modifications

* Add Sendable conformance to appropriate public symbols.
* RSA public and private keys are notable omissions, this is because
  they are backed by SecKey from security framework and we have no
  guarantees about their sendability

Result

* Accurate Sendable annotations
  • Loading branch information
rnro authored Dec 12, 2023
1 parent b793a1e commit ed66091
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
8 changes: 6 additions & 2 deletions Sources/_CryptoExtras/AES/AES_GCM_SIV.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import Crypto
@_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims
@_implementationOnly import CryptoBoringWrapper
#if canImport(Darwin) || swift(>=5.9.1)
import Foundation
#else
@preconcurrency import Foundation
#endif

/// Types associated with the AES GCM SIV algorithm
extension AES.GCM {
Expand Down Expand Up @@ -81,7 +85,7 @@ extension AES.GCM {
}

extension AES.GCM._SIV {
public struct Nonce: ContiguousBytes, Sequence {
public struct Nonce: Sendable, ContiguousBytes, Sequence {
let bytes: Data

/// Generates a fresh random Nonce. Unless required by a specification to provide a specific Nonce, this is the recommended initializer.
Expand Down Expand Up @@ -115,7 +119,7 @@ extension AES.GCM._SIV {
}

extension AES.GCM._SIV {
public struct SealedBox {
public struct SealedBox: Sendable {
/// The combined representation ( nonce || ciphertext || tag)
public let combined: Data
/// The authentication tag
Expand Down
8 changes: 6 additions & 2 deletions Sources/_CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
@_implementationOnly import CCryptoBoringSSLShims
import Crypto
@_implementationOnly import CryptoBoringWrapper
#if canImport(Darwin) || swift(>=5.9.1)
import Foundation
#else
@preconcurrency import Foundation
#endif

typealias ChaCha20CTRImpl = OpenSSLChaCha20CTRImpl

Expand Down Expand Up @@ -51,7 +55,7 @@ extension Insecure {
}

extension Insecure.ChaCha20CTR {
public struct Nonce: ContiguousBytes, Sequence {
public struct Nonce: Sendable, ContiguousBytes, Sequence {
let bytes: Data

/// Generates a fresh random Nonce. Unless required by a specification to provide a specific Nonce, this is the recommended initializer.
Expand Down Expand Up @@ -83,7 +87,7 @@ extension Insecure.ChaCha20CTR {
}
}

public struct Counter: ContiguousBytes {
public struct Counter: Sendable, ContiguousBytes {
let counter: UInt32

/// Generates a fresh Counter set to 0. Unless required by a specification to provide a specific Counter, this is the recommended initializer.
Expand Down
8 changes: 4 additions & 4 deletions Sources/_CryptoExtras/RSA/RSA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ extension _RSA.Signing {
}

extension _RSA.Signing {
public struct RSASignature: ContiguousBytes {
public struct RSASignature: Sendable, ContiguousBytes {
public var rawRepresentation: Data

public init<D: DataProtocol>(rawRepresentation: D) {
Expand All @@ -177,7 +177,7 @@ extension _RSA.Signing {
}

extension _RSA.Signing {
public struct Padding {
public struct Padding: Sendable {
internal enum Backing {
case pkcs1v1_5
case pss
Expand Down Expand Up @@ -305,7 +305,7 @@ extension _RSA.Signing.PublicKey {
}

extension _RSA.Signing {
public struct KeySize {
public struct KeySize: Sendable {
public let bitCount: Int

/// RSA key size of 2048 bits
Expand Down Expand Up @@ -399,7 +399,7 @@ extension _RSA.Encryption {
}

extension _RSA.Encryption {
public struct Padding {
public struct Padding: Sendable {
internal enum Backing {
case pkcs1_oaep(Digest)
}
Expand Down

0 comments on commit ed66091

Please sign in to comment.