abcrypt_wasm/
lib.rs

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