MCPcopy Create free account
hub / github.com/angular/dev-infra / bytesMatch

Function bytesMatch

github-actions/saucelabs/set-saucelabs-env.js:4501–4530  ·  view source on GitHub ↗
(bytes, metadataList)

Source from the content-addressed store, hash-verified

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 = [];

Callers 1

processBodyFunction · 0.70

Calls 6

updateMethod · 0.80
parseMetadataFunction · 0.70
getStrongestMetadataFunction · 0.70
compareBase64MixedFunction · 0.70
sliceMethod · 0.45

Tested by

no test coverage detected