15 lines
680 B
Markdown
15 lines
680 B
Markdown
|
# [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
|
||
|
```
|