pub fn from_bytes(alg: Algorithm, bytes: &[u8]) -> Result<Hash, Error> {
        if bytes.is_empty() {
            return Ok(Hash::None);
        }
        match alg {
            Algorithm::Sha256 => {
                if bytes.len() == SHA256_HASH_SIZE {
                    let mut h = [0u8; SHA256_HASH_SIZE];
                    h.copy_from_slice(bytes);
                    Ok(Hash::Sha256(h))
                } else {
                    Err(Error::invalid_hash_size())
                }
            }
        }
    }
/// Create a new `Hash` with the given algorithm type
Create a new `Hash` with the given algorithm type
Create a new ` Hash ` with the given algorithm type
pub fn from_bytes(alg: Algorithm, bytes: &[u8]) -> Result<Hash, Error> {
        if bytes.is_empty() {
            return Ok(Hash::None);
        }
        match alg {
            Algorithm::Sha256 => {
                if bytes.len() == SHA256_HASH_SIZE {
                    let mut h = [0u8; SHA256_HASH_SIZE];
                    h.copy_from_slice(bytes);
                    Ok(Hash::Sha256(h))
                } else {
                    Err(Error::invalid_hash_size())
                }
            }
        }
    }
pub fn from_bytes ( alg : Algorithm , bytes : & [ u8 ] ) -> Result < Hash , Error > { if bytes . is_empty ( ) { return Ok ( Hash :: None ) ; } match alg { Algorithm :: Sha256 => { if bytes . len ( ) == SHA256_HASH_SIZE { let mut h = [ 0u8 ; SHA256_HASH_SIZE ] ; h . copy_from_slice ( bytes ) ; Ok ( Hash :: Sha256 ( h ) ) } else { Err ( Error :: invalid_hash_size ( ) ) } } } }
Create a new `Hash` with the given algorithm type
Create a new ` Hash ` with the given algorithm type
alg
Algorithm
bytes
&[u8]