use std::fmt;
pub const INTEGRITY_TOKEN_HEADER: &str = "integrity-token";
pub const SIGNATURE_INPUT_HEADER: &str = "signature-input";
pub const SIGNATURE_HEADER: &str = "signature";
pub const SIGNATURE_LABEL: &str = "integrity";
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Component {
Method,
Scheme,
Authority,
Path,
Query,
ContentDigest,
IntegrityToken,
}
impl Component {
pub const ALL: [Self; 7] = [
Self::Method,
Self::Scheme,
Self::Authority,
Self::Path,
Self::Query,
Self::ContentDigest,
Self::IntegrityToken,
];
#[must_use]
pub const fn identifier(self) -> &'static str {
match self {
Self::Method => "@method",
Self::Scheme => "@scheme",
Self::Authority => "@authority",
Self::Path => "@path",
Self::Query => "@query",
Self::ContentDigest => "content-digest",
Self::IntegrityToken => "integrity-token",
}
}
#[must_use]
pub fn from_identifier(identifier: &str) -> Option<Self> {
Self::ALL
.into_iter()
.find(|component| component.identifier() == identifier)
}
}
impl fmt::Display for Component {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.identifier())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Platform {
Ios,
Android,
}
impl Platform {
#[must_use]
pub const fn alg(self) -> &'static str {
match self {
Self::Ios => "world-integrity-ios-v1",
Self::Android => "world-integrity-android-v1",
}
}
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Ios => "ios",
Self::Android => "android",
}
}
#[must_use]
pub fn from_claim(claim: &str) -> Option<Self> {
match claim {
"ios" => Some(Self::Ios),
"android" => Some(Self::Android),
_ => None,
}
}
}
impl fmt::Display for Platform {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}