aboutsummaryrefslogtreecommitdiff
path: root/embassy-boot/src/digest_adapters/ed25519_dalek.rs
blob: 2e4e03da32cc36140bfda72f00ff76782c282279 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use digest::typenum::U64;
use digest::{FixedOutput, HashMarker, OutputSizeUser, Update};
use ed25519_dalek::Digest;

pub struct Sha512(ed25519_dalek::Sha512);

impl Default for Sha512 {
    fn default() -> Self {
        Self(ed25519_dalek::Sha512::new())
    }
}

impl Update for Sha512 {
    fn update(&mut self, data: &[u8]) {
        Digest::update(&mut self.0, data)
    }
}

impl FixedOutput for Sha512 {
    fn finalize_into(self, out: &mut digest::Output<Self>) {
        let result = self.0.finalize();
        out.as_mut_slice().copy_from_slice(result.as_slice())
    }
}

impl OutputSizeUser for Sha512 {
    type OutputSize = U64;
}

impl HashMarker for Sha512 {}