Skip to content

Commit

Permalink
Refactor and adopt package access to remove symlinked files (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjbeaumont authored Oct 8, 2024
1 parent 735a29c commit 21f7878
Show file tree
Hide file tree
Showing 26 changed files with 119 additions and 96 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)

set(SWIFT_CRYPTO_COMPILE_OPTIONS
-package-name com.apple.swift-crypto
)

option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)

if(BUILD_SHARED_LIBS)
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ let package = Package(
"Signatures/ECDSA.swift.gyb",
],
resources: privacyManifestResource,
swiftSettings: swiftSettings + [.define("MODULE_IS_CRYPTO")]
swiftSettings: swiftSettings
),
.target(
name: "_CryptoExtras",
Expand Down Expand Up @@ -173,6 +173,7 @@ let package = Package(
swiftSettings: swiftSettings
),
.testTarget(name: "_CryptoExtrasTests", dependencies: ["_CryptoExtras"]),
.testTarget(name: "CryptoBoringWrapperTests", dependencies: ["CryptoBoringWrapper"]),
],
cxxLanguageStandard: .cxx11
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@_exported import CryptoKit
#else
@_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CryptoBoringWrapper
import CryptoBoringWrapper
import Foundation

enum OpenSSLAESGCMImpl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#else
@_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims
@_implementationOnly import CryptoBoringWrapper
import CryptoBoringWrapper
import Foundation

extension BoringSSLAEAD {
Expand Down
3 changes: 1 addition & 2 deletions Sources/Crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ add_library(Crypto
"Util/BoringSSL/CryptoKitErrors_boring.swift"
"Util/BoringSSL/RNG_boring.swift"
"Util/BoringSSL/SafeCompare_boring.swift"
"Util/BoringSSL/Shared/ArbitraryPrecisionInteger_boring.swift"
"Util/BoringSSL/Shared/FiniteFieldArithmeticContext_boring.swift"
"Util/BoringSSL/Zeroization_boring.swift"
"Util/PrettyBytes.swift"
"Util/SafeCompare.swift"
Expand All @@ -115,6 +113,7 @@ target_link_libraries(Crypto PUBLIC
CCryptoBoringSSL
CCryptoBoringSSLShims
CryptoBoringWrapper)
target_compile_options(Crypto PRIVATE ${SWIFT_CRYPTO_COMPILE_OPTIONS})
set_target_properties(Crypto PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@_exported import CryptoKit
#else
@_implementationOnly import CCryptoBoringSSL
import CryptoBoringWrapper

/// A wrapper around BoringSSL's EC_POINT with some lifetime management.
@usableFromInline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@_exported import CryptoKit
#else
@_implementationOnly import CCryptoBoringSSL
import CryptoBoringWrapper

/// A wrapper around BoringSSL's EC_GROUP object that handles reference counting and
/// liveness.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#else
@_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims
import CryptoBoringWrapper
import Foundation

@usableFromInline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#else
@_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims
import CryptoBoringWrapper
import Foundation

/// A wrapper around BoringSSL's ECDSA_SIG with some lifetime management.
Expand Down
6 changes: 5 additions & 1 deletion Sources/CryptoBoringWrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

add_library(CryptoBoringWrapper STATIC
"AEAD/BoringSSLAEAD.swift"
"CryptoKitErrors_boring.swift")
"CryptoKitErrors_boring.swift"
"Util/ArbitraryPrecisionInteger_boring.swift"
"Util/FiniteFieldArithmeticContext_boring.swift")

target_include_directories(CryptoBoringWrapper PUBLIC
$<TARGET_PROPERTY:CCryptoBoringSSL,INCLUDE_DIRECTORIES>
Expand All @@ -25,6 +27,8 @@ target_link_libraries(CryptoBoringWrapper PUBLIC
CCryptoBoringSSL
CCryptoBoringSSLShims)

target_compile_options(CryptoBoringWrapper PRIVATE ${SWIFT_CRYPTO_COMPILE_OPTIONS})

set_target_properties(CryptoBoringWrapper PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

Expand Down
16 changes: 15 additions & 1 deletion Sources/CryptoBoringWrapper/CryptoKitErrors_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,27 @@
@_implementationOnly import CCryptoBoringSSL

public enum CryptoBoringWrapperError: Error {
/// The key size is incorrect.
case incorrectKeySize
/// The parameter size is incorrect.
case incorrectParameterSize
/// The authentication tag or signature is incorrect.
case authenticationFailure
/// The underlying corecrypto library is unable to complete the requested
/// action.
case underlyingCoreCryptoError(error: Int32)
/// The framework can't wrap the specified key.
case wrapFailure
/// The framework can't unwrap the specified key.
case unwrapFailure
/// The parameter is invalid.
case invalidParameter
}

extension CryptoBoringWrapperError {
/// A helper function that packs the value of `ERR_get_error` into the internal error field.
@usableFromInline
static func internalBoringSSLError() -> CryptoBoringWrapperError {
package static func internalBoringSSLError() -> CryptoBoringWrapperError {
return .underlyingCoreCryptoError(error: Int32(bitPattern: CCryptoBoringSSL_ERR_get_error()))
}
}
Loading

0 comments on commit 21f7878

Please sign in to comment.