mirror of
https://github.com/kou029w/websri.git
synced 2025-01-18 16:08:16 +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,
|
hashAlgorithm: HashAlgorithm,
|
||||||
data: ArrayBuffer,
|
data: ArrayBuffer,
|
||||||
opt: string[] = [],
|
opt: string[] = [],
|
||||||
): Promise<string> {
|
): Promise<IntegrityMetadata> {
|
||||||
const alg = hashAlgorithm.toLowerCase() as HashAlgorithm;
|
const alg = hashAlgorithm.toLowerCase() as HashAlgorithm;
|
||||||
|
|
||||||
if (!(alg in supportedHashAlgorithms)) return "";
|
if (!(alg in supportedHashAlgorithms)) {
|
||||||
|
return new IntegrityMetadata("");
|
||||||
|
}
|
||||||
|
|
||||||
const hashAlgorithmIdentifier = supportedHashAlgorithms[alg];
|
const hashAlgorithmIdentifier = supportedHashAlgorithms[alg];
|
||||||
const arrayBuffer = await crypto.subtle.digest(hashAlgorithmIdentifier, data);
|
const arrayBuffer = await crypto.subtle.digest(hashAlgorithmIdentifier, data);
|
||||||
const val = btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
|
const val = btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
|
||||||
|
const integrity = IntegrityMetadata.stringify({ alg, val, opt });
|
||||||
|
|
||||||
return IntegrityMetadata.stringify({
|
return new IntegrityMetadata(integrity);
|
||||||
alg,
|
|
||||||
val,
|
|
||||||
opt,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Integrity Metadata Set Options */
|
/** Integrity Metadata Set Options */
|
||||||
|
|
Loading…
Add table
Reference in a new issue