Crates.io | ssri2 |
lib.rs | ssri2 |
version | 0.1.0 |
source | src |
created_at | 2024-02-17 07:55:19.811267 |
updated_at | 2024-02-17 07:55:19.811267 |
description | Various utilities for handling Subresource Integrity. |
homepage | https://github.com/cijiugechu/ssri2 |
repository | https://github.com/cijiugechu/ssri2 |
max_upload_size | |
id | 1143060 |
size | 35,927 |
ssri2
, short for Standard Subresource
Integrity, is a Rust library for parsing, manipulating, serializing,
generating, and verifying Subresource Integrity
hashes.
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.
This project is licensed under the Apache-2.0 License.