[][src]Crate 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(())
}

Modules

compact

JWS Compact Serialization implementaton.

hmac

HMAC Verifier and Signer implementations using RustCrypto.

none

Verifier and Signer implementations for the none algorithm.

Macros

json_object

Create a JSON object.

Structs

Error

An error that can occur during JWS processing.

Enums

ErrorKind

Indicates the type of an error that can occur during JWS processing.

Traits

Signer

A signer for JWS messages.

Verifier

A verifier for JWS messages.

Functions

get_header_param

Get a parameter from either the protected or unprotected header, depending on which are available and which has the parameter.

get_required_header_param

Get a required parameter from either header.

parse_required_header_param

Get and deserialize a required parameter from either header.

Type Definitions

JsonObject

A JSON object.

JsonValue

Re-exported serde_json::Value.

Result

std::result::Result with the error type filled in.