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#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8#[derive(Debug, Clone, Hash, Eq, PartialEq, PartialOrd)]
9#[cfg_attr(feature = "serde", serde(transparent))]
10pub struct Certificate(pub(crate) String);
11
12impl Certificate {
13    pub fn new<S: Into<String>>(id: S) -> Self {
14        Self(id.into())
15    }
16
17    pub fn inner(&self) -> &String {
18        &self.0
19    }
20}
21
22impl Display for Certificate {
23    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24        write!(f, "{}", self.0)
25    }
26}
27
28// Explicitly use `From<S: Into<String>>` as `ToString` would otherwise clash with
29// the std blanket implementation.
30impl<S: Into<String>> From<S> for Certificate {
31    fn from(value: S) -> Self {
32        Certificate::new(value)
33    }
34}
35
36/// An identity claim, which can be associated with a certificate by a [Binding](crate::Binding)
37#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
38#[derive(Debug, Clone, Eq, PartialEq, Hash)]
39#[cfg_attr(feature = "serde", serde(transparent))]
40pub struct Identity(pub(crate) String);
41
42impl Identity {
43    pub fn new<S: Into<String>>(id: S) -> Self {
44        Self(id.into())
45    }
46}
47
48impl Display for Identity {
49    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50        write!(f, "{}", self.0)
51    }
52}
53
54// Explicitly use `From<S: Into<String>>` as `ToString` would otherwise clash with
55// the std blanket implementation.
56impl<S: Into<String>> From<S> for Identity {
57    fn from(value: S) -> Self {
58        Identity::new(value)
59    }
60}