use serde::de::DeserializeOwned;
use crate::{
decentralised_identifier::DecentralizedIdentifier,
error::NzcpError,
payload::{barcode::QrBarcode, cose::CoseStructure},
};
pub(crate) mod public_covid_pass;
pub trait Pass: DeserializeOwned {
const CREDENTIAL_TYPE: &'static str;
const CONTEXT_URL: &'static str;
}
const MINISTRY_OF_HEALTH_ISSUER: DecentralizedIdentifier<'static> =
DecentralizedIdentifier::Web("nzcp.identity.health.nz");
pub async fn verify_pass_uri<P: Pass>(uri: &str) -> Result<P, NzcpError> {
verify_pass_uri_with_trusted_issuers(uri, &[MINISTRY_OF_HEALTH_ISSUER]).await
}
#[doc(hidden)]
pub async fn verify_pass_uri_with_trusted_issuers<P: Pass>(
barcode_str: &str,
trusted_issuers: &[DecentralizedIdentifier<'_>],
) -> Result<P, NzcpError> {
let barcode: QrBarcode = barcode_str.parse()?;
let cose: CoseStructure<'_, P> = serde_cbor::from_slice(&barcode.0)?;
let cwt = cose.verified_claims(trusted_issuers).await?;
let pass = cwt.validated_credential_subject()?;
Ok(pass)
}