windowed_infinity/
wrappers.rs

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! Types that encapsulate foreign types into embedded-io writers, suitable for inclusion in a Tee
//!
//! These types are not exposed publicly (only inside a Tee which on its own is not public yet).

use super::MyWrite;

pub struct WritableDigest<D: digest::Digest>(pub(crate) D);

impl<D: digest::Digest> MyWrite for WritableDigest<D> {
    type Error = core::convert::Infallible;

    fn write(&mut self, buf: &[u8]) -> Result<(), Self::Error> {
        self.0.update(buf);
        Ok(())
    }

    fn flush(&mut self) -> Result<(), Self::Error> {
        Ok(())
    }
}

impl<'a, D: digest::Digest> crate::tee::Tee<crate::WindowedInfinity<'a>, WritableDigest<D>> {
    pub fn into_windowed_and_digest(self) -> (crate::WindowedInfinity<'a>, D) {
        (self.w1, self.w2.0)
    }
}

pub struct WritableCrc<'c, W: crc::Width>(pub(crate) crc::Digest<'c, W>);

impl<'c> MyWrite for WritableCrc<'c, u64> {
    type Error = core::convert::Infallible;

    fn write(&mut self, buf: &[u8]) -> Result<(), Self::Error> {
        self.0.update(buf);
        Ok(())
    }

    fn flush(&mut self) -> Result<(), Self::Error> {
        Ok(())
    }
}

impl<'c> MyWrite for WritableCrc<'c, u32> {
    type Error = core::convert::Infallible;

    fn write(&mut self, buf: &[u8]) -> Result<(), Self::Error> {
        self.0.update(buf);
        Ok(())
    }

    fn flush(&mut self) -> Result<(), Self::Error> {
        Ok(())
    }
}

impl<'a, 'c> crate::tee::Tee<crate::WindowedInfinity<'a>, WritableCrc<'c, u64>> {
    pub fn into_windowed_and_crc(self) -> (crate::WindowedInfinity<'a>, crc::Digest<'c, u64>) {
        (self.w1, self.w2.0)
    }
}

impl<'a, 'c> crate::tee::Tee<crate::WindowedInfinity<'a>, WritableCrc<'c, u32>> {
    pub fn into_windowed_and_crc(self) -> (crate::WindowedInfinity<'a>, crc::Digest<'c, u32>) {
        (self.w1, self.w2.0)
    }
}