use bh_jws_utils::JwkPublic;
use bherror::Error;
use serde_json::json;
use crate::{
into_object, Hasher, HashingAlgorithm, IssuerJwtHeader, IssuerPublicKeyLookup, Sha256,
SignatureError,
};
pub(crate) mod symbolic_crypto;
pub(crate) fn dummy_public_key_lookup() -> impl IssuerPublicKeyLookup {
struct Lookup;
impl IssuerPublicKeyLookup for Lookup {
type Err = SignatureError;
async fn lookup(
&self,
_alleged_iss: &str,
_header: &IssuerJwtHeader,
) -> Result<JwkPublic, Error<Self::Err>> {
Ok(symbolic_crypto::dummy_public_jwk())
}
}
Lookup
}
pub(crate) fn header_public_key_lookup() -> impl IssuerPublicKeyLookup {
struct Lookup;
impl IssuerPublicKeyLookup for Lookup {
type Err = SignatureError;
async fn lookup(
&self,
_alleged_iss: &str,
header: &IssuerJwtHeader,
) -> Result<JwkPublic, Error<Self::Err>> {
Ok(into_object(json!({
"kid": header.kid,
"alg": header.alg,
})))
}
}
Lookup
}
pub(crate) fn failing_public_key_lookup() -> impl IssuerPublicKeyLookup {
struct FailingLookup;
impl IssuerPublicKeyLookup for FailingLookup {
type Err = SignatureError;
async fn lookup(
&self,
_alleged_iss: &str,
_header: &crate::IssuerJwtHeader,
) -> std::result::Result<bh_jws_utils::JwkPublic, Error<Self::Err>> {
Err(Error::root(SignatureError::PublicKeyLookupFailed))
}
}
FailingLookup
}
pub(crate) fn dummy_hasher_factory(algorithm: HashingAlgorithm) -> Option<Box<dyn Hasher>> {
match algorithm {
HashingAlgorithm::Sha256 => Some(Box::new(Sha256)),
}
}
pub(crate) fn dummy_key_binding_audience() -> String {
"http://example.com/dummy_sd_jwt_verifier".into()
}