diff --git a/example/boring_ssl/.gitignore b/example/boring_ssl/.gitignore new file mode 100755 index 0000000..4e5e9cc --- /dev/null +++ b/example/boring_ssl/.gitignore @@ -0,0 +1,6 @@ +dist/ +target/ +.DS_Store +.idea/ + +Cargo.lock diff --git a/example/boring_ssl/Cargo.toml b/example/boring_ssl/Cargo.toml new file mode 100755 index 0000000..54c828a --- /dev/null +++ b/example/boring_ssl/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "boring_ssl" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["cdylib"] + +[dependencies] +napi-ohos = { version = "*" } +napi-derive-ohos = { version = "*" } +boring = { git="https://github.com/ohos-rs/boring" } +hex = "*" + +[build-dependencies] +napi-build-ohos = { version = "*" } + +[profile.release] +lto = true diff --git a/example/boring_ssl/README.md b/example/boring_ssl/README.md new file mode 100644 index 0000000..9a56416 --- /dev/null +++ b/example/boring_ssl/README.md @@ -0,0 +1,5 @@ +## Run + +```shell +source ./prepare.sh && ohrs build +``` \ No newline at end of file diff --git a/example/boring_ssl/build.rs b/example/boring_ssl/build.rs new file mode 100755 index 0000000..b13d1b4 --- /dev/null +++ b/example/boring_ssl/build.rs @@ -0,0 +1,3 @@ +fn main() { + napi_build_ohos::setup(); +} diff --git a/example/boring_ssl/prepare.sh b/example/boring_ssl/prepare.sh new file mode 100644 index 0000000..e3908be --- /dev/null +++ b/example/boring_ssl/prepare.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +export BORING_BSSL_SYSROOT=${OHOS_NDK_HOME}/native/sysroot \ +export CMAKE_TOOLCHAIN_FILE=${OHOS_NDK_HOME}/native/build/cmake/ohos.toolchain.cmake \ No newline at end of file diff --git a/example/boring_ssl/src/lib.rs b/example/boring_ssl/src/lib.rs new file mode 100755 index 0000000..8c355b7 --- /dev/null +++ b/example/boring_ssl/src/lib.rs @@ -0,0 +1,13 @@ +use boring::sha; +use napi_derive_ohos::napi; + +#[napi] +pub fn h() -> String { + let mut hasher = sha::Sha256::new(); + + hasher.update(b"Hello, "); + hasher.update(b"world"); + + let hash = hasher.finish(); + hex::encode(hash) +}