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
use crate::PetError;

#[derive(Debug, PartialEq)]
#[cfg_attr(test, derive(Clone))]
/// A dummy certificate.
pub struct Certificate(Vec<u8>);

#[allow(clippy::len_without_is_empty)]
impl Certificate {
    #[allow(clippy::new_without_default)]
    /// Create a certificate
    pub fn new() -> Self {
        Self(vec![0_u8; 32])
    }

    /// Get the length of the certificate.
    pub fn len(&self) -> usize {
        self.as_ref().len()
    }

    /// Validate a certificate
    pub fn validate(&self) -> Result<(), PetError> {
        Ok(())
    }
}

impl AsRef<[u8]> for Certificate {
    /// Get a reference to the certificate.
    fn as_ref(&self) -> &[u8] {
        self.0.as_slice()
    }
}

impl From<Vec<u8>> for Certificate {
    /// Create a certificate from bytes.
    fn from(bytes: Vec<u8>) -> Self {
        Self(bytes)
    }
}

impl From<&[u8]> for Certificate {
    /// Create a certificate from a slice of bytes.
    fn from(slice: &[u8]) -> Self {
        Self(slice.to_vec())
    }
}