rc_crypto/lib.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5// This file contains code that was copied from the ring crate which is under
6// the ISC license, reproduced below:
7
8// Copyright 2015-2017 Brian Smith.
9
10// Permission to use, copy, modify, and/or distribute this software for any
11// purpose with or without fee is hereby granted, provided that the above
12// copyright notice and this permission notice appear in all copies.
13
14// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
15// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
17// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
19// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21
22#![allow(unknown_lints)]
23#![warn(rust_2018_idioms)]
24/// This crate provides all the cryptographic primitives required by
25/// this workspace, backed by the NSS library.
26/// The exposed API is pretty much the same as the `ring` crate.
27pub mod aead;
28pub mod agreement;
29pub mod constant_time;
30pub mod contentsignature;
31pub mod digest;
32#[cfg(feature = "ece")]
33pub mod ece_crypto;
34mod error;
35#[cfg(feature = "hawk")]
36mod hawk_crypto;
37pub mod hkdf;
38pub mod hmac;
39pub mod pbkdf2;
40pub mod rand;
41pub mod signature;
42
43// Expose `hawk` if the hawk feature is on. This avoids consumers needing to
44// configure this separately, which is more or less trivial to do incorrectly.
45#[cfg(feature = "hawk")]
46pub use hawk;
47
48// Expose `ece` if the ece feature is on. This avoids consumers needing to
49// configure this separately, which is more or less trivial to do incorrectly.
50#[cfg(feature = "ece")]
51pub use ece;
52
53pub use crate::error::{Error, ErrorKind, Result};
54
55/// Only required to be called if you intend to use this library in conjunction
56/// with the `hawk` or the `ece` crate.
57pub fn ensure_initialized() {
58 nss::assert_initialized();
59
60 #[cfg(any(feature = "hawk", feature = "ece"))]
61 {
62 static INIT_ONCE: std::sync::Once = std::sync::Once::new();
63 INIT_ONCE.call_once(|| {
64 #[cfg(feature = "hawk")]
65 crate::hawk_crypto::init();
66 #[cfg(feature = "ece")]
67 crate::ece_crypto::init();
68 });
69 }
70}