Skip to content

Commit

Permalink
Rename SubKey class
Browse files Browse the repository at this point in the history
  • Loading branch information
larabr committed Jun 9, 2021
1 parent 2415b1c commit 00300ae
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
22 changes: 11 additions & 11 deletions openpgp.d.ts
Expand Up @@ -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;
Expand All @@ -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<boolean>;
public getRevocationCertificate(date?: Date, config?: Config): Promise<Stream<string> | string | undefined>;
public getEncryptionKey(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise<PublicKey | SubKey>;
public getSigningKey(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise<PublicKey | SubKey>;
public getKeys(keyID?: KeyID): (PublicKey | SubKey)[];
public getSubkeys(keyID?: KeyID): SubKey[];
public getEncryptionKey(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise<PublicKey | Subkey>;
public getSigningKey(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise<PublicKey | Subkey>;
public getKeys(keyID?: KeyID): (PublicKey | Subkey)[];
public getSubkeys(keyID?: KeyID): Subkey[];
public getFingerprint(): string;
public getCreationTime(): Date;
public getAlgorithmInfo(): AlgorithmInfo;
Expand All @@ -65,13 +65,13 @@ export class PrivateKey extends PublicKey {
constructor(packetlist: PacketList<AnyKeyPacket>);
public revoke(reason: { flag?: enums.reasonForRevocation; string?: string; }, date?: Date, config?: Config): Promise<PrivateKey>;
public isDecrypted(): boolean;
public addSubkey(options: SubKeyOptions): Promise<PrivateKey>;
public getDecryptionKeys(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise<PrivateKey | SubKey>
public addSubkey(options: SubkeyOptions): Promise<PrivateKey>;
public getDecryptionKeys(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise<PrivateKey | Subkey>
public update(sourceKey: PublicKey, date?: Date, config?: Config): Promise<PrivateKey>;
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;
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions src/key/key.js
Expand Up @@ -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';
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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<SubKey>} array of subkeys
* @returns {Array<Subkey>} array of subkeys
*/
getSubkeys(keyID = null) {
const subkeys = this.subkeys.filter(subkey => (
Expand All @@ -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<Key|SubKey>} array of keys
* @returns {Array<Key|Subkey>} array of keys
*/
getKeys(keyID = null) {
const keys = [];
Expand Down Expand Up @@ -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<Key|SubKey>} signing key
* @returns {Promise<Key|Subkey>} signing key
* @throws if no valid signing key was found
* @async
*/
Expand Down Expand Up @@ -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<Key|SubKey>} encryption key
* @returns {Promise<Key|Subkey>} encryption key
* @throws if no valid encryption key was found
* @async
*/
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/key/private_key.js
Expand Up @@ -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<Key|SubKey>>} Array of decryption keys.
* @returns {Promise<Array<Key|Subkey>>} Array of decryption keys.
* @async
*/
async getDecryptionKeys(keyID, date = new Date(), userID = {}, config = defaultConfig) {
Expand Down
28 changes: 14 additions & 14 deletions src/key/subkey.js
@@ -1,5 +1,5 @@
/**
* @module key/SubKey
* @module key/Subkey
* @private
*/

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 &&
Expand Down Expand Up @@ -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<SubKey>} New subkey with revocation signature.
* @returns {Promise<Subkey>} New subkey with revocation signature.
* @async
*/
async revoke(
Expand All @@ -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),
Expand All @@ -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;
2 changes: 1 addition & 1 deletion test/general/key.js
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/general/openpgp.js
Expand Up @@ -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,
Expand Down

0 comments on commit 00300ae

Please sign in to comment.