(bytes, metadataList)
| 4499 | } |
| 4500 | } |
| 4501 | function bytesMatch(bytes, metadataList) { |
| 4502 | if (crypto2 === void 0) { |
| 4503 | return true; |
| 4504 | } |
| 4505 | const parsedMetadata = parseMetadata(metadataList); |
| 4506 | if (parsedMetadata === "no metadata") { |
| 4507 | return true; |
| 4508 | } |
| 4509 | if (parsedMetadata.length === 0) { |
| 4510 | return true; |
| 4511 | } |
| 4512 | const strongest = getStrongestMetadata(parsedMetadata); |
| 4513 | const metadata = filterMetadataListByAlgorithm(parsedMetadata, strongest); |
| 4514 | for (const item of metadata) { |
| 4515 | const algorithm = item.algo; |
| 4516 | const expectedValue = item.hash; |
| 4517 | let actualValue = crypto2.createHash(algorithm).update(bytes).digest("base64"); |
| 4518 | if (actualValue[actualValue.length - 1] === "=") { |
| 4519 | if (actualValue[actualValue.length - 2] === "=") { |
| 4520 | actualValue = actualValue.slice(0, -2); |
| 4521 | } else { |
| 4522 | actualValue = actualValue.slice(0, -1); |
| 4523 | } |
| 4524 | } |
| 4525 | if (compareBase64Mixed(actualValue, expectedValue)) { |
| 4526 | return true; |
| 4527 | } |
| 4528 | } |
| 4529 | return false; |
| 4530 | } |
| 4531 | var parseHashWithOptions = new RegExp("(?<algo>sha256|sha384|sha512)-((?<hash>[A-Za-z0-9+/]+|[A-Za-z0-9_-]+)={0,2}(?:\\s|$)( +[!-~]*)?)?", "i"); |
| 4532 | function parseMetadata(metadata) { |
| 4533 | const result = []; |
no test coverage detected