Fix CDS fetches; use proper hashing mechanism

This commit is contained in:
Scott Nonnenberg 2021-04-07 14:27:40 -07:00 committed by GitHub
parent e4db9358cf
commit a1c534ec0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 7 deletions

View file

@ -14,9 +14,14 @@ export function sign(key: ArrayBuffer, data: ArrayBuffer): ArrayBuffer {
);
}
export function hash(data: ArrayBuffer): ArrayBuffer {
export enum HashType {
size256 = 'sha256',
size512 = 'sha512',
}
export function hash(type: HashType, data: ArrayBuffer): ArrayBuffer {
return toArrayBuffer(
crypto.createHash('sha512').update(Buffer.from(data)).digest()
crypto.createHash(type).update(Buffer.from(data)).digest()
);
}