Skip to content

Commit

Permalink
test add param
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibsG committed Sep 19, 2023
1 parent b929aca commit 6f97b1e
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/kms/kms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ export class KmsClient {
headerMetadata?: Uint8Array
authenticationData?: Uint8Array
} = {},
): Promise<Uint8Array> {
): Promise<Uint8Array | Uint8Array[]> {
const accessPolicyBytes = new TextEncoder().encode(accessPolicy)
const accessPolicySize = encode(accessPolicyBytes.length)

Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6f97b1e

Please sign in to comment.