use crate::compact::{JwaAlg, JweCompact, JweProtectedHeader};
use crate::compact::{JwsCompact, JwsCompactVerifyData, ProtectedHeader};
use crate::error::JwtError;
use crate::jwe::Jwe;
use crate::jws::{Jws, JwsCompactSign2Data};
use crypto_glue::aes128::Aes128Key;
use crypto_glue::aes256::Aes256Key;
pub trait JwsSigner {
fn get_kid(&self) -> &str;
fn set_kid(&mut self, kid: &str);
fn get_legacy_kid(&self) -> &str {
"no legacy kid"
}
fn update_header(&self, header: &mut ProtectedHeader) -> Result<(), JwtError>;
fn sign<V: JwsSignable>(&self, _jws: &V) -> Result<V::Signed, JwtError>;
fn set_sign_option_embed_kid(&self, value: bool) -> Self;
}
pub trait JwsMutSigner {
fn get_kid(&mut self) -> &str;
fn get_legacy_kid(&mut self) -> &str {
"no legacy kid"
}
fn update_header(&mut self, header: &mut ProtectedHeader) -> Result<(), JwtError>;
fn sign<V: JwsSignable>(&mut self, _jws: &V) -> Result<V::Signed, JwtError>;
}
pub trait JwsSignerToVerifier {
type Verifier;
fn get_verifier(&self) -> Result<Self::Verifier, JwtError>;
}
pub trait JwsVerifier {
fn get_kid(&self) -> &str;
fn verify<V: JwsVerifiable>(&self, _jwsc: &V) -> Result<V::Verified, JwtError>;
}
pub trait JwsVerifiable {
type Verified;
fn data(&self) -> JwsCompactVerifyData<'_>;
fn alg(&self) -> JwaAlg;
fn kid(&self) -> Option<&str>;
fn post_process(&self, value: Jws) -> Result<Self::Verified, JwtError>;
}
pub trait JwsSignable {
type Signed;
fn data(&self) -> Result<JwsCompactSign2Data, JwtError>;
fn post_process(&self, value: JwsCompact) -> Result<Self::Signed, JwtError>;
}
pub trait JweEncipherOuterA256 {
fn set_header_alg(&self, hdr: &mut JweProtectedHeader) -> Result<(), JwtError>;
fn wrap_key(&self, wrapping_key: Aes256Key) -> Result<Vec<u8>, JwtError>;
}
pub trait JweEncipherInnerA256 {
fn new_ephemeral() -> Result<Self, JwtError>
where
Self: Sized;
fn encipher_inner<O: JweEncipherOuterA256>(
&self,
outer: &O,
jwe: &Jwe,
) -> Result<JweCompact, JwtError>;
}
pub trait JweEncipherOuterA128 {
fn set_header_alg(&self, hdr: &mut JweProtectedHeader) -> Result<(), JwtError>;
fn wrap_key(&self, wrapping_key: Aes128Key) -> Result<Vec<u8>, JwtError>;
}
pub trait JweEncipherInnerA128 {
fn new_ephemeral() -> Result<Self, JwtError>
where
Self: Sized;
fn encipher_inner<O: JweEncipherOuterA128>(
&self,
outer: &O,
jwe: &Jwe,
) -> Result<JweCompact, JwtError>;
}