Rename vars [skip ci]

This commit is contained in:
larabr 2024-04-09 13:39:33 +02:00
parent 279dc07019
commit f1201ad607
8 changed files with 18 additions and 18 deletions

2
openpgp.d.ts vendored
View File

@ -735,7 +735,7 @@ export interface VerifyMessageResult<T extends MaybeStream<Data> = MaybeStream<D
/** /**
* Armor an OpenPGP binary packet block * Armor an OpenPGP binary packet block
*/ */
export function armor(messagetype: enums.armor, body: object, partindex?: number, parttotal?: number, customComment?: string, config?: Config): string; export function armor(messagetype: enums.armor, body: object, partindex?: number, parttotal?: number, customComment?: string, emitChecksum?: boolean, config?: Config): string;
/** /**
* DeArmor an OpenPGP armored message; verify the checksum and return the encoded bytes * DeArmor an OpenPGP armored message; verify the checksum and return the encoded bytes

View File

@ -111,9 +111,9 @@ export class CleartextMessage {
* @returns {String | ReadableStream<String>} ASCII armor. * @returns {String | ReadableStream<String>} ASCII armor.
*/ */
armor(config = defaultConfig) { armor(config = defaultConfig) {
const includesNonV6Signatures = this.signature.packets.some(packet => packet.version !== 6); // emit header and checksum if one of the signatures has a version not 6
// emit header if one of the signatures has a version not 6 const emitHeaderAndChecksum = this.signature.packets.some(packet => packet.version !== 6);
const hash = includesNonV6Signatures ? const hash = emitHeaderAndChecksum ?
Array.from(new Set(this.signature.packets.map( Array.from(new Set(this.signature.packets.map(
packet => enums.read(enums.hash, packet.hashAlgorithm).toUpperCase() packet => enums.read(enums.hash, packet.hashAlgorithm).toUpperCase()
))).join() : ))).join() :
@ -126,7 +126,7 @@ export class CleartextMessage {
}; };
// An ASCII-armored sequence of Signature packets that only includes v6 Signature packets MUST NOT contain a CRC24 footer. // An ASCII-armored sequence of Signature packets that only includes v6 Signature packets MUST NOT contain a CRC24 footer.
return armor(enums.armor.signed, body, undefined, undefined, undefined, includesNonV6Signatures, config); return armor(enums.armor.signed, body, undefined, undefined, undefined, emitHeaderAndChecksum, config);
} }
} }

View File

