diff --git a/src/kms/kms.ts b/src/kms/kms.ts index 09f0912c..7e0ab902 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, ff options: { authenticationData?: Uint8Array } = {}, - ): Promise<{ headerMetadata: Uint8Array; plaintext: Uint8Array }> { + ): Promise<{ + headerMetadata: Uint8Array + plaintext: Uint8Array | Uint8Array[] + }> { const cryptographicParameters = new CryptographicParameters() if (data instanceof Uint8Array) { @@ -824,23 +827,20 @@ export class KmsClient { const { result: headerMetadataLength, tail } = decode(response.data) const headerMetadata = tail.slice(0, headerMetadataLength) - let plaintext = tail.slice(headerMetadataLength) + let plaintext: Uint8Array | Uint8Array[] = tail.slice(headerMetadataLength) if ( cryptographicParameters.cryptographicAlgorithm === 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 }