use std::fmt;
use puffin::codec::{Codec, Reader};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct PrivateKey(pub Vec<u8>);
#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Certificate(pub Vec<u8>);
impl Codec for PrivateKey {
fn encode(&self, bytes: &mut Vec<u8>) {
bytes.append(&mut self.0.clone())
}
fn read(r: &mut Reader) -> Option<Self> {
<Vec<u8> as Codec>::read(r).map(PrivateKey)
}
}
impl AsRef<[u8]> for Certificate {
fn as_ref(&self) -> &[u8] {
&self.0
}
}
impl fmt::Debug for Certificate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("Certificate").field(&self.0).finish()
}
}
#[cfg(test)]
mod tests {
use super::Certificate;
#[test_log::test]
fn certificate_debug() {
assert_eq!(
"Certificate([97, 98])",
format!("{:?}", Certificate(b"ab".to_vec()))
);
}
}