pub struct CompactJws { /* private fields */ }Expand description
A decoded compact JWS: BASE64URL(header) || '.' || BASE64URL(payload) || '.' || BASE64URL(signature).
Decoding parses the header and the parts and nothing more: CompactJws::verify (or any
JwsVerifier) checks the signature once the caller has resolved the key, which usually
means dereferencing kid through a DID resolver.
§Examples
use identity_kit::jose::{CompactJws, JwsAlgorithm};
// RFC 8037 Appendix A.4.
let token = "eyJhbGciOiJFZERTQSJ9.RXhhbXBsZSBvZiBFZDI1NTE5IHNpZ25pbmc.\
hgyY0il_MGCjP0JzlnLWG1PPOt7-09PGcvMg3AIbQR6dWbhijcNR4ki4iylGjg5BhVsPt9g7sVvpAr_MuM0KAg";
let jws = CompactJws::decode(token)?;
assert_eq!(jws.alg(), JwsAlgorithm::EdDSA);
assert_eq!(jws.kid(), None);
assert_eq!(jws.payload(), b"Example of Ed25519 signing");
assert_eq!(
jws.signing_input(),
b"eyJhbGciOiJFZERTQSJ9.RXhhbXBsZSBvZiBFZDI1NTE5IHNpZ25pbmc"
);
assert_eq!(jws.signature().len(), 64);Implementations§
Source§impl CompactJws
impl CompactJws
Sourcepub fn alg(&self) -> JwsAlgorithm
pub fn alg(&self) -> JwsAlgorithm
The header alg.
Sourcepub fn signing_input(&self) -> &[u8] ⓘ
pub fn signing_input(&self) -> &[u8] ⓘ
The JWS signing input: BASE64URL(header) || '.' || BASE64URL(payload) as ASCII.
Sourcepub fn claims<T: DeserializeOwned>(&self) -> Result<T, JwsError>
pub fn claims<T: DeserializeOwned>(&self) -> Result<T, JwsError>
The payload read as JSON into T, a JwtClaims set say, unverified:
nothing about the signature or the claims is checked.
§Errors
JwsError::InvalidPayload when the payload is not JSON of the shape T expects.
§Examples
use identity_kit::jose::{CompactJws, JwtClaims};
// RFC 7515 Appendix A.3: the RFC 7519 §3.1 claims set, signed with ES256.
let jws = CompactJws::decode(
"eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGF\
tcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDx\
w5djxLa8ISlSApmWQxfKTUJqPP3-Kg6NU1Q",
)?;
let claims: JwtClaims = jws.claims()?;
assert_eq!(claims.iss.as_deref(), Some("joe"));
assert_eq!(claims.exp, Some(1300819380));
assert_eq!(claims.additional["http://example.com/is_root"], true);Sourcepub fn verify<V: JwsVerifier + ?Sized>(
&self,
verifier: &V,
key: &Jwk,
) -> Result<(), VerificationError>
pub fn verify<V: JwsVerifier + ?Sized>( &self, verifier: &V, key: &Jwk, ) -> Result<(), VerificationError>
Verifies the signature with verifier under key and the header alg.
§Errors
Whatever the verifier reports; see JwsVerifier::verify.
Trait Implementations§
Source§impl AsRef<str> for CompactJws
impl AsRef<str> for CompactJws
Source§impl Clone for CompactJws
impl Clone for CompactJws
Source§impl Debug for CompactJws
impl Debug for CompactJws
Auto Trait Implementations§
impl Freeze for CompactJws
impl RefUnwindSafe for CompactJws
impl Send for CompactJws
impl Sync for CompactJws
impl Unpin for CompactJws
impl UnsafeUnpin for CompactJws
impl UnwindSafe for CompactJws
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more