sri_hash
Version, currently 0.1.02 versions
- 0.2.0latestMar 24, 2021
- 0.1.0not indexedMar 24, 2021
github.com/anamba/sri_hash.cr
Generates SRI hash or complete script tag for a resource
Nothing has been indexed for 0.1.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
sri_hash:
github: anamba/sri_hash.cr
version: ~> 0.1.0Then run:
shards installshard.yml
No shard.yml has been indexed for 0.1.0. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
sri_hash.cr - Generates SRI hash or complete script tag for a resource
Subresource integrity helper for Crystal. More info on SRI: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
Installation
-
Add the dependency to your
shard.yml:dependencies: sri_hash: github: anamba/sri_hash.cr -
Run
shards install
Usage
require "sri_hash"
SRIHash.from_string("Example text") # -> "sha256-ljgfRyA+rQLdERYr90sJ9dRLkTYUnUIAHmR1dX6cvmQ="
# downloads file using http-client, then computes hash
# NOTE: adds defer by default (pass defer: false to override)
SRIHash.script_tag("https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.slim.min.js") # -> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.slim.min.js" integrity="sha256-ZaXnYkHGqIhqTbJ6MB4l9Frs/r7U4jlx7ir8PJYBqbI=" crossorigin="anonymous" defer></script>
Algorithm defaults to sha256 (like cdnjs), but can be changed, either on individual calls or globally:
SRIHash.from_string("Example text", "sha384") # -> "sha384-ccLtG4S0txUiu3s0kEOUSiKfr3poGC+i1midiPHzO/aDkeHwlXnP4ozRKWqOREqn"
SRIHash.settings.algorithm = "sha384"
SRIHash.from_string("Example text") # -> "sha384-ccLtG4S0txUiu3s0kEOUSiKfr3poGC+i1midiPHzO/aDkeHwlXnP4ozRKWqOREqn"
Contributing
- Fork it (https://github.com/anamba/sri_hash.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Aaron Namba - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.0- Tagged
- Mar 24, 2021
- Commit
d95b37b12e7d- Indexed
- not yet
Dependents
No indexed shard depends on this one yet.
Repository
github.com/anamba/sri_hash.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 12, 2026
- Synced
- Aug 12, 2026
- Versions
- 2