1 unstable release

0.1.0 Feb 17, 2024

#2461 in Algorithms

Download history 23/week @ 2024-07-01 27/week @ 2024-07-08 31/week @ 2024-07-15 27/week @ 2024-07-22 53/week @ 2024-07-29 38/week @ 2024-08-05 23/week @ 2024-08-12 20/week @ 2024-08-19 38/week @ 2024-08-26 23/week @ 2024-09-02 33/week @ 2024-09-09 21/week @ 2024-09-16 41/week @ 2024-09-23 59/week @ 2024-09-30 49/week @ 2024-10-07 28/week @ 2024-10-14

179 downloads per month

Apache-2.0

32KB
605 lines

ssri2

ssri2, short for Standard Subresource Integrity, is a Rust library for parsing, manipulating, serializing, generating, and verifying Subresource Integrity hashes.

Example

Parse a string as Integrity to convert it to a struct:

use ssri2::Integrity;

let source = "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=";

let parsed: Integrity = source.parse().unwrap();
assert_eq!(parsed.to_string(), source)

Generating a new hash from file data:

use ssri2::Integrity;

// By default, generates Integrity as Sha256.
// Use IntegrityOpts to pick the algorithm yourself.
let sri = Integrity::from(b"hello world");
assert_eq!(sri.to_string(), "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=");

Verifying data against an SRI:

use ssri2::{Integrity, Algorithm};

let sri = Integrity::from(b"hello world");
assert_eq!(sri.check(b"hello world").unwrap(), Algorithm::Sha256);

You can also use IntegrityOpts and IntegrityChecker to generate and check subresource integrity, respectively. These allow things like multiple algorithms, and incremental/streamed data input.

Documentation

Features

  • Parses and stringifies Subresource Integrity strings.
  • Generates SRI strings from raw data.
  • Strict standard compliance.
  • Multiple entries for the same algorithm.

License

This project is licensed under the Apache-2.0 License.

Dependencies

~1.1–1.8MB
~40K SLoC