1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-FileCopyrightText: 2022 Shun Sakai
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! The `scryptenc-wasm` crate is the Wasm bindings for the [`scryptenc`] crate.

#![doc(html_root_url = "https://docs.rs/scryptenc-wasm/0.1.0/")]
// Lint levels of rustc.
#![forbid(unsafe_code)]
#![deny(missing_debug_implementations, missing_docs)]
#![warn(rust_2018_idioms)]
// Lint levels of Clippy.
#![warn(clippy::cargo, clippy::nursery, clippy::pedantic)]

mod decrypt;
mod encrypt;
mod params;

use wasm_bindgen::prelude::wasm_bindgen;

pub use crate::{
    decrypt::decrypt,
    encrypt::{encrypt, encrypt_with_params},
    params::Params,
};

#[allow(clippy::missing_const_for_fn)]
/// The number of bytes of the header.
#[must_use]
#[inline]
#[wasm_bindgen]
pub fn header_size() -> usize {
    scryptenc::HEADER_SIZE
}

#[allow(clippy::missing_const_for_fn)]
/// The number of bytes of the MAC (authentication tag) of the scrypt encrypted
/// data format.
#[must_use]
#[inline]
#[wasm_bindgen]
pub fn tag_size() -> usize {
    scryptenc::TAG_SIZE
}

#[cfg(test)]
mod tests {
    use wasm_bindgen_test::wasm_bindgen_test;

    #[wasm_bindgen_test]
    fn header_size() {
        assert_eq!(super::header_size(), 96);
        assert_eq!(super::header_size(), scryptenc::HEADER_SIZE);
    }

    #[wasm_bindgen_test]
    fn tag_size() {
        assert_eq!(super::tag_size(), 32);
        assert_eq!(super::tag_size(), scryptenc::TAG_SIZE);
    }
}