sheave_core::handlers

Function inconsistent_sha

Source
pub fn inconsistent_sha(sha: Vec<u8>) -> Error
Expand description

A utility function for wrapping the error InconsistentSha into ::std::io::Error.

ยงExamples

use std::{
    io::{
        Error,
        Result as IOResult
    },
    time::Instant
};
use sheave_core::{
    handlers::inconsistent_sha,
    handshake::{
        EncryptionAlgorithm,
        Handshake,
        Version
    }
};


fn main() -> IOResult<()> {
    let mut handshake = Handshake::new(Instant::now().elapsed(), Version::LATEST_CLIENT);
    handshake.imprint_digest(EncryptionAlgorithm::NotEncrypted, Handshake::CLIENT_KEY);
    if !handshake.did_digest_match(EncryptionAlgorithm::NotEncrypted, Handshake::CLIENT_KEY) {
        return Err(inconsistent_sha(handshake.get_digest(EncryptionAlgorithm::NotEncrypted).to_vec()))
    }

    Ok(())
}