From 25664ca8ddb1e511e7f076f44d8f5248765b32d7 Mon Sep 17 00:00:00 2001 From: Thibaud Genty Date: Tue, 19 Sep 2023 11:29:14 +0200 Subject: [PATCH] test add param --- src/kms/kms.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/kms/kms.ts b/src/kms/kms.ts index 09f0912c..93999c6b 100644 --- a/src/kms/kms.ts +++ b/src/kms/kms.ts @@ -703,7 +703,7 @@ export class KmsClient { headerMetadata?: Uint8Array authenticationData?: Uint8Array } = {}, - ): Promise { + ): Promise { const accessPolicyBytes = new TextEncoder().encode(accessPolicy) const accessPolicySize = encode(accessPolicyBytes.length) @@ -764,16 +764,15 @@ export class KmsClient { let { result: nbChunks, tail: tailPlaintext } = decode(encryptedData) - let encryptedChunks = Uint8Array.from([]) + const encryptedChunks = [] for (let i = 0; i < nbChunks; i++) { const { result: chunkSize, tail } = decode(tailPlaintext) const chunk = tail.slice(0, chunkSize) tailPlaintext = tail.slice(chunkSize) - encryptedChunks = Uint8Array.from([ - ...encryptedChunks, - ...Uint8Array.from([...chunk]), - ]) + encryptedChunks.push(new Uint8Array([...chunk])) + + console.log(`Enc chunks: ${encryptedChunks.toString()}`) } return encryptedChunks @@ -789,10 +788,14 @@ export class KmsClient { public async coverCryptDecrypt( uniqueIdentifier: string, data: Uint8Array | Uint8Array[], + // cryptographicAlgorithm: CryptographicAlgorithm = CryptographicAlgorithm.CoverCrypt, f options: { authenticationData?: Uint8Array } = {}, - ): Promise<{ headerMetadata: Uint8Array; plaintext: Uint8Array }> { + ): Promise<{ + headerMetadata: Uint8Array + plaintext: Uint8Array | Uint8Array[] + }> { const cryptographicParameters = new CryptographicParameters() if (data instanceof Uint8Array) { @@ -831,16 +834,13 @@ export class KmsClient { CryptographicAlgorithm.CoverCryptBulk ) { let { result: nbChunks, tail: tailPlaintext } = decode(plaintext) - let decryptedChunks = Uint8Array.from([]) + const decryptedChunks = [] for (let i = 0; i < nbChunks; i++) { const { result: chunkSize, tail } = decode(tailPlaintext) const chunk = tail.slice(0, chunkSize) tailPlaintext = tail.slice(chunkSize) - decryptedChunks = Uint8Array.from([ - ...decryptedChunks, - ...Uint8Array.from([...chunk]), - ]) + decryptedChunks.push(new Uint8Array([...chunk])) plaintext = decryptedChunks }