refactor: move QMCv2KeyCrypto constructor to shared utility method

This commit is contained in:
鲁树人 2023-06-17 14:29:24 +01:00
parent 2881f70f68
commit 6f1d1423fe
2 changed files with 6 additions and 1 deletions

View File

@ -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 { SEED, ENC_V2_KEY_1, ENC_V2_KEY_2 } from './qmc_v2.key.ts';
import { fetchParakeet } from '@jixun/libparakeet'; import { fetchParakeet } from '@jixun/libparakeet';
import { stringToUTF8Bytes } from '~/decrypt-worker/util/utf8Encoder.ts'; import { stringToUTF8Bytes } from '~/decrypt-worker/util/utf8Encoder.ts';
import { makeQMCv2KeyCrypto } from '~/decrypt-worker/util/qmc2KeyCrypto.ts';
export class QMC2Crypto implements CryptoBase { export class QMC2Crypto implements CryptoBase {
cryptoName = 'QMC/v2'; cryptoName = 'QMC/v2';
@ -38,7 +39,7 @@ export class QMC2CryptoWithKey implements CryptoBase {
const parakeet = await fetchParakeet(); const parakeet = await fetchParakeet();
const key = stringToUTF8Bytes(options.qmc2Key); 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), { return transformBlob(buffer, (p) => p.make.QMCv2EKey(key, keyCrypto), {
parakeet, parakeet,
cleanup: () => keyCrypto.delete(), cleanup: () => keyCrypto.delete(),

View File

@ -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);