wot_network/
id.rs

1use std::fmt::Display;
2
3/// Representation of an OpenPGP certificate
4///
5/// (Can be a fingerprint, but for the purpose of WoT resolution, any uniquely identifying naming
6/// scheme works)
7#[derive(Debug, Clone, Hash, Eq, PartialEq, PartialOrd)]
8pub struct Certificate(pub(crate) String);
9
10impl Certificate {
11    pub fn new<S: Into<String>>(id: S) -> Self {
12        Self(id.into())
13    }
14}
15
16impl Display for Certificate {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        write!(f, "{}", self.0)
19    }
20}
21
22// Explicitly use `From<S: Into<String>>` as `ToString` would otherwise clash with
23// the std blanket implementation.
24impl<S: Into<String>> From<S> for Certificate {
25    fn from(value: S) -> Self {
26        Certificate::new(value)
27    }
28}
29
30/// An identity claim, which can be associated with a certificate by a [Binding](crate::Binding)
31#[derive(Debug, Clone, Eq, PartialEq, Hash)]
32pub struct Identity(pub(crate) String);
33
34impl Identity {
35    pub fn new<S: Into<String>>(id: S) -> Self {
36        Self(id.into())
37    }
38}
39
40impl Display for Identity {
41    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42        write!(f, "{}", self.0)
43    }
44}
45
46// Explicitly use `From<S: Into<String>>` as `ToString` would otherwise clash with
47// the std blanket implementation.
48impl<S: Into<String>> From<S> for Identity {
49    fn from(value: S) -> Self {
50        Identity::new(value)
51    }
52}