scryptenc_wasm/
lib.rs

1// SPDX-FileCopyrightText: 2022 Shun Sakai
2//
3// SPDX-License-Identifier: Apache-2.0 OR MIT
4
5//! The `scryptenc-wasm` crate is the Wasm bindings for the `scryptenc` crate.
6
7#![doc(html_root_url = "https://docs.rs/scryptenc-wasm/0.3.0/")]
8// Lint levels of rustc.
9#![deny(missing_docs)]
10
11mod decrypt;
12mod encrypt;
13mod params;
14
15use wasm_bindgen::prelude::wasm_bindgen;
16
17pub use crate::{
18    decrypt::decrypt,
19    encrypt::{encrypt, encrypt_with_params},
20    params::Params,
21};
22
23#[allow(clippy::missing_const_for_fn)]
24/// The number of bytes of the header.
25#[must_use]
26#[wasm_bindgen(js_name = headerSize)]
27pub fn header_size() -> usize {
28    scryptenc::HEADER_SIZE
29}
30
31#[allow(clippy::missing_const_for_fn)]
32/// The number of bytes of the MAC (authentication tag) of the scrypt encrypted
33/// data format.
34#[must_use]
35#[wasm_bindgen(js_name = tagSize)]
36pub fn tag_size() -> usize {
37    scryptenc::TAG_SIZE
38}
39
40#[cfg(test)]
41mod tests {
42    use wasm_bindgen_test::wasm_bindgen_test;
43
44    #[wasm_bindgen_test]
45    fn header_size() {
46        assert_eq!(super::header_size(), 96);
47        assert_eq!(super::header_size(), scryptenc::HEADER_SIZE);
48    }
49
50    #[wasm_bindgen_test]
51    fn tag_size() {
52        assert_eq!(super::tag_size(), 32);
53        assert_eq!(super::tag_size(), scryptenc::TAG_SIZE);
54    }
55}