(wasm) re-export helpful length constants

This commit is contained in:
Brandon Vandegrift 2023-09-24 14:47:22 -04:00
parent 38ff6f81c5
commit 1af71e7154
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); crypto_system.crypt_in_place_no_auth(&mut body, &nonce, &shared_secret);
APIResult::Ok(body) 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(); }).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');
});
});
}); });