pub struct Jwt(/* private fields */);Available on crate feature
vc only.Expand description
A JSON Web Token (RFC 7519) in compact serialization, kept as the string it is.
Construction checks that the string is a well-formed compact JWS with a supported alg;
nothing is verified. The type serializes as a plain string, which is how a presentation
carries its credentials.
§Examples
use identity_kit::vc::Jwt;
// RFC 8037 Appendix A.4.
let jwt: Jwt = "eyJhbGciOiJFZERTQSJ9.RXhhbXBsZSBvZiBFZDI1NTE5IHNpZ25pbmc.\
hgyY0il_MGCjP0JzlnLWG1PPOt7-09PGcvMg3AIbQR6dWbhijcNR4ki4iylGjg5BhVsPt9g7sVvpAr_MuM0KAg"
.parse()?;
assert_eq!(jwt.decode()?.payload(), b"Example of Ed25519 signing");
assert!("not.a.jwt".parse::<Jwt>().is_err());Implementations§
Source§impl Jwt
impl Jwt
Sourcepub fn new(token: impl Into<String>) -> Result<Self, JwsError>
pub fn new(token: impl Into<String>) -> Result<Self, JwsError>
Wraps token after checking it is a compact JWS this crate can decode.
§Errors
The JwsError of CompactJws::decode.
Sourcepub async fn sign(
header: &JwsHeader,
claims: &JwtClaims,
signer: &dyn Signer,
) -> Result<Self, JwsError>
pub async fn sign( header: &JwsHeader, claims: &JwtClaims, signer: &dyn Signer, ) -> Result<Self, JwsError>
Signs claims under header with signer.
The claims are serialized as compact JSON in their field order, additional last.
§Errors
JwsError::InvalidPayload when additional holds a registered claim, which would put
the member in the payload twice; otherwise as encode_compact.
§Panics
Never: a claims set always serializes to JSON.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
The compact serialization.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Jwt
impl<'de> Deserialize<'de> for Jwt
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Jwt
impl StructuralPartialEq for Jwt
Auto Trait Implementations§
impl Freeze for Jwt
impl RefUnwindSafe for Jwt
impl Send for Jwt
impl Sync for Jwt
impl Unpin for Jwt
impl UnsafeUnpin for Jwt
impl UnwindSafe for Jwt
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.