8 releases

0.2.7 May 10, 2022
0.2.6 Jan 30, 2022
0.2.5 Oct 3, 2021
0.2.4 Oct 14, 2020
0.1.0 Dec 25, 2018

#6 in #jws

Download history 55/week @ 2022-11-29 139/week @ 2022-12-06 90/week @ 2022-12-13 102/week @ 2022-12-20 216/week @ 2022-12-27 91/week @ 2023-01-03 197/week @ 2023-01-10 85/week @ 2023-01-17 72/week @ 2023-01-24 124/week @ 2023-01-31 65/week @ 2023-02-07 99/week @ 2023-02-14 53/week @ 2023-02-21 57/week @ 2023-02-28 53/week @ 2023-03-07 79/week @ 2023-03-14

271 downloads per month

BSD-2-Clause

46KB
677 lines

Documentation crates.io tests

jws

This library provides JSON Web Signature encoding, decoding, signing and verification as described in RFC 7515.

Currently, encoding and decoding is available only for the JWS Compact Serialization scheme in the compact module.

Signing and verifying is done through the Signer and Verifier traits. The hmac module contains implementations for these traits that support the HMAC-SHA2 family of algorithms.

Example:

use jws::{JsonObject, JsonValue};
use jws::compact::{decode_verify, encode_sign};
use jws::hmac::{Hs512Signer, HmacVerifier};

fn encode_decode() -> jws::Result<()> {
  // Add custom header parameters.
  let mut header = JsonObject::new();
  header.insert(String::from("typ"), JsonValue::from("text/plain"));

  // Encode and sign the message.
  let encoded = encode_sign(header, b"payload", &Hs512Signer::new(b"secretkey"))?;

  // Decode and verify the message.
  let decoded = decode_verify(encoded.data().as_bytes(), &HmacVerifier::new(b"secretkey"))?;

  assert_eq!(decoded.payload, b"payload");
  assert_eq!(decoded.header.get("typ").and_then(|x| x.as_str()), Some("text/plain"));

  Ok(())
}

Dependencies

~1.6–2.4MB
~54K SLoC