5 releases

✓ Uses Rust 2018 edition

0.2.3 Jan 14, 2020
0.2.2 Jan 10, 2019
0.2.1 Dec 30, 2018
0.2.0 Dec 30, 2018
0.1.0 Dec 25, 2018

#12 in #jwt

Download history 259/week @ 2019-10-07 203/week @ 2019-10-14 402/week @ 2019-10-21 248/week @ 2019-10-28 224/week @ 2019-11-04 160/week @ 2019-11-11 150/week @ 2019-11-18 197/week @ 2019-11-25 104/week @ 2019-12-02 100/week @ 2019-12-09 79/week @ 2019-12-16 140/week @ 2019-12-23 69/week @ 2019-12-30 124/week @ 2020-01-06 89/week @ 2020-01-13

702 downloads per month

BSD-2-Clause

44KB
666 lines

Documentation crates.io Build Status

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.5–2MB
~45K SLoC