// Copyright 2023 Cryspen Sarl // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0
//! This module contains the trait and related errors for hashers that take slices as //! arguments and write the results to mutable slices.
usesuper::arrayref;
/// A trait for oneshot hashing, where the output is written to a provided slice. pubtrait Hash { /// Writes the digest for the given input byte slice, into `digest` in immediate mode. fn hash(digest: &mut [u8], payload: &[u8]) -> Result<usize, HashError>;
}
/// A trait for incremental hashing, where the output is written to a provided slice. pubtrait DigestIncremental: super::DigestIncrementalBase { /// Writes the digest into `digest`. /// /// Note that the digest state can be continued to be used, to extend the digest. fn finish(state: &mutSelf::IncrementalState, digest: &e='color:red'>mut [u8]) -> Result<usize, FinishError>;
}
/// Error indicating that finalizing failed. #[derive(Debug, PartialEq)] pubenum FinishError { /// The length of the provided digest buffer is invalid.
InvalidDigestLength, /// Unknown error.
Unknown,
}
impl core::fmt::Display for FinishError { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let text = matchself {
FinishError::InvalidDigestLength => { "the length of the provided digest buffer is invalid"
}
FinishError::Unknown => "indicates an unknown error",
};
f.write_str(text)
}
}
/// Error indicating that hashing failed. #[derive(Debug, PartialEq)] pubenum HashError { /// The length of the provided digest buffer is invalid.
InvalidDigestLength, /// The length of the provided payload is invalid.
InvalidPayloadLength,
}
impl core::fmt::Display for HashError { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let text = matchself {
HashError::InvalidDigestLength => "the length of the provided digest buffer is invalid",
HashError::InvalidPayloadLength => "the length of the provided payload is invalid",
};
f.write_str(text)
}
}
#[cfg(feature = "error-in-core")] mod error_in_core {
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.