From 1af71e7154cd4a038b59c7615e385562fdad2bd3 Mon Sep 17 00:00:00 2001 From: Brandon Vandegrift <798832-bmv437@users.noreply.gitlab.com> Date: Sun, 24 Sep 2023 14:47:22 -0400 Subject: [PATCH] (wasm) re-export helpful length constants --- veilid-wasm/src/veilid_crypto_js.rs | 101 +++++++++++++++++++++ veilid-wasm/tests/src/veilidCrypto.test.ts | 50 ++++++++++ 2 files changed, 151 insertions(+) diff --git a/veilid-wasm/src/veilid_crypto_js.rs b/veilid-wasm/src/veilid_crypto_js.rs index 21012046..eb8c6949 100644 --- a/veilid-wasm/src/veilid_crypto_js.rs +++ b/veilid-wasm/src/veilid_crypto_js.rs @@ -478,4 +478,105 @@ impl VeilidCrypto { crypto_system.crypt_in_place_no_auth(&mut body, &nonce, &shared_secret); APIResult::Ok(body) } + + // -------------------------------- + // Constants + // (written as getters since wasm_bindgen doesn't support export of const) + // -------------------------------- + + /// Length of a crypto key in bytes + #[wasm_bindgen(getter)] + pub fn CRYPTO_KEY_LENGTH() -> usize { + veilid_core::CRYPTO_KEY_LENGTH + } + + /// Length of a crypto key in bytes after encoding to base64url + #[wasm_bindgen(getter)] + pub fn CRYPTO_KEY_LENGTH_ENCODED() -> usize { + veilid_core::CRYPTO_KEY_LENGTH_ENCODED + } + + /// Length of a hash digest in bytes + #[wasm_bindgen(getter)] + pub fn HASH_DIGEST_LENGTH() -> usize { + veilid_core::HASH_DIGEST_LENGTH + } + + /// Length of a hash digest in bytes after encoding to base64url + #[wasm_bindgen(getter)] + pub fn HASH_DIGEST_LENGTH_ENCODED() -> usize { + veilid_core::HASH_DIGEST_LENGTH_ENCODED + } + + /// Length of a nonce in bytes + #[wasm_bindgen(getter)] + pub fn NONCE_LENGTH() -> usize { + veilid_core::NONCE_LENGTH + } + + /// Length of a nonce in bytes after encoding to base64url + #[wasm_bindgen(getter)] + pub fn NONCE_LENGTH_ENCODED() -> usize { + veilid_core::NONCE_LENGTH_ENCODED + } + + /// Length of a crypto key in bytes + #[wasm_bindgen(getter)] + pub fn PUBLIC_KEY_LENGTH() -> usize { + veilid_core::PUBLIC_KEY_LENGTH + } + + /// Length of a crypto key in bytes after encoding to base64url + #[wasm_bindgen(getter)] + pub fn PUBLIC_KEY_LENGTH_ENCODED() -> usize { + veilid_core::PUBLIC_KEY_LENGTH_ENCODED + } + + /// Length of a route id in bytes + #[wasm_bindgen(getter)] + pub fn ROUTE_ID_LENGTH() -> usize { + veilid_core::ROUTE_ID_LENGTH + } + + /// Length of a route id in bytes afer encoding to base64url + #[wasm_bindgen(getter)] + pub fn ROUTE_ID_LENGTH_ENCODED() -> usize { + veilid_core::ROUTE_ID_LENGTH_ENCODED + } + + /// Length of a secret key in bytes + #[wasm_bindgen(getter)] + pub fn SECRET_KEY_LENGTH() -> usize { + veilid_core::SECRET_KEY_LENGTH + } + + /// Length of a secret key in bytes after encoding to base64url + #[wasm_bindgen(getter)] + pub fn SECRET_KEY_LENGTH_ENCODED() -> usize { + veilid_core::SECRET_KEY_LENGTH_ENCODED + } + + /// Length of a shared secret in bytes + #[wasm_bindgen(getter)] + pub fn SHARED_SECRET_LENGTH() -> usize { + veilid_core::SHARED_SECRET_LENGTH + } + + /// Length of a shared secret in bytes after encoding to base64url + #[wasm_bindgen(getter)] + pub fn SHARED_SECRET_LENGTH_ENCODED() -> usize { + veilid_core::SHARED_SECRET_LENGTH_ENCODED + } + + /// Length of a signature in bytes + #[wasm_bindgen(getter)] + pub fn SIGNATURE_LENGTH() -> usize { + veilid_core::SIGNATURE_LENGTH + } + + /// Length of a signature in bytes after encoding to base64url + #[wasm_bindgen(getter)] + pub fn SIGNATURE_LENGTH_ENCODED() -> usize { + veilid_core::SIGNATURE_LENGTH_ENCODED + } } diff --git a/veilid-wasm/tests/src/veilidCrypto.test.ts b/veilid-wasm/tests/src/veilidCrypto.test.ts index afbdfac2..da2a0190 100644 --- a/veilid-wasm/tests/src/veilidCrypto.test.ts +++ b/veilid-wasm/tests/src/veilidCrypto.test.ts @@ -142,4 +142,54 @@ describe('veilidCrypto', () => { }).not.toThrow(); }); + describe('contants', () => { + it('CRYPTO_KEY_LENGTH', () => { + expect(typeof veilidCrypto.CRYPTO_KEY_LENGTH).toBe('number'); + }); + it('CRYPTO_KEY_LENGTH_ENCODED', () => { + expect(typeof veilidCrypto.CRYPTO_KEY_LENGTH_ENCODED).toBe('number'); + }); + it('HASH_DIGEST_LENGTH', () => { + expect(typeof veilidCrypto.HASH_DIGEST_LENGTH).toBe('number'); + }); + it('HASH_DIGEST_LENGTH_ENCODED', () => { + expect(typeof veilidCrypto.HASH_DIGEST_LENGTH_ENCODED).toBe('number'); + }); + it('NONCE_LENGTH', () => { + expect(typeof veilidCrypto.NONCE_LENGTH).toBe('number'); + }); + it('NONCE_LENGTH_ENCODED', () => { + expect(typeof veilidCrypto.NONCE_LENGTH_ENCODED).toBe('number'); + }); + it('PUBLIC_KEY_LENGTH', () => { + expect(typeof veilidCrypto.PUBLIC_KEY_LENGTH).toBe('number'); + }); + it('PUBLIC_KEY_LENGTH_ENCODED', () => { + expect(typeof veilidCrypto.PUBLIC_KEY_LENGTH_ENCODED).toBe('number'); + }); + it('ROUTE_ID_LENGTH', () => { + expect(typeof veilidCrypto.ROUTE_ID_LENGTH).toBe('number'); + }); + it('ROUTE_ID_LENGTH_ENCODED', () => { + expect(typeof veilidCrypto.ROUTE_ID_LENGTH_ENCODED).toBe('number'); + }); + it('SECRET_KEY_LENGTH', () => { + expect(typeof veilidCrypto.SECRET_KEY_LENGTH).toBe('number'); + }); + it('SECRET_KEY_LENGTH_ENCODED', () => { + expect(typeof veilidCrypto.SECRET_KEY_LENGTH_ENCODED).toBe('number'); + }); + it('SHARED_SECRET_LENGTH', () => { + expect(typeof veilidCrypto.SHARED_SECRET_LENGTH).toBe('number'); + }); + it('SHARED_SECRET_LENGTH_ENCODED', () => { + expect(typeof veilidCrypto.SHARED_SECRET_LENGTH_ENCODED).toBe('number'); + }); + it('SIGNATURE_LENGTH', () => { + expect(typeof veilidCrypto.SIGNATURE_LENGTH).toBe('number'); + }); + it('SIGNATURE_LENGTH_ENCODED', () => { + expect(typeof veilidCrypto.SIGNATURE_LENGTH_ENCODED).toBe('number'); + }); + }); });