Skip to content

Commit

Permalink
Use consistent name casing (#1268)
Browse files Browse the repository at this point in the history
- Use PascalCase for classes, with uppercase acronyms.
- Use camelCase for function and variables. First word/acronym is always
  lowercase, otherwise acronyms are uppercase.

Also, make the packet classes' `tag` properties `static`.
  • Loading branch information
larabr committed Mar 25, 2021
1 parent 8a57246 commit 6cff19c
Show file tree
Hide file tree
Showing 91 changed files with 1,586 additions and 1,501 deletions.
18 changes: 9 additions & 9 deletions README.md
Expand Up @@ -79,9 +79,9 @@ library to convert back and forth between them.
You can change the AEAD mode by setting one of the following options:

```
openpgp.config.preferredAeadAlgorithm = openpgp.enums.aead.eax // Default, native
openpgp.config.preferredAeadAlgorithm = openpgp.enums.aead.ocb // Non-native
openpgp.config.preferredAeadAlgorithm = openpgp.enums.aead.experimentalGcm // **Non-standard**, fastest
openpgp.config.preferredAEADAlgorithm = openpgp.enums.aead.eax // Default, native
openpgp.config.preferredAEADAlgorithm = openpgp.enums.aead.ocb // Non-native
openpgp.config.preferredAEADAlgorithm = openpgp.enums.aead.experimentalGCM // **Non-standard**, fastest
```

* For environments that don't provide native crypto, the library falls back to [asm.js](https://caniuse.com/#feat=asmjs) implementations of AES, SHA-1, and SHA-256.
Expand Down Expand Up @@ -139,7 +139,7 @@ To test whether the lazy loading works, try to generate a key with a non-standar

```js
import { generateKey } from 'openpgp/lightweight';
await generateKey({ curve: 'brainpoolP512r1', userIds: [{ name: 'Test', email: 'test@test.com' }] });
await generateKey({ curve: 'brainpoolP512r1', userIDs: [{ name: 'Test', email: 'test@test.com' }] });
```

For more examples of how to generate a key, see [Generate new key pair](#generate-new-key-pair). It is recommended to use `curve25519` instead of `brainpoolP512r1` by default.
Expand Down Expand Up @@ -395,7 +395,7 @@ and a subkey for encryption using Curve25519.
const { privateKeyArmored, publicKeyArmored, revocationCertificate } = await openpgp.generateKey({
type: 'ecc', // Type of the key, defaults to ECC
curve: 'curve25519', // ECC curve name, defaults to curve25519
userIds: [{ name: 'Jon Smith', email: 'jon@example.com' }], // you can pass multiple user IDs
userIDs: [{ name: 'Jon Smith', email: 'jon@example.com' }], // you can pass multiple user IDs
passphrase: 'super long and hard to guess secret' // protects the private key
});

Expand All @@ -412,7 +412,7 @@ RSA keys (increased compatibility):
const key = await openpgp.generateKey({
type: 'rsa', // Type of the key
rsaBits: 4096, // RSA key size (defaults to 4096 bits)
userIds: [{ name: 'Jon Smith', email: 'jon@example.com' }], // you can pass multiple user IDs
userIDs: [{ name: 'Jon Smith', email: 'jon@example.com' }], // you can pass multiple user IDs
passphrase: 'super long and hard to guess secret' // protects the private key
});
})();
Expand Down Expand Up @@ -473,7 +473,7 @@ Using the private key:
});
const { valid } = verified.signatures[0];
if (valid) {
console.log('signed by key id ' + verified.signatures[0].keyid.toHex());
console.log('signed by key id ' + verified.signatures[0].keyID.toHex());
} else {
throw new Error('signature could not be verified');
}
Expand Down Expand Up @@ -515,7 +515,7 @@ Using the private key:
});
const { valid } = verified.signatures[0];
if (valid) {
console.log('signed by key id ' + verified.signatures[0].keyid.toHex());
console.log('signed by key id ' + verified.signatures[0].keyID.toHex());
} else {
throw new Error('signature could not be verified');
}
Expand Down Expand Up @@ -563,7 +563,7 @@ Using the private key:

