mod cbor;
mod ceremony;
mod cose;
mod origin;
mod tags;
pub use ceremony::{Ceremony, Challenge, Counter, Credential, StrictCounter, TIMEOUT};
pub use cose::{Algorithm, PublicKey};
pub use origin::Origin;
use sha2::{Digest, Sha256};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RelyingParty {
pub id: String,
pub name: String,
pub origins: Vec<String>,
}
impl RelyingParty {
pub fn new(id: impl Into<String>, name: impl Into<String>, origins: Vec<String>) -> Self {
Self { id: id.into(), name: name.into(), origins }
}
pub fn fingerprint(&self) -> String {
let mut origins: php_std::Array = self.origins.iter().map(|o| php_std::Value::from(o.as_str())).collect();
let _ = php_std::sort::sort(&mut origins, php_std::sort::SortFlags::Regular);
let origins: Vec<&[u8]> = origins
.values()
.map(|o| match o {
php_std::Value::Str(s) => s.as_bytes(),
_ => b"",
})
.collect();
hex::encode(Sha256::digest([self.id.as_bytes(), b"\n", &origins.join(&b'\n')].concat()))
}
}