https://github.com/moreati/subresource-integrity
A Python package to create and parse Subresource Integrity values.
https://github.com/moreati/subresource-integrity
Last synced: 6 months ago
JSON representation
A Python package to create and parse Subresource Integrity values.
- Host: GitHub
- URL: https://github.com/moreati/subresource-integrity
- Owner: moreati
- License: bsd-2-clause
- Created: 2015-10-19T15:52:18.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2019-06-01T00:18:43.000Z (over 6 years ago)
- Last Synced: 2025-04-05T00:35:23.316Z (6 months ago)
- Language: Python
- Homepage: https://pypi.org/project/subresource-integrity/
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: HISTORY.rst
- License: LICENSE
Awesome Lists containing this project
README
=====================
subresource-integrity
=====================A Python package to create and parse `Subresource Integrity`_ values.
Installation
============.. code:: shell
pip install subresource-integrity
Usage
=====Render an integrity value, given the content
.. code:: python
>>> import subresource_integrity as integrity
>>> data = b"alert('Hello, world.');"
>>> integrity.render(data)
'sha384-H8BRh8j48O9oYatfu5AZzq6A9RINhZO5H16dQZngK7T62em8MUt1FLm52t+eX6xO'Render multiple integrity values for the same content
.. code:: python
>>> hashes = list(integrity.generate(data, ['sha384', 'sha256']))
>>> [str(h) for h in hashes] # doctest: +NORMALIZE_WHITESPACE
['sha384-H8BRh8j48O9oYatfu5AZzq6A9RINhZO5H16dQZngK7T62em8MUt1FLm52t+eX6xO',
'sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=']Parse several space-delimited integrity values, and iterate of them
.. code:: python
>>> parsed = integrity.parse(' sha256-47DEQpj8HBSa+/TImW+5JCeu'
... 'QeRkm5NMpJWZG3hSuFU= ')
>>> parsed # doctest: +ELLIPSIS
[subresource_integrity.Hash('sha256', '47DEQp...SuFU=', '')]
>>> [str(h) for h in parsed]
['sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='].. _subresource integrity: https://en.wikipedia.org/wiki/Subresource_Integrity