ssi_data_integrity_core/suite/standard/
hashing.rs1use ssi_claims_core::{ProofValidationError, SignatureError};
2
3use crate::ProofConfigurationRef;
4
5use super::{StandardCryptographicSuite, TransformedData};
6
7pub type HashedData<S> =
8 <<S as StandardCryptographicSuite>::Hashing as HashingAlgorithm<S>>::Output;
9
10#[derive(Debug, thiserror::Error)]
11pub enum HashingError {
12 #[error("invalid message: {0}")]
13 InvalidMessage(String),
14
15 #[error("message is too long")]
16 TooLong,
17
18 #[error("invalid key")]
19 InvalidKey,
20}
21
22impl From<HashingError> for SignatureError {
23 fn from(value: HashingError) -> Self {
24 Self::other(value)
25 }
26}
27
28impl From<HashingError> for ProofValidationError {
29 fn from(value: HashingError) -> Self {
30 Self::other(value)
31 }
32}
33
34pub trait HashingAlgorithm<S: StandardCryptographicSuite> {
36 type Output;
37
38 fn hash(
39 input: TransformedData<S>,
40 proof_configuration: ProofConfigurationRef<S>,
41 verification_method: &S::VerificationMethod,
42 ) -> Result<Self::Output, HashingError>;
43}