17 stable releases (9 major)

9.2.0 Jul 18, 2023
9.0.0 May 20, 2023
8.1.0 Apr 1, 2023
8.0.0 Feb 19, 2023
0.2.0 May 21, 2019

#796 in Cryptography

Download history 10495/week @ 2024-06-09 10827/week @ 2024-06-16 10127/week @ 2024-06-23 7678/week @ 2024-06-30 7867/week @ 2024-07-07 8306/week @ 2024-07-14 8868/week @ 2024-07-21 11597/week @ 2024-07-28 10951/week @ 2024-08-04 10456/week @ 2024-08-11 11366/week @ 2024-08-18 12375/week @ 2024-08-25 11841/week @ 2024-09-01 10532/week @ 2024-09-08 11375/week @ 2024-09-15 13305/week @ 2024-09-22

48,427 downloads per month
Used in 77 crates (7 directly)

Apache-2.0

32KB
609 lines

ssri

ssri, 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 ssri::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 ssri::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 ssri::{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.

Install

Using cargo-edit

$ cargo add ssri

Documentation

Features

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

Contributing

The ssri team enthusiastically welcomes contributions and project participation! There's a bunch of things you can do if you want to contribute! The Contributor Guide has all the information you need for everything from reporting bugs to contributing entire new features. Please don't hesitate to jump in if you'd like to, or even ask us questions if something isn't clear.

All participants and maintainers in this project are expected to follow Code of Conduct, and just generally be excellent to each other.

Happy hacking!

License

This project is licensed under the Apache-2.0 License.

Dependencies

~2.4–3.5MB
~64K SLoC