subresource-integrity/README.md

15 lines
680 B
Markdown
Raw Normal View History

2024-10-06 06:15:17 +00:00
# [Subresource Integrity](https://www.w3.org/TR/SRI/)
This library accepts an integrity attribute value which can be used to verify the integrity of a fetched resource.
## Supported Algorithms
Only the algorithms [required in the specification](https://www.w3.org/TR/SRI/#cryptographic-hash-functions) are supported. Those algorithms are SHA-256, SHA-384, and SHA-512. These hashing algorithms are provided by the [sha2](https://docs.rs/sha2/) crate.
# Usage
```rust
let value = "sha384-H8BRh8j48O9oYatfu5AZzq6A9RINhZO5H16dQZngK7T62em8MUt1FLm52t+eX6xO";
let integrity = Integrity::try_from(integrity_value).unwrap();
integrity.verify("alert(\'Hello, world.\');"); // true
```