SubResource Integrity(SRI) library and CLI tools¶
SubResource Integrity(SRI) Tool¶
Calculates the digest of a file and generates an SRI string
usage: SubResource Integrity(SRI) Tool [-h] [--url-safe]
{generate,verify,decode} ...
-
-h
,
--help
¶
show this help message and exit
-
--url-safe
¶
Assume a URL safe base64 encoded SRI: decodes to an SRI of format sha256-myhash
SubResource Integrity(SRI) Tool decode¶
usage: SubResource Integrity(SRI) Tool decode [-h] sri
-
sri
¶
-
-h
,
--help
¶
show this help message and exit
SubResource Integrity(SRI) Tool generate¶
usage: SubResource Integrity(SRI) Tool generate [-h]
[--dgst {sha1,sha224,blake2s,sha512,shake_128,sha3_384,sha256,sha384,md5,sha3_512,blake2b,sha3_256,sha3_224,shake_256}]
file
-
file
¶
-
-h
,
--help
¶
show this help message and exit
-
--dgst
{sha1,sha224,blake2s,sha512,shake_128,sha3_384,sha256,sha384,md5,sha3_512,blake2b,sha3_256,sha3_224,shake_256}
¶ digest algorithm see: openssl dgst
SRI python Library¶
import piperci.sri as sritool
-
piperci.sri.
b64_hash
(bhash)¶ Converts a raw binary hash object to b64encoded hash for manual sri generation. :param bhash: raw binary hash object to b64encode :return: base64 encoded string of bhash
-
piperci.sri.
generate_sri
(path, dgst='sha256', url_safe=False)¶ Generate an SRI from a file path. :param path: string path to the file to generate an SRI. :param sri_dgst: string digest hash method ex: sha256, md5, sha512 :param url_safe: boolean flag to encode as a urlsafe base64 string :return string SRI hash or urlsafe SRI hash
-
piperci.sri.
hash_file
(sri_dgst, path)¶ Generate a digest hash from file path. :param sri_dgst: string digest hash method ex: sha256, md5, sha512 :param path: string path to the file to generate an SRI.
-
piperci.sri.
hash_to_sri_hash
(sri_dgst, sri_bytest_value)¶ Coverts a b64 encoded binary digest and value to integrity.Hash boject :param sri_dgst: The digest hash method ex: sha256, md5, sha512 :param sri_bytest_value: The SRI bytes hash value. :return: integrity.Hash object
-
piperci.sri.
hash_to_urlsafeb64
(hash)¶ Convert an integrity.Hash object to urlsafe encoded sri hash. :param integrity.Hash: An integrity.Hash object :return: string urlsafe encoded SRI
-
piperci.sri.
sri_to_hash
(sri)¶ Convert an SRI encoded string to integrity.Hash. :param sri: A string sri like digest-hash_value :return: integrity.Hash object
-
piperci.sri.
urlsafe_to_hash
(url_safe_b64)¶ Convert a urlsafe_b64encode’d string to and integrity.Hash object. :param url_safe_b64: A urlsafe_b64encoded bytes or string object :return: integrity.Hash object