pub mod compact;
pub mod hmac;
mod error;
mod header;
mod combine;
pub mod none;
pub use crate::error::{Error, ErrorKind, Result};
pub use crate::header::{get_header_param, get_required_header_param, parse_required_header_param};
pub type JsonValue = serde_json::Value;
pub type JsonObject = std::collections::BTreeMap<String, JsonValue>;
#[macro_export]
macro_rules! json_object {
{} => { $crate::JsonObject::new() };
{ $( $name:tt : $value:expr, )+ } => {{
let mut object = $crate::JsonObject::new();
$(object.insert(String::from($name), $crate::JsonValue::from($value));)*
object
}};
{ $( $name:tt : $value:expr ),+ } => {{
let mut object = $crate::JsonObject::new();
$(object.insert(String::from($name), $crate::JsonValue::from($value));)*
object
}};
}
pub trait Verifier: Sized {
fn verify(
&self,
protected_header : Option<&JsonObject>,
unprotected_header : Option<&JsonObject>,
encoded_header : &[u8],
encoded_payload : &[u8],
signature : &[u8],
) -> Result<()>;
fn or<Other: Verifier>(self, other: Other) -> combine::OrVerifier<Self, Other> {
combine::OrVerifier::new(self, other)
}
fn and<Other: Verifier>(self, other: Other) -> combine::AndVerifier<Self, Other> {
combine::AndVerifier::new(self, other)
}
}
pub trait Signer {
fn set_header_params(&self, header: &mut JsonObject);
fn compute_mac(&self, encoded_protected_header: &[u8], encoded_payload: &[u8]) -> Result<Vec<u8>>;
}