wot-network 0.0.6

Data structures for OpenPGP Web of Trust calculations
Documentation
use std::fmt::Display;

/// Representation of an OpenPGP certificate
///
/// (Can be a fingerprint, but for the purpose of WoT resolution, any uniquely identifying naming
/// scheme works)
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Hash, Eq, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct Certificate(pub(crate) String);

impl Certificate {
    pub fn new<S: Into<String>>(id: S) -> Self {
        Self(id.into())
    }

    pub fn inner(&self) -> &String {
        &self.0
    }
}

impl Display for Certificate {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

// Explicitly use `From<S: Into<String>>` as `ToString` would otherwise clash with
// the std blanket implementation.
impl<S: Into<String>> From<S> for Certificate {
    fn from(value: S) -> Self {
        Certificate::new(value)
    }
}

/// An identity claim, which can be associated with a certificate by a [Binding](crate::Binding)
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct Identity(pub(crate) String);

impl Identity {
    pub fn new<S: Into<String>>(id: S) -> Self {
        Self(id.into())
    }
}

impl Display for Identity {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

// Explicitly use `From<S: Into<String>>` as `ToString` would otherwise clash with
// the std blanket implementation.
impl<S: Into<String>> From<S> for Identity {
    fn from(value: S) -> Self {
        Identity::new(value)
    }
}