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

use thiserror::Error;

use crate::fetcher::ProofFetchError;

/// Identity claim
#[derive(Debug)]
pub struct Claim {
    pub uri: String,
    pub claim_type: ClaimType,
}

#[derive(Debug)]
pub enum ClaimType {
    PlainUri,
    DataUri(ClaimService),
}

#[derive(Debug)]
pub enum ClaimService {
    Forgejo,
    Gitea,
}

impl Claim {
    /// Create a new identity claim
    pub fn new(text: &str) -> Self {
        Claim {
            uri: text.to_owned(),
            claim_type: ClaimType::PlainUri,
        }
    }
}

/// Results of a claim verification
#[derive(Default, Debug)]
pub struct ClaimVerificationResult {
    pub result: bool,
}

#[derive(Error, Debug)]
pub enum ClaimVerificationError {
    #[error("proof fetching error")]
    ProofFetch(#[from] ProofFetchError),
    #[error("claim and service mismatch error")]
    ServiceMismatch,
    #[error("proof processing error")]
    ProofProcessing,
    #[error("claim processing error")]
    ClaimProcessing,
    #[error("unknown claim verification error")]
    Unknown,
}

#[derive(Error, Debug)]
pub enum ClaimMatchingError {
    #[error("claim processing error")]
    ClaimProcessing,
    #[error("unknown claim matching error")]
    Unknown,
}