From 1e30a615e595a4a521141fc2cf2477365aa2c7cc Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sat, 4 Jan 2025 21:42:28 -0500 Subject: [PATCH] Add Android support --- .github/workflows/android.yml | 21 +++++++++++++++++++++ Sources/CryptoSwift/BlockMode/CCM.swift | 2 ++ Sources/CryptoSwift/Cryptors.swift | 2 ++ Sources/CryptoSwift/HKDF.swift | 2 ++ Sources/CryptoSwift/Int+Extension.swift | 2 ++ Sources/CryptoSwift/PKCS/PBKDF2.swift | 2 ++ Sources/CryptoSwift/SHA3.swift | 2 ++ Sources/CryptoSwift/SecureBytes.swift | 6 ++++++ Sources/CryptoSwift/UInt32+Extension.swift | 2 ++ Sources/CryptoSwift/UInt8+Extension.swift | 2 ++ 10 files changed, 43 insertions(+) create mode 100644 .github/workflows/android.yml diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml new file mode 100644 index 00000000..e0fece0d --- /dev/null +++ b/.github/workflows/android.yml @@ -0,0 +1,21 @@ +name: Android + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Run tests + uses: skiptools/swift-android-action@v2 diff --git a/Sources/CryptoSwift/BlockMode/CCM.swift b/Sources/CryptoSwift/BlockMode/CCM.swift index 31eefdb2..3bff1a62 100644 --- a/Sources/CryptoSwift/BlockMode/CCM.swift +++ b/Sources/CryptoSwift/BlockMode/CCM.swift @@ -19,6 +19,8 @@ #if canImport(Darwin) import Darwin +#elseif canImport(Android) +import Android #elseif canImport(Glibc) import Glibc #elseif canImport(Musl) diff --git a/Sources/CryptoSwift/Cryptors.swift b/Sources/CryptoSwift/Cryptors.swift index 35713760..727531b7 100644 --- a/Sources/CryptoSwift/Cryptors.swift +++ b/Sources/CryptoSwift/Cryptors.swift @@ -15,6 +15,8 @@ #if canImport(Darwin) import Darwin +#elseif canImport(Android) +import Android #elseif canImport(Glibc) import Glibc #elseif canImport(Musl) diff --git a/Sources/CryptoSwift/HKDF.swift b/Sources/CryptoSwift/HKDF.swift index 5df795ee..000f5c17 100644 --- a/Sources/CryptoSwift/HKDF.swift +++ b/Sources/CryptoSwift/HKDF.swift @@ -18,6 +18,8 @@ #if canImport(Darwin) import Darwin +#elseif canImport(Android) +import Android #elseif canImport(Glibc) import Glibc #elseif canImport(Musl) diff --git a/Sources/CryptoSwift/Int+Extension.swift b/Sources/CryptoSwift/Int+Extension.swift index 2f603188..5f02d8a8 100644 --- a/Sources/CryptoSwift/Int+Extension.swift +++ b/Sources/CryptoSwift/Int+Extension.swift @@ -16,6 +16,8 @@ #if canImport(Darwin) import Darwin +#elseif canImport(Android) +import Android #elseif canImport(Glibc) import Glibc #elseif canImport(Musl) diff --git a/Sources/CryptoSwift/PKCS/PBKDF2.swift b/Sources/CryptoSwift/PKCS/PBKDF2.swift index 94a3cb5b..e1666675 100644 --- a/Sources/CryptoSwift/PKCS/PBKDF2.swift +++ b/Sources/CryptoSwift/PKCS/PBKDF2.swift @@ -18,6 +18,8 @@ #if canImport(Darwin) import Darwin +#elseif canImport(Android) +import Android #elseif canImport(Glibc) import Glibc #elseif canImport(Musl) diff --git a/Sources/CryptoSwift/SHA3.swift b/Sources/CryptoSwift/SHA3.swift index 3952d921..d78b4d98 100644 --- a/Sources/CryptoSwift/SHA3.swift +++ b/Sources/CryptoSwift/SHA3.swift @@ -19,6 +19,8 @@ #if canImport(Darwin) import Darwin +#elseif canImport(Android) +import Android #elseif canImport(Glibc) import Glibc #elseif canImport(Musl) diff --git a/Sources/CryptoSwift/SecureBytes.swift b/Sources/CryptoSwift/SecureBytes.swift index 7e12466c..9e23ee07 100644 --- a/Sources/CryptoSwift/SecureBytes.swift +++ b/Sources/CryptoSwift/SecureBytes.swift @@ -15,6 +15,8 @@ #if canImport(Darwin) import Darwin +#elseif canImport(Android) +import Android #elseif canImport(Glibc) import Glibc #elseif canImport(Musl) @@ -39,6 +41,8 @@ final class SecureBytes { VirtualLock(UnsafeMutableRawPointer(mutating: pointer.baseAddress), SIZE_T(pointer.count)) #elseif os(WASI) // not supported on WASI + #elseif os(Android) + mlock(pointer.baseAddress!, pointer.count) #else mlock(pointer.baseAddress, pointer.count) #endif @@ -51,6 +55,8 @@ final class SecureBytes { VirtualUnlock(UnsafeMutableRawPointer(mutating: pointer.baseAddress), SIZE_T(pointer.count)) #elseif os(WASI) // not supported on WASI + #elseif os(Android) + munlock(pointer.baseAddress!, pointer.count) #else munlock(pointer.baseAddress, pointer.count) #endif diff --git a/Sources/CryptoSwift/UInt32+Extension.swift b/Sources/CryptoSwift/UInt32+Extension.swift index 7cd047d9..65a49a2a 100644 --- a/Sources/CryptoSwift/UInt32+Extension.swift +++ b/Sources/CryptoSwift/UInt32+Extension.swift @@ -15,6 +15,8 @@ #if canImport(Darwin) import Darwin +#elseif canImport(Android) +import Android #elseif canImport(Glibc) import Glibc #elseif canImport(Musl) diff --git a/Sources/CryptoSwift/UInt8+Extension.swift b/Sources/CryptoSwift/UInt8+Extension.swift index 80596f16..01123dbe 100644 --- a/Sources/CryptoSwift/UInt8+Extension.swift +++ b/Sources/CryptoSwift/UInt8+Extension.swift @@ -15,6 +15,8 @@ #if canImport(Darwin) import Darwin +#elseif canImport(Android) +import Android #elseif canImport(Glibc) import Glibc #elseif canImport(Musl)