From 6f1d1423fe341d5133471e1ac2a9fe5e9c7f8acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Sat, 17 Jun 2023 14:29:24 +0100 Subject: [PATCH] refactor: move QMCv2KeyCrypto constructor to shared utility method --- src/decrypt-worker/crypto/qmc/qmc_v2.ts | 3 ++- src/decrypt-worker/util/qmc2KeyCrypto.ts | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 src/decrypt-worker/util/qmc2KeyCrypto.ts diff --git a/src/decrypt-worker/crypto/qmc/qmc_v2.ts b/src/decrypt-worker/crypto/qmc/qmc_v2.ts index c39234a..6996802 100644 --- a/src/decrypt-worker/crypto/qmc/qmc_v2.ts +++ b/src/decrypt-worker/crypto/qmc/qmc_v2.ts @@ -4,6 +4,7 @@ import type { DecryptCommandOptions } from '~/decrypt-worker/types.ts'; import { SEED, ENC_V2_KEY_1, ENC_V2_KEY_2 } from './qmc_v2.key.ts'; import { fetchParakeet } from '@jixun/libparakeet'; import { stringToUTF8Bytes } from '~/decrypt-worker/util/utf8Encoder.ts'; +import { makeQMCv2KeyCrypto } from '~/decrypt-worker/util/qmc2KeyCrypto.ts'; export class QMC2Crypto implements CryptoBase { cryptoName = 'QMC/v2'; @@ -38,7 +39,7 @@ export class QMC2CryptoWithKey implements CryptoBase { const parakeet = await fetchParakeet(); const key = stringToUTF8Bytes(options.qmc2Key); - const keyCrypto = parakeet.make.QMCv2KeyCrypto(SEED, ENC_V2_KEY_1, ENC_V2_KEY_2); + const keyCrypto = makeQMCv2KeyCrypto(parakeet); return transformBlob(buffer, (p) => p.make.QMCv2EKey(key, keyCrypto), { parakeet, cleanup: () => keyCrypto.delete(), diff --git a/src/decrypt-worker/util/qmc2KeyCrypto.ts b/src/decrypt-worker/util/qmc2KeyCrypto.ts new file mode 100644 index 0000000..7f534ee --- /dev/null +++ b/src/decrypt-worker/util/qmc2KeyCrypto.ts @@ -0,0 +1,4 @@ +import type { Parakeet } from '@jixun/libparakeet'; +import { SEED, ENC_V2_KEY_1, ENC_V2_KEY_2 } from '../crypto/qmc/qmc_v2.key'; + +export const makeQMCv2KeyCrypto = (p: Parakeet) => p.make.QMCv2KeyCrypto(SEED, ENC_V2_KEY_1, ENC_V2_KEY_2);