Skip to main content

Create and parse HTML subresource integrity values

Project description

A Python package to create and parse Subresource Integrity values.

Installation

pip install subresource-integrity

Usage

Render an integrity value, given the content

>>> import subresource_integrity as integrity
>>> data = b"alert('Hello, world.');"
>>> integrity.render(data)
'sha384-H8BRh8j48O9oYatfu5AZzq6A9RINhZO5H16dQZngK7T62em8MUt1FLm52t+eX6xO'

Render multiple integrity values for the same content

>>> 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

>>> 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=']

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

subresource-integrity-0.2.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

subresource_integrity-0.2-py2.py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page