Remove import cycles
This commit is contained in:
parent
94868e606a
commit
8ffd7aa1d4
13
src/crypto/cipher/getCipher.js
Normal file
13
src/crypto/cipher/getCipher.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
import * as cipher from '.';
|
||||
import enums from '../../enums';
|
||||
|
||||
/**
|
||||
* Get implementation of the given cipher
|
||||
* @param {enums.symmetric} algo
|
||||
* @returns {Object}
|
||||
* @throws {Error} on invalid algo
|
||||
*/
|
||||
export default function getCipher(algo) {
|
||||
const algoName = enums.read(enums.symmetric, algo);
|
||||
return cipher[algoName];
|
||||
}
|
|
@ -25,9 +25,9 @@
|
|||
*/
|
||||
|
||||
import publicKey from './public_key';
|
||||
import * as cipher from './cipher';
|
||||
import mode from './mode';
|
||||
import { getRandomBytes } from './random';
|
||||
import getCipher from './cipher/getCipher';
|
||||
import ECDHSymkey from '../type/ecdh_symkey';
|
||||
import KDFParams from '../type/kdf_params';
|
||||
import enums from '../enums';
|
||||
|
@ -385,16 +385,7 @@ export function getAEADMode(algo) {
|
|||
return mode[algoName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get implementation of the given cipher
|
||||
* @param {enums.symmetric} algo
|
||||
* @returns {Object}
|
||||
* @throws {Error} on invalid algo
|
||||
*/
|
||||
export function getCipher(algo) {
|
||||
const algoName = enums.read(enums.symmetric, algo);
|
||||
return cipher[algoName];
|
||||
}
|
||||
export { getCipher };
|
||||
|
||||
/**
|
||||
* Check whether the given curve OID is supported
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
|
||||
import { AES_CFB } from '@openpgp/asmcrypto.js/dist_es8/aes/cfb';
|
||||
import * as stream from '@openpgp/web-stream-tools';
|
||||
import { getCipher } from '../crypto';
|
||||
import * as cipher from '../cipher';
|
||||
import getCipher from '../cipher/getCipher';
|
||||
import util from '../../util';
|
||||
import enums from '../../enums';
|
||||
|
||||
|
@ -62,7 +61,8 @@ export async function encrypt(algo, key, plaintext, iv, config) {
|
|||
return aesEncrypt(algo, key, plaintext, iv, config);
|
||||
}
|
||||
|
||||
const cipherfn = new cipher[algoName](key);
|
||||
const Cipher = getCipher(algo);
|
||||
const cipherfn = new Cipher(key);
|
||||
const block_size = cipherfn.blockSize;
|
||||
|
||||
const blockc = iv.slice();
|
||||
|
@ -104,7 +104,8 @@ export async function decrypt(algo, key, ciphertext, iv) {
|
|||
return aesDecrypt(algo, key, ciphertext, iv);
|
||||
}
|
||||
|
||||
const cipherfn = new cipher[algoName](key);
|
||||
const Cipher = getCipher(algo);
|
||||
const cipherfn = new Cipher(key);
|
||||
const block_size = cipherfn.blockSize;
|
||||
|
||||
let blockp = iv;
|
||||
|
|
|
@ -31,7 +31,7 @@ import util from '../../../util';
|
|||
import { b64ToUint8Array } from '../../../encoding/base64';
|
||||
import * as pkcs5 from '../../pkcs5';
|
||||
import { keyFromPublic, keyFromPrivate, getIndutnyCurve } from './indutnyKey';
|
||||
import { getCipher } from '../../crypto';
|
||||
import getCipher from '../../cipher/getCipher';
|
||||
|
||||
const webCrypto = util.getWebCrypto();
|
||||
const nodeCrypto = util.getNodeCrypto();
|
||||
|
|
|
@ -26,7 +26,7 @@ import {
|
|||
UserAttributePacket
|
||||
} from '../packet';
|
||||
import PrivateKey from './private_key';
|
||||
import { createKey } from './key';
|
||||
import PublicKey from './public_key';
|
||||
import * as helper from './helper';
|
||||
import enums from '../enums';
|
||||
import util from '../util';
|
||||
|
@ -44,6 +44,25 @@ const allowedKeyPackets = /*#__PURE__*/ util.constructAllowedPackets([
|
|||
SignaturePacket
|
||||
]);
|
||||
|
||||
/**
|
||||
* Creates a PublicKey or PrivateKey depending on the packetlist in input
|
||||
* @param {PacketList} - packets to parse
|
||||
* @return {Key} parsed key
|
||||
* @throws if no key packet was found
|
||||
*/
|
||||
function createKey(packetlist) {
|
||||
for (const packet of packetlist) {
|
||||
switch (packet.constructor.tag) {
|
||||
case enums.packet.secretKey:
|
||||
return new PrivateKey(packetlist);
|
||||
case enums.packet.publicKey:
|
||||
return new PublicKey(packetlist);
|
||||
}
|
||||
}
|
||||
throw new Error('No key packet found');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates a new OpenPGP key. Supports RSA and ECC keys.
|
||||
* By default, primary and subkeys will be of same type.
|
||||
|
|
|
@ -26,8 +26,6 @@ import util from '../util';
|
|||
import User from './user';
|
||||
import Subkey from './subkey';
|
||||
import * as helper from './helper';
|
||||
import PrivateKey from './private_key';
|
||||
import PublicKey from './public_key';
|
||||
import { UnparseablePacket } from '../packet/packet';
|
||||
|
||||
// A key revocation certificate can contain the following packets
|
||||
|
@ -710,21 +708,3 @@ class Key {
|
|||
});
|
||||
|
||||
export default Key;
|
||||
|
||||
/**
|
||||
* Creates a PublicKey or PrivateKey depending on the packetlist in input
|
||||
* @param {PacketList} - packets to parse
|
||||
* @return {Key} parsed key
|
||||
* @throws if no key packet was found
|
||||
*/
|
||||
export function createKey(packetlist) {
|
||||
for (const packet of packetlist) {
|
||||
switch (packet.constructor.tag) {
|
||||
case enums.packet.secretKey:
|
||||
return new PrivateKey(packetlist);
|
||||
case enums.packet.publicKey:
|
||||
return new PublicKey(packetlist);
|
||||
}
|
||||
}
|
||||
throw new Error('No key packet found');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user