Skip to content
Merged
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
76 changes: 63 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,83 @@ jobs:
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: cargo build --verbose
- run: cargo test --verbose

release:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
strategy:
matrix:
include:
- os: ubuntu-latest
suffix: linux-x86_64
target: x86_64-unknown-linux-gnu
ext: so
- os: macos-14
suffix: macos-arm64
target: aarch64-apple-darwin
ext: dylib
- os: macos-14
suffix: ios-arm64
target: aarch64-apple-ios
ext: a
- os: ubuntu-latest
suffix: android-arm64
target: aarch64-linux-android
ext: so
runs-on: ${{ matrix.os }}
needs: build_and_test
steps:
- uses: actions/checkout@v4
- run: rustup update stable && rustup default stable
- run: rustup target add ${{ matrix.target }}
- name: Configure NDK tool-chain
if: matrix.target == 'aarch64-linux-android'
shell: bash
run: |
NDK="$(ls -d "$ANDROID_HOME"/ndk/* | sort -V | tail -n1)"
echo "Using NDK at $NDK"
echo "NDK=$NDK" >> "$GITHUB_ENV"
echo "LLVM_BIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin" >> "$GITHUB_ENV"
echo "$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin" >> "$GITHUB_PATH"
echo "CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang" >> "$GITHUB_ENV"
- name: Extract version from tag
id: extract
run: echo "version=${GITHUB_REF##*/}" >> "$GITHUB_OUTPUT"
- run: cargo build --release
- run: cargo build --release --target ${{ matrix.target }}
- name: Archive and rename binary
shell: bash
run: |
VERSION=${{ steps.extract.outputs.version }}
PLATFORM=linux-x86_64
mkdir -p target/dist
cp target/release/libscal3.so target/dist/libscal3-$VERSION-$PLATFORM.so
- run: cargo publish --locked
VERSION=${{ steps.version.outputs.VERSION }}
SUFFIX=${{ matrix.suffix }}
EXT=${{ matrix.ext }}
mkdir -p dist
SRC="target/${{ matrix.target }}/release/libscal3.${EXT}"
cp "$SRC" "dist/libscal3-${VERSION}-${SUFFIX}.${EXT}"
- uses: actions/upload-artifact@v4
with:
name: bin-${{ matrix.suffix }}
path: dist/*
publish:
if: startsWith(github.ref, 'refs/tags/v')
needs: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with: { name: bin-linux-x86_64, path: dist/ }
- uses: actions/download-artifact@v4
with: { name: bin-macos-arm64, path: dist/ }
- uses: actions/download-artifact@v4
with: { name: bin-ios-arm64, path: dist/ }
- uses: actions/download-artifact@v4
with: { name: bin-android-arm64, path: dist/ }
- name: Publish crate
run: cargo publish --locked
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Create GitHub Release with uploaded binary
- name: Create GitHub Release with all binaries
run: |
VERSION=${{ steps.extract.outputs.version }}
PLATFORM=linux-x86_64
gh release create "${{ steps.extract.outputs.version }}" target/dist/libscal3-$VERSION-$PLATFORM.so \
--title "Release ${{ steps.extract.outputs.version }}" \
VERSION=${GITHUB_REF##*/}
gh release create "$VERSION" dist/* \
--title "Release $VERSION" \
--verify-tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "scal3"
description = "Verify that systems operate under your sole control (prototype, patent pending)"
license = "CC-BY-NC-4.0"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
repository = "https://github.com/cleverbase/scal3"
authors = ["Sander Dijkhuis <sander.dijkhuis@cleverbase.com>"]
Expand Down
10 changes: 8 additions & 2 deletions demo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@ import org.bouncycastle.jce.interfaces.{ECPrivateKey, ECPublicKey}
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.jce.spec.ECPublicKeySpec

import java.nio.file.Paths
import java.security.{KeyFactory, KeyPairGenerator, MessageDigest, SecureRandom, Security, Signature}
import javax.crypto.{KeyAgreement, KeyGenerator, Mac, SecretKey}
import scala.util.Try

val libraryPath = "target/release/libscal3.so"
val libraryPath =
val os = System.getProperty("os.name").toLowerCase
val extension = if os.contains("mac") then ".dylib" else ".so"
s"target/release/libscal3$extension"

object authentication:
private object impl:
private trait AuthenticationLibrary extends Library:
def scal3_process(ip: Array[Byte], il: Int, op: PointerByReference, ol: IntByReference): Unit
def scal3_free(ptr: Pointer, len: Int): Unit

private val library: AuthenticationLibrary = Native.load(libraryPath, classOf[AuthenticationLibrary])
private val library: AuthenticationLibrary =
val path = Paths.get(libraryPath).toFile.getAbsolutePath
Native.load(path, classOf[AuthenticationLibrary])

given AdtEncodingStrategy = AdtEncodingStrategy.flat(typeMemberName = "type")

Expand Down