Struct ssi_claims::Jws
source · pub struct Jws(/* private fields */);
Expand description
Borrowed URL-safe JWS.
This is an unsized type borrowing the JWS and meant to be referenced as
&Jws
, just like &str
.
Use JwsBuf
if you need to own the JWS.
Contrarily to JwsSlice
or JwsStr
, this type guarantees that
the payload is URL-safe, even if it is unencoded.
Use JwsStr
if you expect an UTF-8 encoded JWS but don’t know if it is
URL-safe.
Use JwsSlice
if you don’t have any expectations about the encoding.
Implementations§
source§impl Jws
impl Jws
pub fn new<T>(data: &T) -> Result<&Jws, InvalidJws<&T>>
sourcepub const fn from_str_const(input: &str) -> Result<&Jws, InvalidJws<&str>>
pub const fn from_str_const(input: &str) -> Result<&Jws, InvalidJws<&str>>
Parses the given input
string as an URL-safe JWS.
Returns an error if it is not a valid URL-safe JWS.
pub const fn validate(bytes: &[u8]) -> bool
pub const fn validate_range(bytes: &[u8], i: usize, end: usize) -> bool
sourcepub const unsafe fn new_unchecked(data: &[u8]) -> &Jws
pub const unsafe fn new_unchecked(data: &[u8]) -> &Jws
Creates a new compact JWS without checking the data.
§Safety
The input data
must represent a valid compact JWS where the payload
is an UTF-8 string.
pub fn as_str(&self) -> &str
Methods from Deref<Target = JwsSlice>§
pub fn len(&self) -> usize
pub fn decode_header(&self) -> Result<Header, InvalidHeader>
sourcepub fn decode_payload(
&self,
header: &Header,
) -> Result<Cow<'_, [u8]>, DecodeError>
pub fn decode_payload( &self, header: &Header, ) -> Result<Cow<'_, [u8]>, DecodeError>
Decode the payload bytes.
The header is necessary to know how the payload is encoded.
pub fn decode_signature(&self) -> Result<JwsSignature, DecodeError>
sourcepub fn decode(&self) -> Result<DecodedJws<'_, Cow<'_, [u8]>>, DecodeError>
pub fn decode(&self) -> Result<DecodedJws<'_, Cow<'_, [u8]>>, DecodeError>
Decodes the entire JWS.
sourcepub fn signing_bytes(&self) -> &[u8] ⓘ
pub fn signing_bytes(&self) -> &[u8] ⓘ
Returns the signing bytes.
It is the concatenation of the Base64 encoded headers, a period ‘.’ and the Base64 encoded payload.
pub fn as_bytes(&self) -> &[u8] ⓘ
sourcepub async fn verify<V>(
&self,
params: V,
) -> Result<Result<(), Invalid>, ProofValidationError>
pub async fn verify<V>( &self, params: V, ) -> Result<Result<(), Invalid>, ProofValidationError>
Verify the JWS signature.
This will only check the signature and not the validity of the decoded payload. For instance if the payload is a set of JWT claims, those claims will not be validated.
To perform a more precise verification, specify use a specialized T
instead of the default Vec<u8>
The params
argument provides all the verification parameters required
to validate the claims and proof.
§What verification parameters should I use?
Any type that providing a JWKResolver
through the ResolverProvider
trait will be fine. Notable implementors are:
VerificationParameters
: A good default providing many other common verification parameters that are not necessary here.JWK
: allows you to put a JWK asparams
, which will resolve into itself. Can be useful if you don’t need key resolution because you know in advance what key was used to sign the JWS.
§Passing the parameters by reference
If the validation traits are implemented for P
, they will be
implemented for &P
as well. This means the parameters can be passed
by move or by reference.
Trait Implementations§
source§impl PartialOrd for Jws
impl PartialOrd for Jws
source§impl Serialize for Jws
impl Serialize for Jws
source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl Eq for Jws
impl StructuralPartialEq for Jws
Auto Trait Implementations§
impl Freeze for Jws
impl RefUnwindSafe for Jws
impl Send for Jws
impl !Sized for Jws
impl Sync for Jws
impl Unpin for Jws
impl UnwindSafe for Jws
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
source§impl<T> CallHasher for T
impl<T> CallHasher for T
source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
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
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
fn equivalent(&self, key: &K) -> bool
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.