Skip to content

Commit

Permalink
🤖 🎨 Autoformat
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanovSPvirtru authored and github-actions[bot] committed Nov 20, 2023
1 parent a10b559 commit f3c4784
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
10 changes: 5 additions & 5 deletions lib/tdf3/src/crypto/decrypt-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface WorkersQueue {
freeWorkers: Worker[];
resolvers: ((worker: Worker) => void)[];
push: (worker: Worker) => void;
pop: () => Promise<Worker>,
pop: () => Promise<Worker>;
}

const workersQueue: WorkersQueue = {
Expand All @@ -54,8 +54,8 @@ const workersQueue: WorkersQueue = {
this.resolvers.push(resolve);
}
});
}
}
},
};

export async function decrypt(data: DecryptData): Promise<ArrayBuffer> {
const worker: Worker = await workersQueue.pop();
Expand All @@ -64,12 +64,12 @@ export async function decrypt(data: DecryptData): Promise<ArrayBuffer> {
const { success, data, error } = event.data;
workersQueue.push(worker);
if (success) {
resolve((data as ArrayBuffer));
resolve(data as ArrayBuffer);
} else {
reject(new TdfDecryptError(error));
}
};

worker.postMessage(data);
});
};
}
12 changes: 7 additions & 5 deletions lib/tdf3/src/crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,13 @@ async function _doDecrypt(
algoDomString.iv = iv.asArrayBuffer();

try {
const decrypted = (
navigator?.hardwareConcurrency
? await workerDecrypt({ key: importedKey, encryptedPayload: payloadBuffer, algo: algoDomString })
: await crypto.subtle.decrypt(algoDomString, importedKey, payloadBuffer)
)
const decrypted = navigator?.hardwareConcurrency
? await workerDecrypt({
key: importedKey,
encryptedPayload: payloadBuffer,
algo: algoDomString,
})
: await crypto.subtle.decrypt(algoDomString, importedKey, payloadBuffer);

return { payload: Binary.fromArrayBuffer(decrypted) };
} catch (err) {
Expand Down
34 changes: 16 additions & 18 deletions lib/tdf3/src/tdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,25 +996,23 @@ export async function sliceAndDecrypt({
);

promises.push(
limit(
() => (
decryptChunk(
encryptedChunk,
reconstructedKeyBinary,
slice[index]['hash'],
cipher,
segmentIntegrityAlgorithm,
cryptoService
).then((decryptedChunk) => {
if (!decryptedChunk) return;
slice[index].decryptedChunk = decryptedChunk;
if (slice[index]._resolve) {
(slice[index]._resolve as (value: unknown) => void)(null);
}
})
)
limit(() =>
decryptChunk(
encryptedChunk,
reconstructedKeyBinary,
slice[index]['hash'],
cipher,
segmentIntegrityAlgorithm,
cryptoService
).then((decryptedChunk) => {
if (!decryptedChunk) return;
slice[index].decryptedChunk = decryptedChunk;
if (slice[index]._resolve) {
(slice[index]._resolve as (value: unknown) => void)(null);
}
})
)
)
);
}
await Promise.all(promises);
}
Expand Down

0 comments on commit f3c4784

Please sign in to comment.