pub trait DigestImplementation {
// Required method
fn digest(&self, algorithm: DigestAlgorithm, bytes: &[u8]) -> Vec<u8> ⓘ;
}
Expand description
Trait used to provide a custom digest backend to tokio_postgres_generic_rustls
This trait is implementated for three types by default, each behind it’s own feature flag. The provided backends are aws-lc-rs, ring, and rustcrypto.
Required Methods§
Sourcefn digest(&self, algorithm: DigestAlgorithm, bytes: &[u8]) -> Vec<u8> ⓘ
fn digest(&self, algorithm: DigestAlgorithm, bytes: &[u8]) -> Vec<u8> ⓘ
Hash the provided bytes with the provided algorithm
use tokio_postgres_generic_rustls::{DigestImplementation, DigestAlgorithm};
struct CustomAwsLcRsDigest;
impl DigestImplementation for CustomAwsLcRsDigest {
fn digest(&self, digest_algorithm: DigestAlgorithm, bytes: &[u8]) -> Vec<u8> {
let digest_alg = match digest_algorithm {
// Note: SHA1 is upgraded to SHA256 as per https://datatracker.ietf.org/doc/html/rfc5929#section-4.1
DigestAlgorithm::Sha1 | DigestAlgorithm::Sha256 => &aws_lc_rs::digest::SHA256,
DigestAlgorithm::Sha384 => &aws_lc_rs::digest::SHA384,
DigestAlgorithm::Sha512 => &aws_lc_rs::digest::SHA512,
};
aws_lc_rs::digest::digest(digest_alg, bytes).as_ref().into()
}
}