mirror of
https://github.com/kou029w/websri.git
synced 2025-01-18 08:05:13 +00:00
change return type of createIntegrityMetadata()
to Promise<IntegrityMetadata>
This commit is contained in:
parent
bd29bf4dc1
commit
9952afecc2
1 changed files with 6 additions and 7 deletions
13
src/index.ts
13
src/index.ts
|
@ -81,20 +81,19 @@ export async function createIntegrityMetadata(
|
|||
hashAlgorithm: HashAlgorithm,
|
||||
data: ArrayBuffer,
|
||||
opt: string[] = [],
|
||||
): Promise<string> {
|
||||
): Promise<IntegrityMetadata> {
|
||||
const alg = hashAlgorithm.toLowerCase() as HashAlgorithm;
|
||||
|
||||
if (!(alg in supportedHashAlgorithms)) return "";
|
||||
if (!(alg in supportedHashAlgorithms)) {
|
||||
return new IntegrityMetadata("");
|
||||
}
|
||||
|
||||
const hashAlgorithmIdentifier = supportedHashAlgorithms[alg];
|
||||
const arrayBuffer = await crypto.subtle.digest(hashAlgorithmIdentifier, data);
|
||||
const val = btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
|
||||
const integrity = IntegrityMetadata.stringify({ alg, val, opt });
|
||||
|
||||
return IntegrityMetadata.stringify({
|
||||
alg,
|
||||
val,
|
||||
opt,
|
||||
});
|
||||
return new IntegrityMetadata(integrity);
|
||||
}
|
||||
|
||||
/** Integrity Metadata Set Options */
|
||||
|
|
Loading…
Add table
Reference in a new issue