Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cip 1244/use latest client builder #12

Merged
merged 3 commits into from
Feb 26, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ lib
cargo.log
cross.log
mise.local.toml
cipherstash.secret.toml
67 changes: 61 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ $ npm run build

This command uses the [@neon-rs/cli](https://www.npmjs.com/package/@neon-rs/cli) utility to assemble the binary Node addon from the output of `cargo`.

## Local setup

You can use the `stash` CLI tool to set up your local environment.

You will be prompted to sign in or create an account and follow steps to create a keyset and client key.

```sh
brew install cipherstash/tap/stash
stash setup
```

## Exploring

After building `protect-ffi`, you can explore its exports at the Node console.
Expand Down
2 changes: 1 addition & 1 deletion crates/protect-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crate-type = ["cdylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cipherstash-client = "0.16.0"
cipherstash-client = "=0.17.0-pre"
neon = "1"
once_cell = "1.20.2"
thiserror = "2.0.8"
Expand Down
22 changes: 11 additions & 11 deletions crates/protect-ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cipherstash_client::{
config::{
console_config::ConsoleConfig, cts_config::CtsConfig, errors::ConfigError,
zero_kms_config::ZeroKMSConfig,
zero_kms_config::ZeroKMSConfig, EnvSource, CIPHERSTASH_SECRET_TOML, CIPHERSTASH_TOML,
},
credentials::{ServiceCredentials, ServiceToken},
encryption::{
Expand Down Expand Up @@ -75,9 +75,11 @@ async fn new_client_inner() -> Result<Client, Error> {
let console_config = ConsoleConfig::builder().with_env().build()?;
let cts_config = CtsConfig::builder().with_env().build()?;
let zerokms_config = ZeroKMSConfig::builder()
.add_source(EnvSource::default())
.add_source(CIPHERSTASH_SECRET_TOML)
.add_source(CIPHERSTASH_TOML)
.console_config(&console_config)
.cts_config(&cts_config)
.with_env()
.build_with_client_key()?;

let zerokms = Arc::new(zerokms_config.create_client());
Expand All @@ -91,7 +93,7 @@ async fn new_client_inner() -> Result<Client, Error> {
}

fn encrypt(mut cx: FunctionContext) -> JsResult<JsPromise> {
let client = (&**cx.argument::<JsBox<Client>>(0)?).clone();
let client = (**cx.argument::<JsBox<Client>>(0)?).clone();
let plaintext = cx.argument::<JsString>(1)?.value(&mut cx);
let column_name = cx.argument::<JsString>(2)?.value(&mut cx);
let lock_context = encryption_context_from_js_value(cx.argument_opt(3), &mut cx)?;
Expand Down Expand Up @@ -156,7 +158,7 @@ async fn encrypt_inner(
}

fn encrypt_bulk(mut cx: FunctionContext) -> JsResult<JsPromise> {
let client = (&**cx.argument::<JsBox<Client>>(0)?).clone();
let client = (**cx.argument::<JsBox<Client>>(0)?).clone();
let plaintext_targets = plaintext_targets_from_js_array(cx.argument::<JsArray>(1)?, &mut cx)?;
let service_token = service_token_from_js_value(cx.argument_opt(2), &mut cx)?;

Expand Down Expand Up @@ -209,7 +211,7 @@ async fn encrypt_bulk_inner(
}

fn decrypt(mut cx: FunctionContext) -> JsResult<JsPromise> {
let client = (&**cx.argument::<JsBox<Client>>(0)?).clone();
let client = (**cx.argument::<JsBox<Client>>(0)?).clone();
let ciphertext = cx.argument::<JsString>(1)?.value(&mut cx);
let lock_context = encryption_context_from_js_value(cx.argument_opt(2), &mut cx)?;
let service_token = service_token_from_js_value(cx.argument_opt(3), &mut cx)?;
Expand Down Expand Up @@ -249,7 +251,7 @@ async fn decrypt_inner(
}

fn decrypt_bulk(mut cx: FunctionContext) -> JsResult<JsPromise> {
let client = (&**cx.argument::<JsBox<Client>>(0)?).clone();
let client = (**cx.argument::<JsBox<Client>>(0)?).clone();
let ciphertexts = ciphertexts_from_js_array(cx.argument::<JsArray>(1)?, &mut cx)?;
let service_token = service_token_from_js_value(cx.argument_opt(2), &mut cx)?;

Expand Down Expand Up @@ -425,11 +427,9 @@ fn plaintext_str_from_bytes(bytes: Vec<u8>) -> Result<String, Error> {

match plaintext {
Plaintext::Utf8Str(Some(ref inner)) => Ok(inner.clone()),
_ => {
return Err(Error::Unimplemented(
"data types other than `Utf8Str`".to_string(),
))
}
_ => Err(Error::Unimplemented(
"data types other than `Utf8Str`".to_string(),
)),
}
}

Expand Down
Loading