sequoia_openpgp/packet/
trust.rs1use std::fmt;
2
3#[cfg(test)]
4use quickcheck::{Arbitrary, Gen};
5
6use crate::packet;
7use crate::Packet;
8
9#[derive(Clone, PartialEq, Eq, Hash)]
21pub struct Trust {
22 pub(crate) common: packet::Common,
23 value: Vec<u8>,
24}
25
26assert_send_and_sync!(Trust);
27
28impl From<Vec<u8>> for Trust {
29 fn from(u: Vec<u8>) -> Self {
30 Trust {
31 common: Default::default(),
32 value: u,
33 }
34 }
35}
36
37impl fmt::Display for Trust {
38 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39 let trust = String::from_utf8_lossy(&self.value[..]);
40 write!(f, "{}", trust)
41 }
42}
43
44impl fmt::Debug for Trust {
45 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
46 f.debug_struct("Trust")
47 .field("value", &crate::fmt::hex::encode(&self.value))
48 .finish()
49 }
50}
51
52impl Trust {
53 pub fn value(&self) -> &[u8] {
55 self.value.as_slice()
56 }
57}
58
59impl From<Trust> for Packet {
60 fn from(s: Trust) -> Self {
61 Packet::Trust(s)
62 }
63}
64
65#[cfg(test)]
66impl Arbitrary for Trust {
67 fn arbitrary(g: &mut Gen) -> Self {
68 Vec::<u8>::arbitrary(g).into()
69 }
70}
71
72#[cfg(test)]
73mod tests {
74 use super::*;
75 use crate::parse::Parse;
76 use crate::serialize::MarshalInto;
77
78 quickcheck! {
79 fn roundtrip(p: Trust) -> bool {
80 let q = Trust::from_bytes(&p.to_vec().unwrap()).unwrap();
81 assert_eq!(p, q);
82 true
83 }
84 }
85}