|  | 
|  | 1 | +// Copyright 2024 Contributors to the Parsec project. | 
|  | 2 | +// SPDX-License-Identifier: Apache-2.0 | 
|  | 3 | + | 
|  | 4 | +use crate::interface_types::algorithm::HashingAlgorithm; | 
|  | 5 | + | 
|  | 6 | +/// Provides the value of the digest used in this crate for the digest. | 
|  | 7 | +pub trait AssociatedHashingAlgorithm { | 
|  | 8 | +    /// Value of the digest when interacting with the TPM. | 
|  | 9 | +    const TPM_DIGEST: HashingAlgorithm; | 
|  | 10 | +} | 
|  | 11 | + | 
|  | 12 | +#[cfg(all(feature = "rustcrypto", feature = "sha1"))] | 
|  | 13 | +impl AssociatedHashingAlgorithm for sha1::Sha1 { | 
|  | 14 | +    const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha1; | 
|  | 15 | +} | 
|  | 16 | + | 
|  | 17 | +#[cfg(all(feature = "rustcrypto", feature = "sha2"))] | 
|  | 18 | +impl AssociatedHashingAlgorithm for sha2::Sha256 { | 
|  | 19 | +    const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha256; | 
|  | 20 | +} | 
|  | 21 | + | 
|  | 22 | +#[cfg(all(feature = "rustcrypto", feature = "sha2"))] | 
|  | 23 | +impl AssociatedHashingAlgorithm for sha2::Sha384 { | 
|  | 24 | +    const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha384; | 
|  | 25 | +} | 
|  | 26 | + | 
|  | 27 | +#[cfg(all(feature = "rustcrypto", feature = "sha2"))] | 
|  | 28 | +impl AssociatedHashingAlgorithm for sha2::Sha512 { | 
|  | 29 | +    const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha512; | 
|  | 30 | +} | 
|  | 31 | + | 
|  | 32 | +#[cfg(all(feature = "rustcrypto", feature = "sm3"))] | 
|  | 33 | +impl AssociatedHashingAlgorithm for sm3::Sm3 { | 
|  | 34 | +    const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sm3_256; | 
|  | 35 | +} | 
|  | 36 | + | 
|  | 37 | +#[cfg(all(feature = "rustcrypto", feature = "sha3"))] | 
|  | 38 | +impl AssociatedHashingAlgorithm for sha3::Sha3_256 { | 
|  | 39 | +    const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_256; | 
|  | 40 | +} | 
|  | 41 | + | 
|  | 42 | +#[cfg(all(feature = "rustcrypto", feature = "sha3"))] | 
|  | 43 | +impl AssociatedHashingAlgorithm for sha3::Sha3_384 { | 
|  | 44 | +    const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_384; | 
|  | 45 | +} | 
|  | 46 | + | 
|  | 47 | +#[cfg(all(feature = "rustcrypto", feature = "sha3"))] | 
|  | 48 | +impl AssociatedHashingAlgorithm for sha3::Sha3_512 { | 
|  | 49 | +    const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_512; | 
|  | 50 | +} | 
0 commit comments