Gemention/src/models/verification.rs

66 lines
1.7 KiB
Rust

use crate::error::GementionError;
use std::fmt::Display;
#[derive(Debug)]
pub(crate) enum VerificationStatus {
Verified {
endpoint: String,
source: VerificationSource,
},
Invalid(VerificationFailureReason),
/// Verification has not yet occurred.
NotYetVerified,
}
impl ToString for VerificationStatus {
fn to_string(&self) -> String {
match self {
Self::Verified { endpoint, source } => {
format!("verified: endpoint={} [{}]", endpoint, source)
}
Self::Invalid(failure) => failure.to_string(),
Self::NotYetVerified => format!("not yet verified"),
}
}
}
#[derive(Debug, Clone, Copy)]
pub(crate) enum VerificationSource {
Meta,
Page,
}
impl Display for VerificationSource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Meta => write!(f, "source=meta"),
Self::Page => write!(f, "source=page"),
}
}
}
#[derive(Debug)]
pub(crate) enum VerificationFailureReason {
/// No titan link to our endpoint exists on this page.
NoMentionLinkFound,
/// One or more mention links exist, but they are not to this
/// endpoint, or for this page.
MentionLinkIncorrect,
/// There was an error during the verification process.
Error(GementionError),
}
impl ToString for VerificationFailureReason {
fn to_string(&self) -> String {
match self {
Self::NoMentionLinkFound => String::from("No mention link found"),
Self::MentionLinkIncorrect => String::from("Mention link points to wrong target"),
Self::Error(err) => err.to_string(),
}
}
}