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 publicKey from './public_key';
|
||||||
import * as cipher from './cipher';
|
|
||||||
import mode from './mode';
|
import mode from './mode';
|
||||||
import { getRandomBytes } from './random';
|
import { getRandomBytes } from './random';
|
||||||
|
import getCipher from './cipher/getCipher';
|
||||||
import ECDHSymkey from '../type/ecdh_symkey';
|
import ECDHSymkey from '../type/ecdh_symkey';
|
||||||
import KDFParams from '../type/kdf_params';
|
import KDFParams from '../type/kdf_params';
|
||||||
import enums from '../enums';
|
import enums from '../enums';
|
||||||
|
@ -385,16 +385,7 @@ export function getAEADMode(algo) {
|
||||||
return mode[algoName];
|
return mode[algoName];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export { getCipher };
|
||||||
* 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];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the given curve OID is supported
|
* Check whether the given curve OID is supported
|
||||||
|
|
|
@ -24,8 +24,7 @@
|
||||||
|
|
||||||
import { AES_CFB } from '@openpgp/asmcrypto.js/dist_es8/aes/cfb';
|
import { AES_CFB } from '@openpgp/asmcrypto.js/dist_es8/aes/cfb';
|
||||||
import * as stream from '@openpgp/web-stream-tools';
|
import * as stream from '@openpgp/web-stream-tools';
|
||||||
import { getCipher } from '../crypto';
|
import getCipher from '../cipher/getCipher';
|
||||||
import * as cipher from '../cipher';
|
|
||||||
import util from '../../util';
|
import util from '../../util';
|
||||||
import enums from '../../enums';
|
import enums from '../../enums';
|
||||||
|
|
||||||
|
@ -62,7 +61,8 @@ export async function encrypt(algo, key, plaintext, iv, config) {
|
||||||
return aesEncrypt(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 block_size = cipherfn.blockSize;
|
||||||
|
|
||||||
const blockc = iv.slice();
|
const blockc = iv.slice();
|
||||||
|
@ -104,7 +104,8 @@ export async function decrypt(algo, key, ciphertext, iv) {
|
||||||
return aesDecrypt(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;
|
const block_size = cipherfn.blockSize;
|
||||||
|
|
||||||
let blockp = iv;
|
let blockp = iv;
|
||||||
|
|
|
@ -31,7 +31,7 @@ import util from '../../../util';
|
||||||
import { b64ToUint8Array } from '../../../encoding/base64';
|
import { b64ToUint8Array } from '../../../encoding/base64';
|
||||||
import * as pkcs5 from '../../pkcs5';
|
import * as pkcs5 from '../../pkcs5';
|
||||||
import { keyFromPublic, keyFromPrivate, getIndutnyCurve } from './indutnyKey';
|
import { keyFromPublic, keyFromPrivate, getIndutnyCurve } from './indutnyKey';
|
||||||
import { getCipher } from '../../crypto';
|
import getCipher from '../../cipher/getCipher';
|
||||||
|
|
||||||
const webCrypto = util.getWebCrypto();
|
const webCrypto = util.getWebCrypto();
|
||||||
const nodeCrypto = util.getNodeCrypto();
|
const nodeCrypto = util.getNodeCrypto();
|
||||||
|
|
|
@ -26,7 +26,7 @@ import {
|
||||||
UserAttributePacket
|
UserAttributePacket
|
||||||
} from '../packet';
|
} from '../packet';
|
||||||
import PrivateKey from './private_key';
|
import PrivateKey from './private_key';
|
||||||
import { createKey } from './key';
|
import PublicKey from './public_key';
|
||||||
import * as helper from './helper';
|
import * as helper from './helper';
|
||||||
import enums from '../enums';
|
import enums from '../enums';
|
||||||
import util from '../util';
|
import util from '../util';
|
||||||
|
@ -44,6 +44,25 @@ const allowedKeyPackets = /*#__PURE__*/ util.constructAllowedPackets([
|
||||||
SignaturePacket
|
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.
|
* Generates a new OpenPGP key. Supports RSA and ECC keys.
|
||||||
* By default, primary and subkeys will be of same type.
|
* By default, primary and subkeys will be of same type.
|
||||||
|
|
|
@ -26,8 +26,6 @@ import util from '../util';
|
||||||
import User from './user';
|
import User from './user';
|
||||||
import Subkey from './subkey';
|
import Subkey from './subkey';
|
||||||
import * as helper from './helper';
|
import * as helper from './helper';
|
||||||
import PrivateKey from './private_key';
|
|
||||||
import PublicKey from './public_key';
|
|
||||||
import { UnparseablePacket } from '../packet/packet';
|
import { UnparseablePacket } from '../packet/packet';
|
||||||
|
|
||||||
// A key revocation certificate can contain the following packets
|
// A key revocation certificate can contain the following packets
|
||||||
|
@ -710,21 +708,3 @@ class Key {
|
||||||
});
|
});
|
||||||
|
|
||||||
export default 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