From 00300ae0025d766d503d7e71f5bb30d3fe2e8978 Mon Sep 17 00:00:00 2001 From: larabr <7375870+larabr@users.noreply.github.com> Date: Wed, 9 Jun 2021 14:07:57 +0200 Subject: [PATCH] Rename SubKey class --- openpgp.d.ts | 22 +++++++++++----------- src/key/key.js | 20 ++++++++++---------- src/key/private_key.js | 2 +- src/key/subkey.js | 28 ++++++++++++++-------------- test/general/key.js | 2 +- test/general/openpgp.js | 4 ++-- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/openpgp.d.ts b/openpgp.d.ts index baed08765..d08aa14a6 100644 --- a/openpgp.d.ts +++ b/openpgp.d.ts @@ -25,7 +25,7 @@ export function reformatKey(options: { privateKey: PrivateKey; userIDs?: UserID| export abstract class Key { private keyPacket: PublicKeyPacket | SecretKeyPacket; - public subkeys: SubKey[]; + public subkeys: Subkey[]; public users: User[]; public revocationSignatures: SignaturePacket[]; public write(): Uint8Array; @@ -45,10 +45,10 @@ export abstract class Key { public verifyAllUsers(publicKeys: PublicKey[], date?: Date, config?: Config): Promise<{ userID: string, keyID: KeyID, valid: boolean | null }[]>; public isRevoked(signature: SignaturePacket, key?: AnyKeyPacket, date?: Date, config?: Config): Promise; public getRevocationCertificate(date?: Date, config?: Config): Promise | string | undefined>; - public getEncryptionKey(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise; - public getSigningKey(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise; - public getKeys(keyID?: KeyID): (PublicKey | SubKey)[]; - public getSubkeys(keyID?: KeyID): SubKey[]; + public getEncryptionKey(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise; + public getSigningKey(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise; + public getKeys(keyID?: KeyID): (PublicKey | Subkey)[]; + public getSubkeys(keyID?: KeyID): Subkey[]; public getFingerprint(): string; public getCreationTime(): Date; public getAlgorithmInfo(): AlgorithmInfo; @@ -65,13 +65,13 @@ export class PrivateKey extends PublicKey { constructor(packetlist: PacketList); public revoke(reason: { flag?: enums.reasonForRevocation; string?: string; }, date?: Date, config?: Config): Promise; public isDecrypted(): boolean; - public addSubkey(options: SubKeyOptions): Promise; - public getDecryptionKeys(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise + public addSubkey(options: SubkeyOptions): Promise; + public getDecryptionKeys(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise public update(sourceKey: PublicKey, date?: Date, config?: Config): Promise; - public getKeys(keyID?: KeyID): (PrivateKey | SubKey)[]; + public getKeys(keyID?: KeyID): (PrivateKey | Subkey)[]; } -export class SubKey { +export class Subkey { constructor(subkeyPacket: SecretSubkeyPacket | PublicSubkeyPacket, mainKey: PublicKey); private keyPacket: SecretSubkeyPacket | PublicSubkeyPacket; private mainKey: PublicKey; @@ -634,11 +634,11 @@ interface KeyOptions { rsaBits?: number; keyExpirationTime?: number; date?: Date; - subkeys?: SubKeyOptions[]; + subkeys?: SubkeyOptions[]; config?: PartialConfig; } -interface SubKeyOptions { +interface SubkeyOptions { type?: 'ecc' | 'rsa'; curve?: EllipticCurveName; rsaBits?: number; diff --git a/src/key/key.js b/src/key/key.js index 849403924..1c6478509 100644 --- a/src/key/key.js +++ b/src/key/key.js @@ -24,7 +24,7 @@ import defaultConfig from '../config'; import enums from '../enums'; import util from '../util'; import User from './user'; -import SubKey from './subkey'; +import Subkey from './subkey'; import * as helper from './helper'; import PrivateKey from './private_key'; import PublicKey from './public_key'; @@ -76,7 +76,7 @@ class Key { case enums.packet.publicSubkey: case enums.packet.secretSubkey: user = null; - subkey = new SubKey(packet, this); + subkey = new Subkey(packet, this); this.subkeys.push(subkey); break; case enums.packet.signature: @@ -172,7 +172,7 @@ class Key { * Returns an array containing all public or private subkeys matching keyID; * If no keyID is given, returns all subkeys. * @param {type/keyID} [keyID] - key ID to look for - * @returns {Array} array of subkeys + * @returns {Array} array of subkeys */ getSubkeys(keyID = null) { const subkeys = this.subkeys.filter(subkey => ( @@ -185,7 +185,7 @@ class Key { * Returns an array containing all public or private keys matching keyID. * If no keyID is given, returns all keys, starting with the primary key. * @param {type/keyid~KeyID} [keyID] - key ID to look for - * @returns {Array} array of keys + * @returns {Array} array of keys */ getKeys(keyID = null) { const keys = []; @@ -227,7 +227,7 @@ class Key { * @param {Date} [date] - use the fiven date date to to check key validity instead of the current date * @param {Object} [userID] - filter keys for the given user ID * @param {Object} [config] - Full configuration, defaults to openpgp.config - * @returns {Promise} signing key + * @returns {Promise} signing key * @throws if no valid signing key was found * @async */ @@ -281,7 +281,7 @@ class Key { * @param {Date} [date] - use the fiven date date to to check key validity instead of the current date * @param {Object} [userID] - filter keys for the given user ID * @param {Object} [config] - Full configuration, defaults to openpgp.config - * @returns {Promise} encryption key + * @returns {Promise} encryption key * @throws if no valid encryption key was found * @async */ @@ -475,9 +475,9 @@ class Key { if (this.isPublic() && sourceKey.isPrivate()) { // check for equal subkey packets const equal = (this.subkeys.length === sourceKey.subkeys.length) && - (this.subkeys.every(destSubKey => { - return sourceKey.subkeys.some(srcSubKey => { - return destSubKey.hasSameFingerprintAs(srcSubKey); + (this.subkeys.every(destSubkey => { + return sourceKey.subkeys.some(srcSubkey => { + return destSubkey.hasSameFingerprintAs(srcSubkey); }); })); if (!equal) { @@ -667,7 +667,7 @@ class Key { ['getKeyID', 'getFingerprint', 'getAlgorithmInfo', 'getCreationTime', 'hasSameFingerprintAs'].forEach(name => { Key.prototype[name] = - SubKey.prototype[name]; + Subkey.prototype[name]; }); export default Key; diff --git a/src/key/private_key.js b/src/key/private_key.js index e53b89c75..fa5cd29f2 100644 --- a/src/key/private_key.js +++ b/src/key/private_key.js @@ -84,7 +84,7 @@ class PrivateKey extends PublicKey { * @param {Date} date, optional * @param {String} userID, optional * @param {Object} [config] - Full configuration, defaults to openpgp.config - * @returns {Promise>} Array of decryption keys. + * @returns {Promise>} Array of decryption keys. * @async */ async getDecryptionKeys(keyID, date = new Date(), userID = {}, config = defaultConfig) { diff --git a/src/key/subkey.js b/src/key/subkey.js index 94bf5316c..08a48c8a3 100644 --- a/src/key/subkey.js +++ b/src/key/subkey.js @@ -1,5 +1,5 @@ /** - * @module key/SubKey + * @module key/Subkey * @private */ @@ -10,14 +10,14 @@ import defaultConfig from '../config'; /** * Class that represents a subkey packet and the relevant signatures. - * @borrows PublicSubkeyPacket#getKeyID as SubKey#getKeyID - * @borrows PublicSubkeyPacket#getFingerprint as SubKey#getFingerprint - * @borrows PublicSubkeyPacket#hasSameFingerprintAs as SubKey#hasSameFingerprintAs - * @borrows PublicSubkeyPacket#getAlgorithmInfo as SubKey#getAlgorithmInfo - * @borrows PublicSubkeyPacket#getCreationTime as SubKey#getCreationTime - * @borrows PublicSubkeyPacket#isDecrypted as SubKey#isDecrypted + * @borrows PublicSubkeyPacket#getKeyID as Subkey#getKeyID + * @borrows PublicSubkeyPacket#getFingerprint as Subkey#getFingerprint + * @borrows PublicSubkeyPacket#hasSameFingerprintAs as Subkey#hasSameFingerprintAs + * @borrows PublicSubkeyPacket#getAlgorithmInfo as Subkey#getAlgorithmInfo + * @borrows PublicSubkeyPacket#getCreationTime as Subkey#getCreationTime + * @borrows PublicSubkeyPacket#isDecrypted as Subkey#isDecrypted */ -class SubKey { +class Subkey { /** * @param {SecretSubkeyPacket|PublicSubkeyPacket} subkeyPacket - subkey packet to hold in the Subkey * @param {Key} mainKey - reference to main Key object, containing the primary key packet corresponding to the subkey @@ -112,7 +112,7 @@ class SubKey { /** * Update subkey with new components from specified subkey - * @param {SubKey} subkey - Source subkey to merge + * @param {Subkey} subkey - Source subkey to merge * @param {Date} [date] - Date to verify validity of signatures * @param {Object} [config] - Full configuration, defaults to openpgp.config * @throws {Error} if update failed @@ -121,7 +121,7 @@ class SubKey { async update(subkey, date = new Date(), config = defaultConfig) { const primaryKey = this.mainKey.keyPacket; if (!this.hasSameFingerprintAs(subkey)) { - throw new Error('SubKey update method: fingerprints of subkeys not equal'); + throw new Error('Subkey update method: fingerprints of subkeys not equal'); } // key packet if (this.keyPacket.constructor.tag === enums.packet.publicSubkey && @@ -161,7 +161,7 @@ class SubKey { * @param {String} reasonForRevocation.string optional, string explaining the reason for revocation * @param {Date} date - optional, override the creationtime of the revocation signature * @param {Object} [config] - Full configuration, defaults to openpgp.config - * @returns {Promise} New subkey with revocation signature. + * @returns {Promise} New subkey with revocation signature. * @async */ async revoke( @@ -174,7 +174,7 @@ class SubKey { config = defaultConfig ) { const dataToSign = { key: primaryKey, bind: this.keyPacket }; - const subkey = new SubKey(this.keyPacket, this.mainKey); + const subkey = new Subkey(this.keyPacket, this.mainKey); subkey.revocationSignatures.push(await helper.createSignaturePacket(dataToSign, null, primaryKey, { signatureType: enums.signature.subkeyRevocation, reasonForRevocationFlag: enums.write(enums.reasonForRevocation, reasonForRevocationFlag), @@ -190,10 +190,10 @@ class SubKey { } ['getKeyID', 'getFingerprint', 'getAlgorithmInfo', 'getCreationTime', 'isDecrypted'].forEach(name => { - SubKey.prototype[name] = + Subkey.prototype[name] = function() { return this.keyPacket[name](); }; }); -export default SubKey; +export default Subkey; diff --git a/test/general/key.js b/test/general/key.js index 5b725e3d0..a87672f5e 100644 --- a/test/general/key.js +++ b/test/general/key.js @@ -2907,7 +2907,7 @@ module.exports = () => describe('Key', function() { expect(expirationTime.toISOString()).to.be.equal('1970-01-01T00:22:18.000Z'); }); - it('Method getExpirationTime V4 SubKey', async function() { + it('Method getExpirationTime V4 Subkey', async function() { const [, pubKey] = await openpgp.readKeys({ armoredKeys: twoKeys }); expect(pubKey).to.exist; expect(pubKey).to.be.an.instanceof(openpgp.PublicKey); diff --git a/test/general/openpgp.js b/test/general/openpgp.js index 4a04bcb45..cd156a96c 100644 --- a/test/general/openpgp.js +++ b/test/general/openpgp.js @@ -3177,8 +3177,8 @@ aOU= privateKey: await openpgp.readKey({ armoredKey: priv_key_de }), passphrase }); - return privKeyDE.subkeys[0].revoke(privKeyDE.keyPacket).then(async function(revSubKey) { - pubKeyDE.subkeys[0] = revSubKey; + return privKeyDE.subkeys[0].revoke(privKeyDE.keyPacket).then(async function(revSubkey) { + pubKeyDE.subkeys[0] = revSubkey; return openpgp.encrypt({ message: await openpgp.createMessage({ text: plaintext }), encryptionKeys: pubKeyDE,