Skip to content

Commit

Permalink
feat: add boring_ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
richerfu committed Apr 1, 2024
1 parent c4f146c commit ba7ff0d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions example/boring_ssl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist/
target/
.DS_Store
.idea/

Cargo.lock
21 changes: 21 additions & 0 deletions example/boring_ssl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions example/boring_ssl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Run

```shell
source ./prepare.sh && ohrs build
```
3 changes: 3 additions & 0 deletions example/boring_ssl/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
napi_build_ohos::setup();
}
4 changes: 4 additions & 0 deletions example/boring_ssl/prepare.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions example/boring_ssl/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit ba7ff0d

Please sign in to comment.