pub struct WasmConversions;Expand description
Byte-array conversion helpers for WASM bindings.
Implementations§
Source§impl WasmConversions
impl WasmConversions
Sourcepub fn vec_to_uint8array(data: &[u8]) -> Uint8Array
pub fn vec_to_uint8array(data: &[u8]) -> Uint8Array
Copy data into a new JavaScript Uint8Array.
The input slice is not modified; callers that need the source buffer cleared must do so
separately (for example by holding secrets in [zeroize::Zeroizing] and letting it drop
after this call).
Sourcepub fn uint8array_to_vec(array: &Uint8Array) -> Result<Vec<u8>>
pub fn uint8array_to_vec(array: &Uint8Array) -> Result<Vec<u8>>
Convert WASM Uint8Array to Rust Vec
Validates input size to limit abuse; copies array contents into a new Vec.
Sourcepub fn string_to_algorithm(algorithm_str: &str) -> Result<Algorithm>
pub fn string_to_algorithm(algorithm_str: &str) -> Result<Algorithm>
Convert algorithm string to Algorithm enum
This function provides secure algorithm parsing with:
- Input validation to prevent injection attacks
- Case-insensitive matching for user convenience
- Clear error messages for unsupported algorithms
Sourcepub fn algorithm_to_string(algorithm: Algorithm) -> String
pub fn algorithm_to_string(algorithm: Algorithm) -> String
Convert Algorithm enum to string
This function provides consistent algorithm naming for JavaScript
Sourcepub fn kem_keypair_to_js(
public_key: &[u8],
secret_key: &[u8],
) -> Result<JsValue>
pub fn kem_keypair_to_js( public_key: &[u8], secret_key: &[u8], ) -> Result<JsValue>
Convert KEM keypair to JavaScript object
This function securely serializes keypair data for JavaScript consumption
Sourcepub fn sig_keypair_to_js(
public_key: &[u8],
secret_key: &[u8],
) -> Result<JsValue>
pub fn sig_keypair_to_js( public_key: &[u8], secret_key: &[u8], ) -> Result<JsValue>
Convert signature keypair to JavaScript object
This function securely serializes keypair data for JavaScript consumption
Sourcepub fn hash_result_to_js(hash: &[u8], algorithm: Algorithm) -> Result<JsValue>
pub fn hash_result_to_js(hash: &[u8], algorithm: Algorithm) -> Result<JsValue>
Convert hash result to JavaScript object
This function securely serializes hash data for JavaScript consumption
Sourcepub fn error_to_js(error: &Error) -> JsValue
pub fn error_to_js(error: &Error) -> JsValue
Convert error to JavaScript error
This function provides secure error conversion that doesn’t leak sensitive information