sric-0.1.0 is not a library.
SRIC - Subresource Integrity Generator
A Rust CLI tool that automatically generates Subresource Integrity (SRI) hashes for HTML files. SRIC parses HTML documents, identifies external resources (scripts and stylesheets), fetches them over HTTP, and adds integrity attributes with SHA-384 hashes.
Features
- Generates SHA-384 SRI hashes for external scripts and stylesheets
- Supports in-place modification or output to new files
- MIME type validation for security
- HTTPS upgrade for HTTP URLs
- Content-Type header verification
- 10MB download limit for safety
- Force override of existing SRI hashes
Installation
Usage
# Output to stdout
# Modify file in-place
# Write to specific output file
# Override existing SRI hashes
Examples
# Generate SRI hashes and print to stdout
# Update index.html in-place with SRI hashes
# Save output to a new file
Development
Building and Testing
# Build the project
# Run tests
# Check for compilation errors
# Run linter (if installed)
# Format code (if installed)
Architecture
main.rs- CLI argument parsing and orchestrationparse_html.rs- HTML parsing using html5evergenerate_sri.rs- Core SRI generation logicwrite_html.rs- HTML serializationnode_iter.rs- DOM traversal utilitieselement.rs- Element operationsmime_ext.rs- MIME type validationresponse_ext.rs- HTTP response processing
Dependencies
html5ever+markup5ever_rcdom- HTML parsing and DOM manipulationureq- HTTP client for fetching resourcessha2+base64- Cryptographic hashingclap+clio- CLI interface and file I/Omime+mime_guess- Content type validation
How It Works
- Parse HTML into DOM using html5ever
- Find
<script>tags withsrcand<link>tags withrel="stylesheet|preload|modulepreload" - Fetch external resources via HTTP with MIME type validation
- Generate SHA-384 hash and encode as base64
- Add or update
integrityattribute withsha384-<hash>format - Serialize modified DOM back to HTML
Security
- MIME type validation prevents SRI generation for unexpected content types
- 10MB download limit for safety
- HTTPS upgrade for HTTP URLs
- Content-Type header verification against file extension