[5.x] Adopt CheckImplementationOnly and CI with -warnings-as-errors (#454)

## Motivation

We've long since used `@_implementationOnly import` (IOI) for our
vendored C modules (BoringSSL and libXKCP) in an attempt to not leak our
dependency into downstream builds. This is important because leaking
might cause symbol collisions (build failures) or, worse, layout
mismatches (latent runtime failures).

IOI was intended to be used with library evolution, which this project
does not support, and use of IOI without library evolution has been
soft-deprecated. Users are encouraged to move to `internal import` (II),
which is usually the right choice for Swift packages. But II does not
provide the same guarantees as IOI and, for this project, we really need
the protections given by IOI so we will continue to use it, even with
library evolution disabled.

One of the reasons for the soft-deprecation was the implementation of
IOI used an incomplete checker, that won't catch all interface leaks
without library evolution. However, Swift has also introduced a new
feature, `CheckImplementationOnly` (CIO), which enables the stricter
interface checking that we need, which we should adopt.

Aside: This feature is visible in 6.3 but is incomplete and the Swift
team only recommend adopting in 6.4+. Indeed, this PR is a cut-back
version of #452, which which included a lengthy patch and discussion,
boxing many types that were a result of false positives from the
`CheckImplementationOnly` feature on 6.3.

## Modifications

This patch enables `CheckImplementationOnly`, when building with 6.4, or
newer.

Additionally, as we're approaching a new major, it's a good opportunity
to get warnings-clean and lock in warnings-as-errors, so this PR does
that, suppressing only `ImplementationOnlyDeprecated`, which we cannot
eliminate. So we now build in CI using:

-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc
ImplementationOnlyDeprecated

However, Swift 6.4 introduces `SourceWarningControl`, which we can use
to actually _silence_ these warnings, using `@diagnose(_:as:)`, which we
do conditionally:

    #if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored)
@_implementationOnly import ...
    #else
    @_implementationOnly import ...
    #endif

When we raise the minimum supported Swift compiler version to one that
supports `SourceWarningControl`, we can remove the `#if hasFeature`
guards.

We've had to drop to `--build-system native` (vs swift-build) for Swift
6.4 CI because SwiftPM is not stripping the warning-related compiler
flags when building dependencies.

## Result

- Stricter checks for not leakingC dependencies from BoringSSL and
libXKCP -- project builds cleanly with `CheckImplementationOnly`.
- All other compiler warnings have been addressed and project builds
with `-warnings-as-errors -Wwarning ImplementationOnlyDeprecated` in CI.
- On Swift 6.4+, `ImplementationOnlyDeprecated` warnings are completely
silenced and the project is completely warnings-free.
This commit is contained in:
Si Beaumont authored and GitHub committed 2026-08-07 11:39:12 +01:00
1 parent ce8db4769d
commit 15b0fb5b45
49 files changed
+251 -34

No files matched your search

+9 -14
View File
@@ -10,7 +10,7 @@ on:
jobs: jobs:
soundness: soundness:
name: Soundness name: Soundness
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@0.0.7 uses: swiftlang/github-workflows/.github/workflows/soundness.yml@0.0.13
with: with:
license_header_check_project_name: "SwiftCrypto" license_header_check_project_name: "SwiftCrypto"
docs_check_enabled: false docs_check_enabled: false
@@ -19,28 +19,23 @@ jobs:
name: Unit tests name: Unit tests
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
with: with:
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error" linux_6_2_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error" linux_6_3_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
linux_6_2_arguments_override: "--explicit-target-dependency-import-check error" linux_nightly_next_arguments_override: "--build-system native -Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
linux_6_3_arguments_override: "--explicit-target-dependency-import-check error" linux_nightly_main_arguments_override: "--build-system native --explicit-target-dependency-import-check error"
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
windows_6_1_enabled: true
windows_6_2_enabled: true windows_6_2_enabled: true
windows_6_3_enabled: true windows_6_3_enabled: true
windows_nightly_next_enabled: true windows_nightly_next_enabled: true
windows_nightly_main_enabled: true windows_nightly_main_enabled: true
windows_6_1_arguments_override: "--explicit-target-dependency-import-check error" windows_6_2_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
windows_6_2_arguments_override: "--explicit-target-dependency-import-check error" windows_6_3_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
windows_6_3_arguments_override: "--explicit-target-dependency-import-check error" windows_nightly_next_arguments_override: "--build-system native -Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
windows_nightly_next_arguments_override: "--explicit-target-dependency-import-check error" windows_nightly_main_arguments_override: "--build-system native --explicit-target-dependency-import-check error"
windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
release-builds: release-builds:
name: Release builds name: Release builds
uses: apple/swift-nio/.github/workflows/release_builds.yml@main uses: apple/swift-nio/.github/workflows/release_builds.yml@main
with: with:
windows_6_1_enabled: true
windows_6_2_enabled: true windows_6_2_enabled: true
windows_6_3_enabled: true windows_6_3_enabled: true
windows_nightly_next_enabled: true windows_nightly_next_enabled: true
+13 -1
View File
@@ -38,11 +38,17 @@ let nonDarwinPlatforms: [Platform] = [
.custom("freebsd"), .custom("freebsd"),
] ]
let swiftSettings: [SwiftSetting] = [ var swiftSettings: [SwiftSetting] = [
.define("CRYPTO_IN_SWIFTPM"), .define("CRYPTO_IN_SWIFTPM"),
.enableExperimentalFeature("Lifetimes"), .enableExperimentalFeature("Lifetimes"),
.enableExperimentalFeature("SourceWarningControl"),
] ]
// Only enable CheckImplementationOnly on 6.4 -- 6.3 has the feature, but produces many false positives.
#if compiler(>=6.4)
swiftSettings.append(.enableExperimentalFeature("CheckImplementationOnly"))
#endif
// This doesn't work when cross-compiling: the privacy manifest will be included in the Bundle and // This doesn't work when cross-compiling: the privacy manifest will be included in the Bundle and
// Foundation will be linked. This is, however, strictly better than unconditionally adding the // Foundation will be linked. This is, however, strictly better than unconditionally adding the
// resource. // resource.
@@ -98,6 +104,10 @@ let package = Package(
.when(platforms: [Platform.wasi]) .when(platforms: [Platform.wasi])
), ),
.define("OPENSSL_NO_ASM", .when(platforms: [Platform.wasi])), .define("OPENSSL_NO_ASM", .when(platforms: [Platform.wasi])),
// BoringSSL is vendored verbatim; we don't fix its warnings. Xcode enables
// -Wshorten-64-to-32 by default (SwiftPM does not), which produces dozens
// of warnings. Silence that group here.
.disableWarning("shorten-64-to-32"),
] ]
), ),
.target( .target(
@@ -113,6 +123,7 @@ let package = Package(
.headerSearchPath("low/KeccakP-1600"), .headerSearchPath("low/KeccakP-1600"),
.headerSearchPath("low/common"), .headerSearchPath("low/common"),
.headerSearchPath("common"), .headerSearchPath("common"),
.disableWarning("macro-redefined"),
] ]
), ),
.target( .target(
@@ -141,6 +152,7 @@ let package = Package(
.target(name: "CXKCPShims", condition: .when(platforms: nonDarwinPlatforms)), .target(name: "CXKCPShims", condition: .when(platforms: nonDarwinPlatforms)),
], ],
exclude: privacyManifestExclude + [ exclude: privacyManifestExclude + [
"vendored-sources.txt",
"CMakeLists.txt", "CMakeLists.txt",
"Signatures/BoringSSL/MLDSA_boring.swift.gyb", "Signatures/BoringSSL/MLDSA_boring.swift.gyb",
"KEM/BoringSSL/MLKEM_boring.swift.gyb", "KEM/BoringSSL/MLKEM_boring.swift.gyb",
@@ -14,7 +14,11 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
import CryptoBoringWrapper import CryptoBoringWrapper
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
@@ -14,8 +14,13 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
#endif
import CryptoBoringWrapper import CryptoBoringWrapper
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
@@ -14,7 +14,11 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
protocol HashFunctionImplementationDetails: HashFunction where Digest: DigestPrivate {} protocol HashFunctionImplementationDetails: HashFunction where Digest: DigestPrivate {}
@@ -14,8 +14,13 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CXKCP
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CXKCPShims
#else
@_implementationOnly import CXKCP @_implementationOnly import CXKCP
@_implementationOnly import CXKCPShims @_implementationOnly import CXKCPShims
#endif
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
protocol XKCPBackedHashFunction: HashFunctionImplementationDetails { protocol XKCPBackedHashFunction: HashFunctionImplementationDetails {
@@ -19,7 +19,11 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -19,7 +19,11 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -15,7 +15,11 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -15,7 +15,11 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -14,7 +14,11 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
extension P256.KeyAgreement.PrivateKey { extension P256.KeyAgreement.PrivateKey {
+2 -2
View File
@@ -17,9 +17,9 @@
#else #else
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
public import FoundationEssentials import FoundationEssentials
#else #else
public import Foundation import Foundation
#endif #endif
internal struct ANSIKDFx963<H: HashFunction>: Sendable { internal struct ANSIKDFx963<H: HashFunction>: Sendable {
@@ -14,7 +14,11 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -14,8 +14,13 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -14,8 +14,13 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
#endif
import CryptoBoringWrapper import CryptoBoringWrapper
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
@@ -14,8 +14,13 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -14,8 +14,13 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
#endif
import CryptoBoringWrapper import CryptoBoringWrapper
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
@@ -14,7 +14,11 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
import CryptoBoringWrapper import CryptoBoringWrapper
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
@@ -14,8 +14,13 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -15,7 +15,11 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -26,7 +30,11 @@ import Foundation
// any edits of this file WILL be overwritten and thus discarded // any edits of this file WILL be overwritten and thus discarded
// see section `gyb` in `README` for details. // see section `gyb` in `README` for details.
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -15,7 +15,11 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -26,7 +30,11 @@ import Foundation
// any edits of this file WILL be overwritten and thus discarded // any edits of this file WILL be overwritten and thus discarded
// see section `gyb` in `README` for details. // see section `gyb` in `README` for details.
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -15,7 +15,11 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -14,7 +14,11 @@
#if canImport(CryptoKit) #if canImport(CryptoKit)
@_exported import CryptoKit @_exported import CryptoKit
#else #else
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
extension CryptoKitError { extension CryptoKitError {
@@ -12,7 +12,11 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#if !canImport(Darwin) #if !canImport(Darwin)
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
typealias errno_t = CInt typealias errno_t = CInt
@@ -12,8 +12,13 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
@@ -12,7 +12,11 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
public enum CryptoBoringWrapperError: Error { public enum CryptoBoringWrapperError: Error {
@@ -11,7 +11,11 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
/// A wrapper around BoringSSL's EC_GROUP object that handles reference counting and /// A wrapper around BoringSSL's EC_GROUP object that handles reference counting and
/// liveness. /// liveness.
@@ -11,8 +11,13 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import protocol FoundationEssentials.ContiguousBytes import protocol FoundationEssentials.ContiguousBytes
@@ -12,8 +12,13 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
@@ -12,7 +12,11 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
@@ -13,8 +13,13 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
import Crypto import Crypto
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
#endif
import CryptoBoringWrapper import CryptoBoringWrapper
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
@@ -13,8 +13,13 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
import Crypto import Crypto
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
#endif
import CryptoBoringWrapper import CryptoBoringWrapper
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
@@ -12,9 +12,14 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@_implementationOnly import CCryptoBoringSSL
import Crypto import Crypto
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -12,9 +12,14 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@_implementationOnly import CCryptoBoringSSL
import Crypto import Crypto
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -14,11 +14,17 @@
// This is a copy ChaChaPoly_boring just with a different set aes algos // This is a copy ChaChaPoly_boring just with a different set aes algos
@_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims
import Crypto import Crypto
import CryptoBoringWrapper import CryptoBoringWrapper
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -92,7 +98,7 @@ enum OpenSSLAESGCMSIVImpl {
) )
} }
return try AES.GCM._SIV.SealedBox(combined: combined, nonceByteCount: nonce.bytes.count) return AES.GCM._SIV.SealedBox(combined: combined, nonceByteCount: nonce.bytes.count)
} }
@inlinable @inlinable
+7 -1
View File
@@ -11,9 +11,15 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@_implementationOnly import CCryptoBoringSSL
import Crypto import Crypto
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -12,11 +12,17 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims
import Crypto import Crypto
import CryptoBoringWrapper import CryptoBoringWrapper
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -12,8 +12,13 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
#endif
import Crypto import Crypto
import CryptoBoringWrapper import CryptoBoringWrapper
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
@@ -12,9 +12,14 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@_implementationOnly import CCryptoBoringSSL
import Crypto import Crypto
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL
#endif
#if canImport(Darwin) #if canImport(Darwin)
import Darwin import Darwin
#endif #endif
@@ -12,9 +12,10 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@_implementationOnly import CCryptoBoringSSL
import Crypto import Crypto
@_implementationOnly import CCryptoBoringSSL
struct BoringSSLSHA512256HashFunction { struct BoringSSLSHA512256HashFunction {
static var digestSize: Int { static var digestSize: Int {
Int(SHA256_DIGEST_LENGTH) Int(SHA256_DIGEST_LENGTH)
@@ -20,8 +20,13 @@ import Foundation
#endif #endif
#if !canImport(CommonCrypto) #if !canImport(CommonCrypto)
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
#endif
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
internal struct BoringSSLPBKDF2 { internal struct BoringSSLPBKDF2 {
@@ -12,9 +12,15 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
import Crypto
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
import Crypto #endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
#if os(Windows) #if os(Windows)
+9 -3
View File
@@ -12,12 +12,18 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// NOTE: This file is unconditionally compiled because RSABSSA is implemented using BoringSSL on all platforms.
@_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims
import Crypto import Crypto
import CryptoBoringWrapper import CryptoBoringWrapper
// NOTE: This file is unconditionally compiled because RSABSSA is implemented using BoringSSL on all platforms.
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
#if os(Windows) #if os(Windows)
import ucrt import ucrt
@@ -12,7 +12,11 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#if !canImport(Darwin) #if !canImport(Darwin)
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
typealias errno_t = CInt typealias errno_t = CInt
@@ -13,8 +13,13 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// NOTE: This file is unconditionally compiled because RSABSSA is implemented using BoringSSL on all platforms. // NOTE: This file is unconditionally compiled because RSABSSA is implemented using BoringSSL on all platforms.
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims @_implementationOnly import CCryptoBoringSSLShims
#endif
#if canImport(FoundationEssentials) #if canImport(FoundationEssentials)
import FoundationEssentials import FoundationEssentials
#else #else
@@ -12,9 +12,14 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@_implementationOnly import CCryptoBoringSSL
import Crypto import Crypto
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL
#endif
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
extension CryptoKitError { extension CryptoKitError {
/// A helper function that packs the value of `ERR_get_error` into the internal error field. /// A helper function that packs the value of `ERR_get_error` into the internal error field.
@@ -13,7 +13,11 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// NOTE: This file is unconditionally compiled because RSABSSA is implemented using BoringSSL on all platforms. // NOTE: This file is unconditionally compiled because RSABSSA is implemented using BoringSSL on all platforms.
#if hasFeature(SourceWarningControl)
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
#else
@_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSL
#endif
import Crypto import Crypto
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
+1 -1
View File
@@ -45,7 +45,7 @@ final class AES_CFBTests: XCTestCase {
func testVector(_ vector: TestVector) throws { func testVector(_ vector: TestVector) throws {
let (contiguousPlaintextData, discontiguousPlaintextData) = vector.plaintext.asDataProtocols() let (contiguousPlaintextData, discontiguousPlaintextData) = vector.plaintext.asDataProtocols()
for plaintextData in [contiguousPlaintextData as DataProtocol, discontiguousPlaintextData as DataProtocol] { for plaintextData in [contiguousPlaintextData as (any DataProtocol), discontiguousPlaintextData as (any DataProtocol)] {
let key = SymmetricKey(data: Data(vector.key)) let key = SymmetricKey(data: Data(vector.key))
let iv = try AES._CFB.IV(ivBytes: vector.iv) let iv = try AES._CFB.IV(ivBytes: vector.iv)
let ciphertext = try AES._CFB.encrypt(plaintextData, using: key, iv: iv) let ciphertext = try AES._CFB.encrypt(plaintextData, using: key, iv: iv)
@@ -151,7 +151,7 @@ class AESGCMTests: XCTestCase {
let ciphertext = Array("This pretty clearly isn't ciphertext, but sure why not".utf8) let ciphertext = Array("This pretty clearly isn't ciphertext, but sure why not".utf8)
let (contiguousCiphertext, discontiguousCiphertext) = ciphertext.asDataProtocols() let (contiguousCiphertext, discontiguousCiphertext) = ciphertext.asDataProtocols()
let contiguousSB = try orFail { try AES.GCM.SealedBox(combined: contiguousCiphertext) } let contiguousSB = try orFail { AES.GCM.SealedBox(combined: contiguousCiphertext) }
let discontiguousSB = try orFail { try AES.GCM.SealedBox(combined: discontiguousCiphertext) } let discontiguousSB = try orFail { try AES.GCM.SealedBox(combined: discontiguousCiphertext) }
XCTAssertEqual(contiguousSB.combined, discontiguousSB.combined) XCTAssertEqual(contiguousSB.combined, discontiguousSB.combined)
XCTAssertEqual(Array(contiguousSB.nonce), Array(discontiguousSB.nonce)) XCTAssertEqual(Array(contiguousSB.nonce), Array(discontiguousSB.nonce))