Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for (const headerName of Object.keys(headers)) {
if (headerName.toLowerCase() === SHA256_HEADER) {
return headers[headerName];
}
}
if (body == undefined) {
return "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
} else if (
typeof body === "string" ||
ArrayBuffer.isView(body) ||
isArrayBuffer(body)
) {
const hashCtor = new hashConstructor();
hashCtor.update(body);
return toHex(await hashCtor.digest());
}
// As any defined body that is not a string or binary data is a stream, this
// body is unsignable. Attempt to send the request with an unsigned payload,
// which may or may not be accepted by the service.
return UNSIGNED_PAYLOAD;
}
it(`should calculate a MD5 hash of ${expected} for test vector ${++idx}`, async () => {
const hash = new Md5();
hash.update(fromBase64(input));
expect(toHex(await hash.digest())).toBe(expected);
});
}
it("calculates the SHA256 hash of a stream", async () => {
const result = await calculateSha256(
Sha256,
createReadStream(temporaryFile)
);
expect(result instanceof Uint8Array).toBe(true);
expect(toHex(result)).toBe(
"24dabf4db3774a3224d571d4c089a9c570c3045dbe1e67ee9ee2e2677f57dbe0"
);
});
it("computes tree hashes of string bodies", async () => {
const treeHash = new TreeHash(Sha256, fromUtf8);
treeHash.update("bar");
const results = await treeHash.digest();
expect(toHex(results)).toEqual(
"fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9"
);
});
it("calculates the SHA256 hash of a blob", async () => {
const result = await calculateSha256(Sha256, blob);
expect(result instanceof Uint8Array).toBe(true);
expect(toHex(result)).toBe(
"24dabf4db3774a3224d571d4c089a9c570c3045dbe1e67ee9ee2e2677f57dbe0"
);
});
});
valueOf(): number {
const bytes = this.bytes.slice(0);
const negative = bytes[0] & 0b10000000;
if (negative) {
negate(bytes);
}
return parseInt(toHex(bytes), 16) * (negative ? -1 : 1);
}
)
};
position += 8;
break;
case HEADER_VALUE_TYPE.uuid:
const uuidBytes = new Uint8Array(
headers.buffer,
headers.byteOffset + position,
16
);
position += 16;
out[name] = {
type: UUID_TAG,
value: `${toHex(uuidBytes.subarray(0, 4))}-${toHex(
uuidBytes.subarray(4, 6)
)}-${toHex(uuidBytes.subarray(6, 8))}-${toHex(
uuidBytes.subarray(8, 10)
)}-${toHex(uuidBytes.subarray(10))}`
};
break;
default:
throw new Error(`Unrecognized header type tag`);
}
}
return out;
}
}