@@ -23,6 +23,7 @@ Integrity](https://w3c.github.io/webappsec/specs/subresourceintegrity/) hashes.
2323 * [ ` Integrity#pickAlgorithm ` ] ( #integrity-pick-algorithm )
2424 * [ ` IntegrityMetadata#hexDigest ` ] ( #integrity-metadata-hex-digest )
2525 * Integrity Generation
26+ * [ ` fromHex ` ] ( #from-hex )
2627 * [ ` fromData ` ] ( #from-data )
2728 * [ ` fromStream ` ] ( #from-stream )
2829 * Integrity Verification
@@ -227,6 +228,33 @@ to a hex representation of the base64 data.
227228ssri .parse (' sha1-deadbeef' , {single: true }).hexDigest () // '75e69d6de79f'
228229```
229230
231+ #### <a name =" from-hex " ></a > ` > ssri.fromHex(hexDigest, algorithm, [opts]) -> Integrity `
232+
233+ Creates an ` Integrity ` object with a single entry, based on a hex-formatted
234+ hash. This is a utility function to help convert existing shasums to the
235+ Integrity format, and is roughly equivalent to something like:
236+
237+ ``` javascript
238+ algorithm + ' -' + Buffer .from (hexDigest, ' hex' ).toString (' base64' )
239+ ```
240+
241+ ` opts.options ` may optionally be passed in: it must be an array of option
242+ strings that will be added to all generated integrity metadata generated by
243+ ` fromData ` . This is a loosely-specified feature of SRIs, and currently has no
244+ specified semantics besides being ` ? ` -separated. Use at your own risk, and
245+ probably avoid if your integrity strings are meant to be used with browsers.
246+
247+ If ` opts.strict ` is true, the integrity object will be created using strict
248+ parsing rules. See [ ` ssri.parse ` ] ( #parse ) .
249+
250+ If ` opts.single ` is true, a single ` IntegrityMetadata ` object will be returned.
251+
252+ ##### Example
253+
254+ ``` javascript
255+ ssri .fromHex (' 75e69d6de79f' , ' sha1' ).toString () // 'sha1-deadbeef'
256+ ```
257+
230258#### <a name =" from-data " ></a > ` > ssri.fromData(data, [opts]) -> Integrity `
231259
232260Creates an ` Integrity ` object from either string or ` Buffer ` data, calculating
0 commit comments