Struct ion_binary_rs::IonHash
source · pub struct IonHash<D: Digest = Sha256> { /* private fields */ }
Expand description
Ion Hash implementation. Once the hasher is initialized you can add new values to it
and it will perform the dot operation internally. Once you added everything you want
to add just call get()
and it will provide you with a &u8 slice containing the
hash.
You can use the method digest if you want to hash only one IonValue.
use sha2::Sha256;
use ion_binary_rs::{IonHash, IonValue};
use std::collections::HashMap;
let mut ion_struct = HashMap::new();
ion_struct.insert("Model".to_string(), IonValue::String("CLK 350".to_string()));
ion_struct.insert("Type".to_string(), IonValue::String("Sedan".to_string()));
ion_struct.insert("Color".to_string(), IonValue::String("White".to_string()));
ion_struct.insert(
"VIN".to_string(),
IonValue::String("1C4RJFAG0FC625797".to_string()),
);
ion_struct.insert("Make".to_string(), IonValue::String("Mercedes".to_string()));
ion_struct.insert("Year".to_string(), IonValue::Integer(2019));
let ion_value = IonValue::Struct(ion_struct);
let hash = IonHash::digest::<Sha256>(&ion_value);
println!("{:X?}", hash);
Implementations§
source§impl<D: Digest> IonHash<D>
impl<D: Digest> IonHash<D>
sourcepub fn add_bytes(&mut self, value: &[u8])
pub fn add_bytes(&mut self, value: &[u8])
Hashes the bytes and perform a dot operation with current version of the IonHash hash.
sourcepub fn add_hashed_bytes(&mut self, value: &[u8])
pub fn add_hashed_bytes(&mut self, value: &[u8])
Assumes that the bytes are already hashed and performs the dot operation with current version of the IonHash hash.
sourcepub fn add_ion_value(&mut self, value: &IonValue)
pub fn add_ion_value(&mut self, value: &IonValue)
Serializes and hashes the Ion Value and performs the dot operation with current version of the IonHash hash.
source§impl IonHash
impl IonHash
sourcepub fn from_bytes<D: Digest>(buf: &[u8]) -> IonHash<D>
pub fn from_bytes<D: Digest>(buf: &[u8]) -> IonHash<D>
Creates a hasher with some starting bytes which will be first hashed
sourcepub fn from_hashes_bytes<D: Digest>(buf: &[u8]) -> IonHash<D>
pub fn from_hashes_bytes<D: Digest>(buf: &[u8]) -> IonHash<D>
Creates a hasher with some starting hash
sourcepub fn from_ion_value<D: Digest>(value: &IonValue) -> IonHash<D>
pub fn from_ion_value<D: Digest>(value: &IonValue) -> IonHash<D>
Creates a hasher with some starting Ion Value which will be first serialized and hashed
sourcepub fn with_hasher<D: Digest>() -> IonHash<D>
pub fn with_hasher<D: Digest>() -> IonHash<D>
Creates an empty hasher using the provided hasher
sourcepub fn digest<D: Digest>(value: &IonValue) -> Vec<u8>
pub fn digest<D: Digest>(value: &IonValue) -> Vec<u8>
Shorthand method for hashing an Ion Value in one step.
sourcepub fn default_digest(value: &IonValue) -> Vec<u8>
pub fn default_digest(value: &IonValue) -> Vec<u8>
Shorthand method for hashing an Ion Value in one step. It uses the default hasher: Sha256
Trait Implementations§
source§impl<D: Digest> PartialEq for IonHash<D>
impl<D: Digest> PartialEq for IonHash<D>
source§impl<D: Digest> PartialOrd for IonHash<D>
impl<D: Digest> PartialOrd for IonHash<D>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more