Merge branch 'feature/wasm-constants' into 'main'

(wasm) re-export helpful length constants

See merge request veilid/veilid!200
This commit is contained in:
Christien Rioux 2023-09-26 02:50:31 +00:00
commit f66291fb06
2 changed files with 151 additions and 0 deletions

View File

@ -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
}
}

View File

@ -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');
});
});
});