scryptenc_wasm/
decrypt.rs

1// SPDX-FileCopyrightText: 2022 Shun Sakai
2//
3// SPDX-License-Identifier: Apache-2.0 OR MIT
4
5//! Decrypts from the scrypt encrypted data format.
6
7use wasm_bindgen::{JsError, prelude::wasm_bindgen};
8
9/// Decrypts `ciphertext` and into a newly allocated `Uint8Array`.
10///
11/// # Errors
12///
13/// Returns an error if any of the following are true:
14///
15/// - `ciphertext` is shorter than 128 bytes.
16/// - The magic number is invalid.
17/// - The version number is the unrecognized scrypt version number.
18/// - The scrypt parameters are invalid.
19/// - The checksum of the header mismatch.
20/// - The MAC (authentication tag) of the header is invalid.
21/// - The MAC (authentication tag) of the scrypt encrypted data format is
22///   invalid.
23#[wasm_bindgen]
24pub fn decrypt(ciphertext: &[u8], passphrase: &[u8]) -> Result<Vec<u8>, JsError> {
25    scryptenc::decrypt(ciphertext, passphrase).map_err(JsError::from)
26}