@ -334,13 +334,13 @@ export function unarmor(input) {
* @param {Integer} [partIndex] * @param {Integer} [partIndex]
* @param {Integer} [partTotal] * @param {Integer} [partTotal]
* @param {String} [customComment] - Additional comment to add to the armored string * @param {String} [customComment] - Additional comment to add to the armored string
* @param {Boolean} [withChecksum] - Whether to compute and include the CRC checksum * @param {Boolean} [emitChecksum] - Whether to compute and include the CRC checksum
* (NB: some types of data must not include it, but compliance is left as responsibility of the caller: this function does not carry out any checks) * (NB: some types of data must not include it, but compliance is left as responsibility of the caller: this function does not carry out any checks)
* @param {Object} [config] - Full configuration, defaults to openpgp.config * @param {Object} [config] - Full configuration, defaults to openpgp.config
* @returns {String | ReadableStream<String>} Armored text. * @returns {String | ReadableStream<String>} Armored text.
* @static * @static
*/ */
export function armor(messageType, body, partIndex, partTotal, customComment, withChecksum = false, config = defaultConfig) { export function armor(messageType, body, partIndex, partTotal, customComment, emitChecksum = false, config = defaultConfig) {
let text; let text;
let hash; let hash;
if (messageType === enums.armor.signed) { if (messageType === enums.armor.signed) {
@ -348,9 +348,9 @@ export function armor(messageType, body, partIndex, partTotal, customComment, wi
hash = body.hash; hash = body.hash;
body = body.data; body = body.data;
} }
// unless explicitly forbidden by the spec, we need to include the checksum to workaround an GnuPG bug // unless explicitly forbidden by the spec, we need to include the checksum to work around a GnuPG bug
// where data fails to be decoded if the base64 ends with no padding chars (=) (see https://dev.gnupg.org/T7071) // where data fails to be decoded if the base64 ends with no padding chars (=) (see https://dev.gnupg.org/T7071)
const maybeBodyClone = withChecksum && stream.passiveClone(body); const maybeBodyClone = emitChecksum && stream.passiveClone(body);
const result = []; const result = [];
switch (messageType) { switch (messageType) {

View File

@ -65,8 +65,8 @@ class PrivateKey extends PublicKey {
*/ */
armor(config = defaultConfig) { armor(config = defaultConfig) {
// An ASCII-armored Transferable Public Key packet sequence of a v6 key MUST NOT contain a CRC24 footer. // An ASCII-armored Transferable Public Key packet sequence of a v6 key MUST NOT contain a CRC24 footer.
const v6Key = this.keyPacket.version === 6; const emitChecksum = this.keyPacket.version !== 6;
return armor(enums.armor.privateKey, this.toPacketList().write(), undefined, undefined, undefined, !v6Key, config); return armor(enums.armor.privateKey, this.toPacketList().write(), undefined, undefined, undefined, emitChecksum, config);
} }
/** /**

View File

@ -62,8 +62,8 @@ class PublicKey extends Key {
*/ */
armor(config = defaultConfig) { armor(config = defaultConfig) {
// An ASCII-armored Transferable Public Key packet sequence of a v6 key MUST NOT contain a CRC24 footer. // An ASCII-armored Transferable Public Key packet sequence of a v6 key MUST NOT contain a CRC24 footer.
const v6Key = this.keyPacket.version === 6; const emitChecksum = this.keyPacket.version !== 6;
return armor(enums.armor.publicKey, this.toPacketList().write(), undefined, undefined, undefined, !v6Key, config); return armor(enums.armor.publicKey, this.toPacketList().write(), undefined, undefined, undefined, emitChecksum, config);
} }
} }

View File

@ -683,10 +683,10 @@ export class Message {
const trailingPacket = this.packets[this.packets.length - 1]; const trailingPacket = this.packets[this.packets.length - 1];
// An ASCII-armored Encrypted Message packet sequence that ends in an v2 SEIPD packet MUST NOT contain a CRC24 footer. // An ASCII-armored Encrypted Message packet sequence that ends in an v2 SEIPD packet MUST NOT contain a CRC24 footer.
// An ASCII-armored sequence of Signature packets that only includes v6 Signature packets MUST NOT contain a CRC24 footer. // An ASCII-armored sequence of Signature packets that only includes v6 Signature packets MUST NOT contain a CRC24 footer.
const includeArmorChecksum = trailingPacket.constructor.tag === SymEncryptedIntegrityProtectedDataPacket.tag ? const emitChecksum = trailingPacket.constructor.tag === SymEncryptedIntegrityProtectedDataPacket.tag ?
trailingPacket.version !== 2 : trailingPacket.version !== 2 :
this.packets.some(packet => packet.constructor.tag === SignaturePacket.tag && packet.version !== 6); this.packets.some(packet => packet.constructor.tag === SignaturePacket.tag && packet.version !== 6);
return armor(enums.armor.message, this.write(), null, null, null, includeArmorChecksum, config); return armor(enums.armor.message, this.write(), null, null, null, emitChecksum, config);
} }
} }

View File

@ -50,8 +50,8 @@ export class Signature {
*/ */
armor(config = defaultConfig) { armor(config = defaultConfig) {
// An ASCII-armored sequence of Signature packets that only includes v6 Signature packets MUST NOT contain a CRC24 footer. // An ASCII-armored sequence of Signature packets that only includes v6 Signature packets MUST NOT contain a CRC24 footer.
const includesNonV6Signatures = this.packets.some(packet => packet.constructor.tag === SignaturePacket.tag && packet.version !== 6); const emitChecksum = this.packets.some(packet => packet.constructor.tag === SignaturePacket.tag && packet.version !== 6);
return armor(enums.armor.signature, this.write(), undefined, undefined, undefined, includesNonV6Signatures, config); return armor(enums.armor.signature, this.write(), undefined, undefined, undefined, emitChecksum, config);
} }
/** /**

View File

@ -262,7 +262,7 @@ export default () => describe('ASCII armor', function() {
return (lastDataLine[0] === '=' && lastDataLine.length === 5); return (lastDataLine[0] === '=' && lastDataLine.length === 5);
}; };
// unless explicitly forbidden by the spec, we include the checksum to workaround an GnuPG bug (https://dev.gnupg.org/T7071) // unless explicitly forbidden by the spec, we include the checksum to work around a GnuPG bug (https://dev.gnupg.org/T7071)
const { privateKey: v4Key } = await openpgp.generateKey({ userIDs: { email: 'v4@armor.test' }, format: 'object' }); const { privateKey: v4Key } = await openpgp.generateKey({ userIDs: { email: 'v4@armor.test' }, format: 'object' });
expect(includesArmorChecksum(v4Key.armor())).to.be.true; expect(includesArmorChecksum(v4Key.armor())).to.be.true;
const { privateKey: v6Key } = await openpgp.generateKey({ userIDs: { email: 'v6@armor.test' }, config: { v6Keys: true, aeadProtect: true }, format: 'object' }); const { privateKey: v6Key } = await openpgp.generateKey({ userIDs: { email: 'v6@armor.test' }, config: { v6Keys: true, aeadProtect: true }, format: 'object' });