Skip to content

Commit

Permalink
Make ICipher.decrypt async
Browse files Browse the repository at this point in the history
In preparation for using SubtleCrypto.decrypt, which returns a promise.

Resolves #1293.
  • Loading branch information
lawrence-forooghian committed May 31, 2023
1 parent ea0ed4b commit b5d5a5d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/common/lib/types/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class Message {
if (xformAlgorithm != cipher.algorithm) {
throw new Error('Unable to decrypt message with given cipher; incompatible cipher params');
}
data = cipher.decrypt(data);
data = await cipher.decrypt(data);
continue;
} else {
throw new Error('Unable to decrypt message; not an encrypted channel');
Expand Down
2 changes: 1 addition & 1 deletion src/common/types/ICipher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default interface ICipher<InputPlaintext, OutputCiphertext, InputCiphertext, OutputPlaintext> {
algorithm: string;
encrypt: (plaintext: InputPlaintext, callback: (error: Error | null, data: OutputCiphertext | null) => void) => void;
decrypt: (ciphertext: InputCiphertext) => OutputPlaintext;
decrypt: (ciphertext: InputCiphertext) => Promise<OutputPlaintext>;
}
2 changes: 1 addition & 1 deletion src/platform/nodejs/lib/util/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ var CryptoFactory = function (bufferUtils: typeof BufferUtils) {
return callback(null, ciphertext);
}

decrypt(ciphertext: InputCiphertext) {
async decrypt(ciphertext: InputCiphertext): Promise<OutputPlaintext> {
var blockLength = this.blockLength,
decryptCipher = crypto.createDecipheriv(this.algorithm, this.key, ciphertext.slice(0, blockLength)),
plaintext = toBuffer(decryptCipher.update(ciphertext.slice(blockLength))),
Expand Down
2 changes: 1 addition & 1 deletion src/platform/web/lib/util/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ var CryptoFactory = function (config: IPlatformConfig, bufferUtils: typeof Buffe
}
}

decrypt(ciphertext: InputCiphertext) {
async decrypt(ciphertext: InputCiphertext): Promise<OutputPlaintext> {
Logger.logAction(Logger.LOG_MICRO, 'CBCCipher.decrypt()', '');
ciphertext = bufferUtils.toWordArray(ciphertext);
var blockLengthWords = this.blockLengthWords,
Expand Down

0 comments on commit b5d5a5d

Please sign in to comment.