68 lines
1.8 KiB
Rust
68 lines
1.8 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(String),
|
|
|
|
/// 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(endpoint) => {
|
|
format!("Target URL does not accept gementions from endpoint: {}", endpoint)
|
|
}
|
|
Self::Error(err) => err.to_string(),
|
|
}
|
|
}
|
|
}
|