Skip to content

Commit 3d0f7aa

Browse files
author
michael kappes
committed
refactored Algorithm to use an enum
1 parent 78862e9 commit 3d0f7aa

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/algorithm.const.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export class Algorithm {
2-
public static readonly AES128CBC = "aes-128-cbc";
3-
public static readonly AES256CBC = "aes-256-cbc";
1+
export enum Algorithm {
2+
AES128CBC = "aes-128-cbc",
3+
AES256CBC = "aes-256-cbc"
44
}

lib/generate-key.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Algorithm} from "./algorithm.const";
22
import {generateRandom} from "./random.function";
33

4-
export const getKeyLength = (algorithm: string): { keyLength: number } => {
4+
export const getKeyLength = (algorithm: Algorithm): { keyLength: number } => {
55
switch (algorithm) {
66
case Algorithm.AES128CBC:
77
return ({
@@ -15,7 +15,7 @@ export const getKeyLength = (algorithm: string): { keyLength: number } => {
1515
throw new Error("Not (yet) supported algorithm: " + algorithm);
1616
};
1717

18-
export const generateKey = async (algorithm: string): Promise<string> => {
18+
export const generateKey = async (algorithm: Algorithm): Promise<string> => {
1919
const keyLength = getKeyLength(algorithm);
2020

2121
const randomKey = await generateRandom({byteLength: keyLength.keyLength});

0 commit comments

Comments
 (0)