change return type of createIntegrityMetadata() to Promise<IntegrityMetadata>

This commit is contained in:
Nebel 2024-09-09 18:58:08 +09:00
parent bd29bf4dc1
commit 9952afecc2
Signed by: nebel
GPG key ID: 79807D08C6EF6460

View file

@ -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 */