Skip to content

Commit 08d7b37

Browse files
authored
Merge pull request #21 from nut-tree/feature/13/deprecation_warnings
Feature/13/deprecation warnings
2 parents b985782 + 12152ad commit 08d7b37

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

lib/decrypt.function.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe("secret", () => {
99
const expected = "Can you keep a secret?";
1010

1111
// THEN
12-
expect(decrypt(input, key, Algorithm.AES128CBC)).resolves.toBe(expected);
12+
await expect(decrypt(input, key, Algorithm.AES128CBC)).resolves.toBe(expected);
1313
});
1414

1515
it("should throw an error when IV size is invalid", async () => {
@@ -18,7 +18,7 @@ describe("secret", () => {
1818
const input = "Zm9vCg==";
1919

2020
// THEN
21-
expect(decrypt(input, key, Algorithm.AES128CBC))
21+
await expect(decrypt(input, key, Algorithm.AES128CBC))
2222
.rejects.toThrowError("Invalid IV size. Size of 16 byte required.");
2323
});
2424
});

lib/decrypt.function.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as crypto from "crypto";
1+
import {createDecipher, createDecipheriv, Decipher} from "crypto";
22
import {Algorithm} from "./algorithm.enum";
33
import {base64EncodedBufferFromString} from "./buffer.function";
44
import {CipherSpec, getCipherSpec} from "./get-cipher-spec.function";
@@ -27,19 +27,19 @@ export const decrypt = async (encrypted: string, secret: string, algorithm: Algo
2727
throw new Error(`Invalid IV size. Size of ${cipherSpec.blockSize} byte required.`);
2828
}
2929

30-
let decipher: crypto.Decipher;
30+
let decipher: Decipher;
3131
let data: DecryptInput;
3232
if (useIV) {
3333
data = sliceInput(plainInput, cipherSpec);
3434

35-
decipher = crypto.createDecipheriv(
35+
decipher = createDecipheriv(
3636
algorithm,
3737
key,
3838
data.iv
3939
);
4040
} else {
4141
data = {iv: Buffer.alloc(0), content: plainInput};
42-
decipher = crypto.createDecipher(
42+
decipher = createDecipher(
4343
algorithm,
4444
key
4545
);

lib/encrypt.function.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as crypto from "crypto";
1+
import {createCipher, createCipheriv} from "crypto";
22
import {Algorithm} from "./algorithm.enum";
33
import {base64EncodedBufferFromString} from "./buffer.function";
44
import {getCipherSpec} from "./get-cipher-spec.function";
@@ -16,11 +16,11 @@ export const encrypt = async (
1616
const iv = await generateRandom({
1717
byteLength: cipherSpec.blockSize,
1818
});
19-
const cipher = crypto.createCipheriv(algorithm, key, iv);
19+
const cipher = createCipheriv(algorithm, key, iv);
2020
const part = cipher.update(plainText);
2121
return Buffer.concat([iv, part, cipher.final()]).toString("base64");
2222
} else {
23-
const cipher = crypto.createCipher(algorithm, key);
23+
const cipher = createCipher(algorithm, key);
2424
const part = cipher.update(plainText);
2525
return Buffer.concat([part, cipher.final()]).toString("base64");
2626
}

lib/random.function.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import * as crypto from "crypto";
1+
import {randomBytes} from "crypto";
22

33
export const generateRandom = (params: { byteLength: number } = {
44
byteLength: 16,
55
}): Promise<Buffer> => {
66
return new Promise((resolve, reject) => {
7-
crypto.randomBytes(params.byteLength, (err, buffer) => {
7+
randomBytes(params.byteLength, (err, buffer) => {
88
if (err) {
99
reject(err);
1010
} else {

0 commit comments

Comments
 (0)