Skip to content

Commit

Permalink
Add key.write() and update type definitions (#1267)
Browse files Browse the repository at this point in the history
Also, mark key.keyPacket, message.packets and signature.packets private.
  • Loading branch information
sinderw committed Mar 16, 2021
1 parent 43fb584 commit eba791e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
18 changes: 14 additions & 4 deletions openpgp.d.ts
Expand Up @@ -25,7 +25,8 @@ export class Key {
public subKeys: SubKey[];
public users: User[];
public revocationSignatures: SignaturePacket[];
public keyPacket: PublicKeyPacket | SecretKeyPacket;
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
Expand All @@ -37,7 +38,11 @@ export class Key {
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 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 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>;
Expand All @@ -55,7 +60,7 @@ export class Key {

export class SubKey {
constructor(subKeyPacket: SecretSubkeyPacket | PublicSubkeyPacket);
public keyPacket: SecretSubkeyPacket | PublicSubkeyPacket;
private keyPacket: SecretSubkeyPacket | PublicSubkeyPacket;
public bindingSignatures: SignaturePacket[];
public revocationSignatures: SignaturePacket[];
public verify(primaryKey: PublicKeyPacket | SecretKeyPacket, date?: Date, config?: Config): Promise<SignaturePacket>;
Expand Down Expand Up @@ -91,8 +96,9 @@ export function readSignature(options: { armoredSignature: string, config?: Part
export function readSignature(options: { binarySignature: Uint8Array, config?: PartialConfig }): Promise<Signature>;

export class Signature {
public packets: PacketList<SignaturePacket>;
private packets: PacketList<SignaturePacket>;
constructor(packetlist: PacketList<SignaturePacket>);
public write(): MaybeStream<Uint8Array>;
public armor(config?: Config): string;
}

Expand Down Expand Up @@ -237,9 +243,13 @@ export function verify<T extends MaybeStream<Data>>(options: VerifyOptions & { m
*/
export class Message<T extends MaybeStream<Data>> {

public packets: PacketList<AnyPacket>;
private packets: PacketList<AnyPacket>;
constructor(packetlist: PacketList<AnyPacket>);

/** Returns binary representation of message
*/
public write(): MaybeStream<Uint8Array>;

/** Returns ASCII armored text of message
*/
public armor(config?: Config): string;
Expand Down
8 changes: 8 additions & 0 deletions src/key/key.js
Expand Up @@ -259,6 +259,14 @@ class Key {
return new Key(packetlist);
}

/**
* Returns binary encoded key
* @returns {Uint8Array} Binary key.
*/
write() {
return this.toPacketlist().write();
}

/**
* Returns ASCII armored text of key
* @param {Object} [config] - Full configuration, defaults to openpgp.config
Expand Down

0 comments on commit eba791e

Please sign in to comment.