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 25664ca
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 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, f
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 @@ -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
}
Expand Down

0 comments on commit 25664ca

Please sign in to comment.