const { valid } = verified.signatures[0];
if (valid) {
console.log('signed by key id ' + verified.signatures[0].keyid.toHex());
console.log('signed by key id ' + verified.signatures[0].keyID.toHex());
} else {
throw new Error('signature could not be verified');
}
Expand Down
91 changes: 45 additions & 46 deletions openpgp.d.ts
Expand Up @@ -14,10 +14,10 @@ export function readKey(options: { binaryKey: Uint8Array, config?: PartialConfig
export function readKeys(options: { armoredKeys: string, config?: PartialConfig }): Promise<Key[]>;
export function readKeys(options: { binaryKeys: Uint8Array, config?: PartialConfig }): Promise<Key[]>;
export function generateKey(options: KeyOptions): Promise<KeyPair>;
export function generateSessionKey(options: { publicKeys: Key[], date?: Date, toUserIds?: UserID[], config?: PartialConfig }): Promise<SessionKey>;
export function generateSessionKey(options: { publicKeys: Key[], date?: Date, toUserIDs?: UserID[], config?: PartialConfig }): Promise<SessionKey>;
export function decryptKey(options: { privateKey: Key; passphrase?: string | string[]; config?: PartialConfig }): Promise<Key>;
export function encryptKey(options: { privateKey: Key; passphrase?: string | string[]; config?: PartialConfig }): Promise<Key>;
export function reformatKey(options: { privateKey: Key; userIds?: UserID|UserID[]; passphrase?: string; keyExpirationTime?: number; config?: PartialConfig }): Promise<KeyPair>;
export function reformatKey(options: { privateKey: Key; userIDs?: UserID|UserID[]; passphrase?: string; keyExpirationTime?: number; config?: PartialConfig }): Promise<KeyPair>;

export class Key {
constructor(packetlist: PacketList<AnyPacket>);
Expand All @@ -28,33 +28,33 @@ export class Key {
private keyPacket: PublicKeyPacket | SecretKeyPacket;
public write(): Uint8Array;
public armor(config?: Config): string;
public decrypt(passphrase: string | string[], keyId?: Keyid, config?: Config): Promise<void>; // throws on error
public encrypt(passphrase: string | string[], keyId?: Keyid, config?: Config): Promise<void>; // throws on error
public getExpirationTime(capability?: 'encrypt' | 'encrypt_sign' | 'sign', keyId?: Keyid, userId?: UserID, config?: Config): Promise<Date | typeof Infinity | null>; // Returns null if `capabilities` is passed and the key does not have the specified capabilities or is revoked or invalid.
public getKeyIds(): Keyid[];
public getPrimaryUser(date?: Date, userId?: UserID, config?: Config): Promise<PrimaryUser>; // throws on error
public getUserIds(): string[];
public decrypt(passphrase: string | string[], keyID?: KeyID, config?: Config): Promise<void>; // throws on error
public encrypt(passphrase: string | string[], keyID?: KeyID, config?: Config): Promise<void>; // throws on error
public getExpirationTime(capability?: 'encrypt' | 'encrypt_sign' | 'sign', keyID?: KeyID, userID?: UserID, config?: Config): Promise<Date | typeof Infinity | null>; // Returns null if `capabilities` is passed and the key does not have the specified capabilities or is revoked or invalid.
public getKeyIDs(): KeyID[];
public getPrimaryUser(date?: Date, userID?: UserID, config?: Config): Promise<PrimaryUser>; // throws on error
public getUserIDs(): string[];
public isPrivate(): boolean;
public isPublic(): boolean;
public toPublic(): Key;
public update(key: Key, config?: Config): void;
public signPrimaryUser(privateKeys: Key[], date?: Date, userId?: UserID, config?: Config): Promise<Key>
public signPrimaryUser(privateKeys: Key[], date?: Date, userID?: UserID, config?: Config): Promise<Key>
public signAllUsers(privateKeys: Key[], config?: Config): Promise<Key>
public verifyPrimaryKey(date?: Date, userId?: UserID, config?: Config): Promise<void>; // throws on error
public verifyPrimaryUser(publicKeys: Key[], date?: Date, userIds?: UserID, config?: Config): Promise<{ keyid: Keyid, valid: boolean | null }[]>;
public verifyAllUsers(publicKeys: Key[], config?: Config): Promise<{ userid: string, keyid: Keyid, valid: boolean | null }[]>;
public verifyPrimaryKey(date?: Date, userID?: UserID, config?: Config): Promise<void>; // throws on error
public verifyPrimaryUser(publicKeys: Key[], date?: Date, userIDs?: UserID, config?: Config): Promise<{ keyID: KeyID, valid: boolean | null }[]>;
public verifyAllUsers(publicKeys: Key[], config?: Config): Promise<{ userID: string, keyID: KeyID, valid: boolean | null }[]>;
public isRevoked(signature: SignaturePacket, key?: AnyKeyPacket, date?: Date, config?: Config): Promise<boolean>;
public revoke(reason: { flag?: enums.reasonForRevocation; string?: string; }, date?: Date, config?: Config): Promise<Key>;
public getRevocationCertificate(date?: Date, config?: Config): Promise<Stream<string> | string | undefined>;
public getEncryptionKey(keyid?: Keyid, date?: Date | null, userId?: UserID, config?: Config): Promise<Key | SubKey>;
public getSigningKey(keyid?: Keyid, date?: Date | null, userId?: UserID, config?: Config): Promise<Key | SubKey>;
public getKeys(keyId?: Keyid): (Key | SubKey)[];
public getSubkeys(keyId?: Keyid): SubKey[];
public getEncryptionKey(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise<Key | SubKey>;
public getSigningKey(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise<Key | SubKey>;
public getKeys(keyID?: KeyID): (Key | SubKey)[];
public getSubkeys(keyID?: KeyID): SubKey[];
public isDecrypted(): boolean;
public getFingerprint(): string;
public getCreationTime(): Date;
public getAlgorithmInfo(): AlgorithmInfo;
public getKeyId(): Keyid;
public getKeyID(): KeyID;
public addSubkey(options: SubKeyOptions): Promise<Key>;
}

Expand All @@ -68,11 +68,11 @@ export class SubKey {
public getFingerprint(): string;
public getCreationTime(): Date;
public getAlgorithmInfo(): AlgorithmInfo;
public getKeyId(): Keyid;
public getKeyID(): KeyID;
}

export interface User {
userId: UserIDPacket | null;
userID: UserIDPacket | null;
userAttribute: UserAttributePacket | null;
selfCertifications: SignaturePacket[];
otherCertifications: SignaturePacket[];
Expand Down Expand Up @@ -103,7 +103,7 @@ export class Signature {
}

interface VerificationResult {
keyid: Keyid;
keyID: KeyID;
verified: Promise<null | boolean>;
signature: Promise<Signature>;
}
Expand All @@ -121,7 +121,7 @@ export class CleartextMessage {

/** Returns the key IDs of the keys that signed the cleartext message
*/
getSigningKeyIds(): Keyid[];
getSigningKeyIDs(): KeyID[];

/** Get cleartext
*/
Expand All @@ -131,7 +131,7 @@ export class CleartextMessage {
*
* @param privateKeys private keys with decrypted secret key data for signing
*/
sign(privateKeys: Key[], signature?: Signature, signingKeyIds?: Keyid[], date?: Date, userIds?: UserID[], config?: Config): void;
sign(privateKeys: Key[], signature?: Signature, signingKeyIDs?: KeyID[], date?: Date, userIDs?: UserID[], config?: Config): void;

/** Verify signatures of cleartext signed message
* @param keys array of keys to verify signatures
Expand Down Expand Up @@ -262,19 +262,19 @@ export class Message<T extends MaybeStream<Data>> {
/** Encrypt the message
@param keys array of keys, used to encrypt the message
*/
public encrypt(keys?: Key[], passwords?: string[], sessionKeys?: SessionKey[], wildcard?: boolean, encryptionKeyIds?: Keyid[], date?: Date, userIds?: UserID[], streaming?: boolean, config?: Config): Promise<Message<MaybeStream<Data>>>;
public encrypt(keys?: Key[], passwords?: string[], sessionKeys?: SessionKey[], wildcard?: boolean, encryptionKeyIDs?: KeyID[], date?: Date, userIDs?: UserID[], streaming?: boolean, config?: Config): Promise<Message<MaybeStream<Data>>>;

/** Returns the key IDs of the keys to which the session key is encrypted
*/
public getEncryptionKeyIds(): Keyid[];
public getEncryptionKeyIDs(): KeyID[];

/** Get literal data that is the body of the message
*/
public getLiteralData(): Uint8Array | Stream<Uint8Array> | null;

/** Returns the key IDs of the keys that signed the message
*/
public getSigningKeyIds(): Keyid[];
public getSigningKeyIDs(): KeyID[];

/** Get literal data as text
*/
Expand All @@ -285,7 +285,7 @@ export class Message<T extends MaybeStream<Data>> {
/** Sign the message (the literal data packet of the message)
@param privateKey private keys with decrypted secret key data for signing
*/
public sign(privateKey: Key[], signature?: Signature, signingKeyIds?: Keyid[], date?: Date, userIds?: UserID[], streaming?: boolean, config?: Config): Promise<Message<T>>;
public sign(privateKey: Key[], signature?: Signature, signingKeyIDs?: KeyID[], date?: Date, userIDs?: UserID[], streaming?: boolean, config?: Config): Promise<Message<T>>;

/** Unwrap compressed message
*/
Expand Down Expand Up @@ -320,7 +320,7 @@ interface Config {
allowUnauthenticatedMessages: boolean;
allowUnauthenticatedStream: boolean;
checksumRequired: boolean;
minRsaBits: number;
minRSABits: number;
passwordCollisionCheck: boolean;
revocationsExpire: boolean;
tolerant: boolean;
Expand Down Expand Up @@ -357,7 +357,7 @@ declare abstract class BasePublicKeyPacket extends BasePacket {
public getFingerprintBytes(): Uint8Array | null;
public hasSameFingerprintAs(other: BasePublicKeyPacket): boolean;
public getCreationTime(): Date;
public getKeyId(): Keyid;
public getKeyID(): KeyID;
public isDecrypted(): boolean;
public publicParams: object;
}
Expand Down Expand Up @@ -396,7 +396,7 @@ export class SymEncryptedIntegrityProtectedDataPacket extends BasePacket {
}

export class AEADEncryptedDataPacket extends BasePacket {
public tag: enums.packet.AEADEncryptedData;
public tag: enums.packet.aeadEncryptedData;
}

export class PublicKeyEncryptedSessionKeyPaclet extends BasePacket {
Expand Down Expand Up @@ -433,8 +433,8 @@ export class UserIDPacket extends BasePacket {
public readonly name: string;
public readonly comment: string;
public readonly email: string;
public readonly userid: string;
static fromObject(userId: UserID): UserIDPacket;
public readonly userID: string;
static fromObject(userID: UserID): UserIDPacket;
}

export class SignaturePacket extends BasePacket {
Expand All @@ -460,7 +460,7 @@ export class SignaturePacket extends BasePacket {
public revocationKeyClass: null | number;
public revocationKeyAlgorithm: null | enums.publicKey;
public revocationKeyFingerprint: null | Uint8Array;
public issuerKeyId: Keyid;
public issuerKeyID: KeyID;
public notation: null | { [name: string]: string };
public preferredHashAlgorithms: enums.hash[] | null;
public preferredCompressionAlgorithms: enums.compression[] | null;
Expand All @@ -469,7 +469,7 @@ export class SignaturePacket extends BasePacket {
public isPrimaryUserID: null | boolean;
public policyURI: null | string;
public keyFlags: Uint8Array | null;
public signersUserId: null | string;
public signersUserID: null | string;
public reasonForRevocationFlag: null | enums.reasonForRevocation;
public reasonForRevocationString: null | string;
public features: Uint8Array | null;
Expand All @@ -479,7 +479,7 @@ export class SignaturePacket extends BasePacket {
public embeddedSignature: null | SignaturePacket;
public issuerKeyVersion: null | number;
public issuerFingerprint: null | Uint8Array;
public preferredAeadAlgorithms: enums.aead[] | null;
public preferredAEADAlgorithms: enums.aead[] | null;
public verified: null | boolean;
public revoked: null | boolean;
public sign(key: AnySecretKeyPacket, data: Uint8Array, detached?: boolean, streaming?: boolean): Promise<void>;
Expand Down Expand Up @@ -572,9 +572,9 @@ interface EncryptOptions {
/** (optional) use a key ID of 0 instead of the public key IDs */
wildcard?: boolean;
/** (optional) user ID to sign with, e.g. { name:'Steve Sender', email:'steve@openpgp.org' } */
fromUserId?: UserID;
fromUserID?: UserID;
/** (optional) user ID to encrypt for, e.g. { name:'Robert Receiver', email:'robert@openpgp.org' } */
toUserId?: UserID;
toUserID?: UserID;
config?: PartialConfig;
}

Expand Down Expand Up @@ -608,7 +608,7 @@ interface SignOptions {
dataType?: DataPacketType;
detached?: boolean;
date?: Date;
fromUserId?: UserID;
fromUserID?: UserID;
config?: PartialConfig;
}

Expand Down Expand Up @@ -638,7 +638,7 @@ interface KeyPair {
export type EllipticCurveName = 'ed25519' | 'curve25519' | 'p256' | 'p384' | 'p521' | 'secp256k1' | 'brainpoolP256r1' | 'brainpoolP384r1' | 'brainpoolP512r1';

interface KeyOptions {
userIds: UserID|UserID[];
userIDs: UserID|UserID[];
passphrase?: string;
type?: 'ecc' | 'rsa';
curve?: EllipticCurveName;
Expand All @@ -659,11 +659,11 @@ interface SubKeyOptions {
config?: PartialConfig;
}

declare class Keyid {
declare class KeyID {
bytes: string;
equals(keyid: Keyid, matchWildcard?: boolean): boolean;
equals(keyID: KeyID, matchWildcard?: boolean): boolean;
toHex(): string;
static fromId(hex: string): Keyid;
static fromID(hex: string): KeyID;
}

interface DecryptMessageResult {
Expand Down Expand Up @@ -691,7 +691,6 @@ export function unarmor(input: string, config?: Config): Promise<{ text: string,
/* ############## v5 ENUMS #################### */

export namespace enums {

function read(type: typeof armor, e: armor): armorNames;
function read(type: typeof compression, e: compression): compressionNames;
function read(type: typeof hash, e: hash): hashNames;
Expand All @@ -717,7 +716,7 @@ export namespace enums {
keySuperseded = 1, // Key is superseded (key revocations)
keyCompromised = 2, // Key material has been compromised (key revocations)
keyRetired = 3, // Key is retired and no longer used (key revocations)
useridInvalid = 32, // User ID information is no longer valid (cert revocations)
userIDInvalid = 32, // User ID information is no longer valid (cert revocations)
}

export type compressionNames = 'uncompressed' | 'zip' | 'zlib' | 'bzip2';
Expand All @@ -740,7 +739,7 @@ export namespace enums {
}

export type packetNames = 'publicKeyEncryptedSessionKey' | 'signature' | 'symEncryptedSessionKey' | 'onePassSignature' | 'secretKey' | 'publicKey'
| 'secretSubkey' | 'compressed' | 'symmetricallyEncrypted' | 'marker' | 'literal' | 'trust' | 'userid' | 'publicSubkey' | 'userAttribute'
| 'secretSubkey' | 'compressed' | 'symmetricallyEncrypted' | 'marker' | 'literal' | 'trust' | 'userID' | 'publicSubkey' | 'userAttribute'
| 'symEncryptedIntegrityProtected' | 'modificationDetectionCode' | 'AEADEncryptedDataPacket';
enum packet {
publicKeyEncryptedSessionKey = 1,
Expand All @@ -760,7 +759,7 @@ export namespace enums {
userAttribute = 17,
symEncryptedIntegrityProtectedData = 18,
modificationDetectionCode = 19,
AEADEncryptedData = 20,
aeadEncryptedData = 20,
}

export type publicKeyNames = 'rsaEncryptSign' | 'rsaEncrypt' | 'rsaSign' | 'elgamal' | 'dsa' | 'ecdh' | 'ecdsa' | 'eddsa' | 'aedh' | 'aedsa';
Expand Down Expand Up @@ -832,6 +831,6 @@ export namespace enums {
enum aead {
eax = 1,
ocb = 2,
experimentalGcm = 100 // Private algorithm
experimentalGCM = 100 // Private algorithm
}
}

0 comments on commit 6cff19c

Please sign in to comment.