json-digest 0.0.16

Allow selective masking of JSON subdocuments for privacy, preserving the digest of the whole document.
Documentation
use super::*;

/// Multibase-encoded random content, e.g. "urvU8F6HmEol5zOmHh_nnS1RiX5r3T2t9U_d_kQY7ZC-I"
///
/// The amount of entropy is chosen as 264 bits to end up with full digits in the base64
/// encoding used.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(transparent)]
pub struct Nonce264(pub String);

impl Nonce264 {
    /// Generates a new [`Nonce264`]. Uses the `getrandom` crate to find the best source of entropy on the platform.
    /// In JavaScript tests you might need to refer to <https://github.com/jsdom/jsdom/issues/1612> for
    /// how to fix phantom browsers to comply with HTML5 specs.
    pub fn generate() -> Self {
        use rand::{thread_rng, RngCore};
        let mut arr = [0u8; 33];
        thread_rng().fill_bytes(&mut arr[..]);
        let encoded = multibase::encode(multibase::Base::Base64Url, &arr[..]);
        Self(encoded)
    }
}