* Checks if `sha384(script)` exists in `meta[name="amp-script-src"]` element * in document head. * * @param {string} script The script contents. * @param {string} debugId An element identifier for error messages. * @return {!Promise}
(script, debugId)
| 622 | * @return {!Promise} |
| 623 | */ |
| 624 | checkSha384(script, debugId) { |
| 625 | const bytes = utf8Encode(script); |
| 626 | return this.crypto_.sha384Base64(bytes).then((hash) => { |
| 627 | if (!hash || !this.sources_.includes('sha384-' + hash)) { |
| 628 | // TODO(#24266): Refactor to %s interpolation when error string |
| 629 | // extraction is ready. |
| 630 | throw user().createError( |
| 631 | TAG, |
| 632 | `Script hash not found or incorrect for ${debugId}. You must include <meta name="amp-script-src" content="sha384-${hash}">. ` + |
| 633 | `During development, you can disable this check by adding the "data-ampdevmode" attribute to ${debugId}, or the root html node` + |
| 634 | 'See https://amp.dev/documentation/components/amp-script/#script-hash.' |
| 635 | ); |
| 636 | } |
| 637 | }); |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * Adds `size` to current total. Returns true if new total is <= size cap. |
no test coverage detected