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
203 changes: 82 additions & 121 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ This command uses the [@neon-rs/cli](https://www.npmjs.com/package/@neon-rs/cli)

It is possible to filter according to modules (see the [docs](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html)).

```pwsh
$env:RUST_LOG="crypto_layer_node=trace,crypto_layer=warn"
```

- Activate full backtrace:

```bash
Expand Down
2 changes: 2 additions & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"fgrep",
"fromjs",
"Granual",
"HMAC",
"keyhandle",
"keypairhandle",
"msvc",
"nmshd",
"pswd",
"robinraju",
"rustup",
"softprops",
Expand Down
48 changes: 36 additions & 12 deletions crates/crypto-layer-node/src/fromjs/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use neon::prelude::*;

use super::error::{bad_parameter, js_result, rw_lock_poisoned, ConversionError};
use super::{from_wrapped_enum, from_wrapped_simple_enum, wrapped_array_to_hash_set};
use crate::{JsKeyHandle, JsKeyPairHandle};
use crate::{BoxedKeyHandle, BoxedKeyPairHandle, JsKeyHandle, JsKeyPairHandle};

/// Converts `ProviderConfig` from `crypto-layer-ts-types` to `ProviderConfig` from `crypto-layer`.
#[tracing::instrument(level = "trace", skip_all)]
Expand Down Expand Up @@ -63,7 +63,21 @@ pub fn from_wrapped_provider_impl_config<'a>(
})
}

/// Converts `AdditionalConfig` from `crypto-layer-ts-types` to `AdditionalConfig` from `crypto-layer`.
fn boxed_key_handle_from_node_key_handle(
cx: &mut FunctionContext,
obj: Handle<JsObject>,
) -> Result<BoxedKeyHandle, ConversionError> {
Ok((**bad_parameter(obj.get::<JsKeyHandle, _, _>(cx, "keyHandle"))?).clone())
}

fn boxed_key_pair_handle_from_node_key_pair_handle(
cx: &mut FunctionContext,
obj: Handle<JsObject>,
) -> Result<BoxedKeyPairHandle, ConversionError> {
Ok((**bad_parameter(obj.get::<JsKeyPairHandle, _, _>(cx, "keyPairHandle"))?).clone())
}

/// Converts `AdditionalConfig` from `rs-crypto-types` to `AdditionalConfig` from `crypto-layer`.
///
/// # Errors
/// * `KVStoreConfig` is currently not supported and will crash the program with `unimplemented!()`.
Expand All @@ -81,41 +95,51 @@ pub fn from_wrapped_additional_config(
}

let obj = obj_option.unwrap();
let obj = bad_parameter(obj.downcast::<JsObject, _>(cx))?;

let result = match additional_config {
AdditionalConfigDiscriminants::FileStoreConfig => {
let obj = bad_parameter(obj.downcast::<JsObject, _>(cx))?;
let db_path_js = bad_parameter(obj.get::<JsString, _, _>(cx, "db_dir"))?;

AdditionalConfig::FileStoreConfig {
db_dir: db_path_js.value(cx),
}
}
AdditionalConfigDiscriminants::KVStoreConfig => {
// Implementing this is problamatic:
// Implementing this is problematic:
// There is only one node thread running.
// Meaning that to call methods given to rust, rust queues theses method calls for node to run, when the thread
// is available.
// Rust waits for the call to finish. It never does, as the call can only execute, when the thread is free.
unimplemented!()
}
AdditionalConfigDiscriminants::StorageConfigHMAC => {
let key_handle_js = bad_parameter(obj.downcast::<JsKeyHandle, _>(cx))?;
let boxed_key_handle = boxed_key_handle_from_node_key_handle(cx, obj)?;

let key_handle = rw_lock_poisoned(key_handle_js.read())?;
let key_handle = rw_lock_poisoned(boxed_key_handle.read())?;

AdditionalConfig::StorageConfigHMAC(key_handle.clone())
}
AdditionalConfigDiscriminants::StorageConfigDSA => {
let key_pair_handle_js = bad_parameter(obj.downcast::<JsKeyPairHandle, _>(cx))?;
let key_pair_handle_js = boxed_key_pair_handle_from_node_key_pair_handle(cx, obj)?;

let key_pair_handle = rw_lock_poisoned(key_pair_handle_js.read())?;

AdditionalConfig::StorageConfigDSA(key_pair_handle.clone())
}
AdditionalConfigDiscriminants::StorageConfigPass => {
let pass_js = bad_parameter(obj.downcast::<JsString, _>(cx))?;
AdditionalConfig::StorageConfigPass(pass_js.value(cx))
AdditionalConfigDiscriminants::StorageConfigSymmetricEncryption => {
let key_handle_js = boxed_key_handle_from_node_key_handle(cx, obj)?;

let key_handle = rw_lock_poisoned(key_handle_js.read())?;

AdditionalConfig::StorageConfigSymmetricEncryption(key_handle.clone())
}
AdditionalConfigDiscriminants::StorageConfigAsymmetricEncryption => {
let key_pair_handle_js = boxed_key_pair_handle_from_node_key_pair_handle(cx, obj)?;

let key_pair_handle = rw_lock_poisoned(key_pair_handle_js.read())?;

AdditionalConfig::StorageConfigAsymmetricEncryption(key_pair_handle.clone())
}
};

Expand Down Expand Up @@ -147,7 +171,7 @@ pub(crate) fn from_wrapped_key_pair_spec(
cx: &mut FunctionContext,
wrapped: Handle<JsObject>,
) -> Result<KeyPairSpec, ConversionError> {
let asymc_spec_js = js_result(wrapped.get(cx, "asym_spec"))?;
let asym_spec_js = js_result(wrapped.get(cx, "asym_spec"))?;
let cipher_js = js_result(wrapped.get::<JsValue, _, _>(cx, "cipher"))?;
let signing_hash_js = js_result(wrapped.get(cx, "signing_hash"))?;
let ephemeral_js = js_result(wrapped.get::<JsBoolean, _, _>(cx, "ephemeral"))?;
Expand All @@ -160,7 +184,7 @@ pub(crate) fn from_wrapped_key_pair_spec(
};

Ok(KeyPairSpec {
asym_spec: from_wrapped_simple_enum(cx, asymc_spec_js)?,
asym_spec: from_wrapped_simple_enum(cx, asym_spec_js)?,
cipher,
signing_hash: from_wrapped_simple_enum(cx, signing_hash_js)?,
ephemeral: ephemeral_js.value(cx),
Expand Down
6 changes: 4 additions & 2 deletions crates/crypto-layer-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ use fromjs::*;
use tojs::config::wrap_provider_config;
use tojs::*;

type JsKeyHandle = JsBox<Arc<RwLock<Finalized<KeyHandle>>>>;
type JsKeyPairHandle = JsBox<Arc<RwLock<Finalized<KeyPairHandle>>>>;
type BoxedKeyHandle = Arc<RwLock<Finalized<KeyHandle>>>;
type JsKeyHandle = JsBox<BoxedKeyHandle>;
type BoxedKeyPairHandle = Arc<RwLock<Finalized<KeyPairHandle>>>;
type JsKeyPairHandle = JsBox<BoxedKeyPairHandle>;
type JsProvider = JsBox<Arc<RwLock<Finalized<Provider>>>>;
type JsDhExchange = JsBox<Arc<RwLock<Finalized<DHExchange>>>>;

Expand Down
79 changes: 50 additions & 29 deletions package-lock.json

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

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nmshd/rs-crypto-node",
"version": "0.13.0",
"version": "0.14.0",
"description": "crypto layer ts interface for nodejs",
"homepage": "https://enmeshed.eu",
"repository": "github:nmshd/crypto-layer-node",
Expand Down Expand Up @@ -56,18 +56,19 @@
"jest": "^29.7.0",
"jiti": "^2.4.2",
"prettier": "3.5.3",
"tmp-promise": "^3.0.3",
"ts-jest": "^29.2.5",
"typescript": "^5.3.3",
"typescript-eslint": "^8.25.0"
},
"dependencies": {
"@neon-rs/load": "^0.1.73",
"@nmshd/rs-crypto-types": "^0.10.0"
"@nmshd/rs-crypto-types": "^0.11.0"
},
"optionalDependencies": {
"@nmshd/rs-crypto-node-darwin-arm64": "0.13.0",
"@nmshd/rs-crypto-node-darwin-x64": "0.13.0",
"@nmshd/rs-crypto-node-linux-x64-gnu": "0.13.0",
"@nmshd/rs-crypto-node-win32-x64-msvc": "0.13.0"
"@nmshd/rs-crypto-node-darwin-arm64": "0.14.0",
"@nmshd/rs-crypto-node-darwin-x64": "0.14.0",
"@nmshd/rs-crypto-node-linux-x64-gnu": "0.14.0",
"@nmshd/rs-crypto-node-win32-x64-msvc": "0.14.0"
}
}
2 changes: 1 addition & 1 deletion platforms/darwin-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nmshd/rs-crypto-node-darwin-arm64",
"description": "Prebuilt binary package for `rs-crypto-node` on `darwin-arm64`.",
"repository": "github:nmshd/crypto-layer-node",
"version": "0.13.0",
"version": "0.14.0",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion platforms/darwin-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nmshd/rs-crypto-node-darwin-x64",
"description": "Prebuilt binary package for `rs-layer-ts` on `darwin-x64`.",
"repository": "github:nmshd/crypto-layer-node",
"version": "0.13.0",
"version": "0.14.0",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion platforms/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nmshd/rs-crypto-node-linux-arm64-gnu",
"description": "Prebuilt binary package for `rs-layer-ts` on `linux-arm64-gnu`.",
"repository": "github:nmshd/crypto-layer-node",
"version": "0.13.0",
"version": "0.14.0",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion platforms/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nmshd/rs-crypto-node-linux-x64-gnu",
"description": "Prebuilt binary package for `rs-layer-ts` on `linux-x64-gnu`.",
"repository": "github:nmshd/crypto-layer-node",
"version": "0.13.0",
"version": "0.14.0",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion platforms/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nmshd/rs-crypto-node-win32-x64-msvc",
"description": "Prebuilt binary package for `rs-layer-ts` on `win32-x64-msvc`.",
"repository": "github:nmshd/crypto-layer-node",
"version": "0.13.0",
"version": "0.14.0",
"os": [
"win32"
],
Expand Down
Loading
Loading