dax_core 0.1.0

Common data types for dax-rs
Documentation
// SPDX-FileCopyrightText: 2024 Yarmo Mackenbach
//
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

/// Identity proof
///
/// This is the struct that is used to verify the identity
/// claim. It is usually constructed based on some unique
/// identifier tied to an identity profile. For example,
/// an OpenPGP profile will have the fingerprint in URI
/// format as the proof.
#[derive(Debug)]
pub struct Proof {
    /// Text content of the proof
    pub text: String,
    /// Formats for which the proof should be checked
    pub allowed_formats: Vec<ProofFormat>,
}

impl Proof {
    /// Create a new identity proof
    pub fn new(text: &str) -> Self {
        Proof {
            text: text.to_string(),
            allowed_formats: vec![ProofFormat::Plain, ProofFormat::Hashed],
        }
    }
}

/// Method of formatting an identity proof
#[derive(Debug)]
pub enum ProofFormat {
    Plain,
    Hashed,
}

/// Method of formatting an identity proof
pub enum ProofRelation {
    Equals,
    Contains,
}

pub fn find_proof_in_str(proofs: &[Proof], data: &str, relation: ProofRelation) -> bool {
    proofs.iter().any(|proof| match relation {
        ProofRelation::Contains => data.contains(&proof.text),
        ProofRelation::Equals => data == proof.text,
    })
}