#[cfg(feature = "did-jwk")]
#[cfg_attr(docsrs, doc(cfg(feature = "did-jwk")))]
pub mod jwk;
#[cfg(feature = "did-key")]
#[cfg_attr(docsrs, doc(cfg(feature = "did-key")))]
pub mod key;
#[cfg(feature = "did-web")]
#[cfg_attr(docsrs, doc(cfg(feature = "did-web")))]
pub mod web;
#[cfg(feature = "did-jwk")]
mod jcs;
#[cfg(feature = "did-jwk")]
pub use jwk::DidJwk;
#[cfg(feature = "did-key")]
pub use key::DidKey;
#[cfg(feature = "did-web")]
pub use web::DidWeb;
use crate::did::{
APPLICATION_DID_JSON, APPLICATION_DID_LD_JSON, ResolutionError, ResolutionErrorKind,
ResolutionOptions,
};
#[cfg(any(feature = "did-key", feature = "did-jwk"))]
use crate::jose::Jwk;
#[cfg(any(feature = "did-key", feature = "did-jwk"))]
use crate::resolver::ProduceError;
#[allow(unused_imports)]
use crate::resolver::{DidProducer, DidResolver, Resolver, ResolverBuilder};
#[cfg(feature = "did-web")]
#[cfg_attr(docsrs, doc(cfg(feature = "did-web")))]
pub fn default_methods(http: impl web::HttpClient + 'static) -> ResolverBuilder {
let builder = Resolver::builder();
#[cfg(feature = "did-key")]
let builder = builder.with(DidKey::default());
#[cfg(feature = "did-jwk")]
let builder = builder.with(DidJwk);
builder.with(DidWeb::new(http))
}
#[cfg(any(feature = "did-key", feature = "did-jwk"))]
fn single_key(keys: &[Jwk]) -> Result<&Jwk, ProduceError> {
match keys {
[] => Err(ProduceError::NoKeys),
[key] => Ok(key),
_ => Err(ProduceError::TooManyKeys {
max: 1,
actual: keys.len(),
}),
}
}
const JSON_MEDIA_TYPES: [&str; 3] = [
APPLICATION_DID_JSON,
APPLICATION_DID_LD_JSON,
"application/json",
];
fn check_accept(options: &ResolutionOptions) -> Result<(), ResolutionError> {
match options.accept.as_deref() {
None => Ok(()),
Some(accept) if JSON_MEDIA_TYPES.contains(&accept) => Ok(()),
Some(accept) => Err(
ResolutionError::new(ResolutionErrorKind::RepresentationNotSupported)
.with_detail(format!("`{accept}` is not a JSON representation")),
),
}
}