UNPKG

gpg-ts

Version:

GPG encryption and decryption in node.js by way of the gpg command-line tool. Now with TypeScript.

167 lines (166 loc) 7.45 kB
/*! * node-gpg-ts * Copyright(c) 2020 Stevan Dedovic * MIT Licensed * * node-gpg-ts was ported from node-gpg * Copyright(c) 2011 Nicholas Penree <drudge@conceited.net> * MIT Licensed */ /// <reference types="node" /> import { Opts } from './spawnGPG'; import { Readable, Writable } from "stream"; import { PathLike } from "fs"; import ErrnoException = NodeJS.ErrnoException; export declare class GPG { /** * Raw call to gpg. * * @param {String} stdin String to send to stdin. * @param {Array} [args] Array of arguments. * @param {Function} [fn] Callback. * @api public */ static call(stdin: string, args: string[], fn: (err: Error, msg: Buffer, error: string) => void): void; /** * Raw streaming call to gpg. Reads from input file and writes to output file. * * @param input * @param output * @param {Array} [args] Array of arguments. * @param {Function} [fn] Callback. * @api public */ static callStreaming(input: string | Readable, output: string | Writable, args: string[], fn: (err: Error, msg: Writable) => void): void; /** * Encrypt source file passed as `options.source` and store it in a file specified in `options.dest`. * * @param {Opts} options Should contain 'source' and 'dest' keys. * @param {Function} [fn] Callback. * @api public */ static encryptToFile(options: Opts, fn: (err: Error, msg: Writable) => void): void; /** * Encrypt source `file` and pass the encrypted contents to the callback `fn`. * * @param {PathLike} file Filename. * @param {Function} [fn] Callback containing the encrypted file contents. * @api public */ static encryptFile(file: PathLike, fn: (err: Error, msg: Buffer, error: string) => void): void; /** * Encrypt source stream passed as `options.source` and pass it to the stream specified in `options.dest`. * Is basically the same method as `encryptToFile()`. * * @param {Opts} options Should contain 'source' and 'dest' keys that are streams. * @param {Function} [fn] Callback. * @api public */ static encryptToStream(options: Opts, fn: (err: Error, msg: Writable) => void): void; /** * Encrypt source `stream` and pass the encrypted contents to the callback `fn`. * * @param {ReadableStream} stream Stream to read from. * @param {Array} [args] Array of additonal gpg arguments. * @param {Function} [fn] Callback containing the encrypted file contents. * @api public */ static encryptStream(stream: Readable, args: string[], fn: (err: Error, msg: Buffer, error: string) => void): void; /** * Encrypt `str` and pass the encrypted version to the callback `fn`. * * @param {String|Buffer} str String to encrypt. * @param {Array} [args] Array of additonal gpg arguments. * @param {Function} [fn] Callback containing the encrypted Buffer. * @api public */ static encrypt(str: string | Buffer, args: string[], fn: (err: Error, msg: Buffer, error: string) => void): void; /** * Decrypt `str` and pass the decrypted version to the callback `fn`. * * @param {String|Buffer} str Data to decrypt. * @param {Array} [args] Array of additonal gpg arguments. * @param {Function} [fn] Callback containing the decrypted Buffer. * @api public */ static decrypt(str: string | Buffer, args: string[], fn: (err: Error, msg: Buffer, error: string) => void): void; /** * Decrypt source `file` and pass the decrypted contents to the callback `fn`. * * @param {PathLike} file Filename. * @param {Function} fn Callback containing the decrypted file contents. * @api public */ static decryptFile(file: PathLike, fn: (err: Error, msg: Buffer, error: string) => void): void; /** * Decrypt source file passed as `options.source` and store it in a file specified in `options.dest`. * * @param {Opts} options Should contain 'source' and 'dest' keys. * @param {Function} fn Callback * @api public */ static decryptToFile(options: Opts, fn: (err: Error, msg: Writable) => void): void; /** * Decrypt source `stream` and pass the decrypted contents to the callback `fn`. * * @param {ReadableStream} stream Stream to read from. * @param {Array} [args] Array of additonal gpg arguments. * @param {Function} [fn] Callback containing the decrypted file contents. * @api public */ static decryptStream(stream: Readable, args: string[], fn: (err: Error, msg: Buffer, error: string) => void): void; /** * Decrypt source stream passed as `options.source` and pass it to the stream specified in `options.dest`. * This is basically the same method as `decryptToFile()`. * * @param {Opts} options Should contain 'source' and 'dest' keys that are streams. * @param {Function} fn Callback * @api public */ static decryptToStream(options: Opts, fn: (err: Error, msg: Writable) => void): void; /** * Clearsign `str` and pass the signed message to the callback `fn`. * * @param {String|Buffer} str String to clearsign. * @param {Array} [args] Array of additonal gpg arguments. * @param {Function} fn Callback containing the signed message Buffer. * @api public */ static clearsign(str: string | Buffer, args: string[], fn: (err: Error, msg: Buffer, error: string) => void): void; /** * Verify `str` and pass the output to the callback `fn`. * * @param {String|Buffer} str Signature to verify. * @param {Array} [args] Array of additonal gpg arguments. * @param {Function} [fn] Callback containing the signed message Buffer. * @api public */ static verifySignature(str: string | Buffer, args: string[], fn: (err: Error, msg: Buffer, error: string) => void): void; /** * Add a key to the keychain by filename. * * @param {PathLike} fileName Key filename. * @param {Array} [args] Array of additonal gpg arguments. * @param {Function} [fn] Callback containing the signed message Buffer. * @api public */ static importKeyFromFile(fileName: PathLike, args: string[], fn: (err: Error | ErrnoException, msg: string, error: string) => void): void; /** * Add an ascii-armored key to gpg. Expects the key to be passed as input. * * @param {String | Buffer} keyStr Key string (armored). * @param {Array} args Optional additional arguments to pass to gpg. * @param {Function} fn Callback containing the signed message Buffer. * @api public */ static importKey(keyStr: string | Buffer, args: string[], fn: (err: Error, msg: string, error: string) => void): void; /** * Removes a key by fingerprint. Warning: this will remove both pub and privkeys! * * @param {String} keyID Key fingerprint. * @param {Array} [args] Array of additonal gpg arguments. * @param {Function} fn Callback containing the signed message Buffer. * @api public */ static removeKey(keyID: string, args: string[], fn: (err: Error, msg: Buffer, error: string) => void): void; }