From f1201ad607f9cfbe04816d0de37bcf77ae2ed3e5 Mon Sep 17 00:00:00 2001 From: larabr <7375870+larabr@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:39:33 +0200 Subject: [PATCH] Rename vars [skip ci] --- openpgp.d.ts | 2 +- src/cleartext.js | 8 ++++---- src/encoding/armor.js | 8 ++++---- src/key/private_key.js | 4 ++-- src/key/public_key.js | 4 ++-- src/message.js | 4 ++-- src/signature.js | 4 ++-- test/general/armor.js | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/openpgp.d.ts b/openpgp.d.ts index 10c8d710..8801d0e3 100644 --- a/openpgp.d.ts +++ b/openpgp.d.ts @@ -735,7 +735,7 @@ export interface VerifyMessageResult = MaybeStream} ASCII armor. */ armor(config = defaultConfig) { - const includesNonV6Signatures = this.signature.packets.some(packet => packet.version !== 6); - // emit header if one of the signatures has a version not 6 - const hash = includesNonV6Signatures ? + // emit header and checksum if one of the signatures has a version not 6 + const emitHeaderAndChecksum = this.signature.packets.some(packet => packet.version !== 6); + const hash = emitHeaderAndChecksum ? Array.from(new Set(this.signature.packets.map( packet => enums.read(enums.hash, packet.hashAlgorithm).toUpperCase() ))).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. - return armor(enums.armor.signed, body, undefined, undefined, undefined, includesNonV6Signatures, config); + return armor(enums.armor.signed, body, undefined, undefined, undefined, emitHeaderAndChecksum, config); } } diff --git a/src/encoding/armor.js b/src/encoding/armor.js index ed0a6be4..5404d8f6 100644 --- a/src/encoding/armor.js +++ b/src/encoding/armor.js @@ -334,13 +334,13 @@ export function unarmor(input) { * @param {Integer} [partIndex] * @param {Integer} [partTotal] * @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) * @param {Object} [config] - Full configuration, defaults to openpgp.config * @returns {String | ReadableStream} Armored text. * @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 hash; if (messageType === enums.armor.signed) { @@ -348,9 +348,9 @@ export function armor(messageType, body, partIndex, partTotal, customComment, wi hash = body.hash; 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) - const maybeBodyClone = withChecksum && stream.passiveClone(body); + const maybeBodyClone = emitChecksum && stream.passiveClone(body); const result = []; switch (messageType) { diff --git a/src/key/private_key.js b/src/key/private_key.js index 94385420..904c09a0 100644 --- a/src/key/private_key.js +++ b/src/key/private_key.js @@ -65,8 +65,8 @@ class PrivateKey extends PublicKey { */ armor(config = defaultConfig) { // An ASCII-armored Transferable Public Key packet sequence of a v6 key MUST NOT contain a CRC24 footer. - const v6Key = this.keyPacket.version === 6; - return armor(enums.armor.privateKey, this.toPacketList().write(), undefined, undefined, undefined, !v6Key, config); + const emitChecksum = this.keyPacket.version !== 6; + return armor(enums.armor.privateKey, this.toPacketList().write(), undefined, undefined, undefined, emitChecksum, config); } /** diff --git a/src/key/public_key.js b/src/key/public_key.js index cada0ef1..7996a32c 100644 --- a/src/key/public_key.js +++ b/src/key/public_key.js @@ -62,8 +62,8 @@ class PublicKey extends Key { */ armor(config = defaultConfig) { // An ASCII-armored Transferable Public Key packet sequence of a v6 key MUST NOT contain a CRC24 footer. - const v6Key = this.keyPacket.version === 6; - return armor(enums.armor.publicKey, this.toPacketList().write(), undefined, undefined, undefined, !v6Key, config); + const emitChecksum = this.keyPacket.version !== 6; + return armor(enums.armor.publicKey, this.toPacketList().write(), undefined, undefined, undefined, emitChecksum, config); } } diff --git a/src/message.js b/src/message.js index e43162df..113d5623 100644 --- a/src/message.js +++ b/src/message.js @@ -683,10 +683,10 @@ export class Message { 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 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 : 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); } } diff --git a/src/signature.js b/src/signature.js index 6a03d8bb..f3e14e85 100644 --- a/src/signature.js +++ b/src/signature.js @@ -50,8 +50,8 @@ export class Signature { */ armor(config = defaultConfig) { // 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); - return armor(enums.armor.signature, this.write(), undefined, undefined, undefined, includesNonV6Signatures, config); + const emitChecksum = this.packets.some(packet => packet.constructor.tag === SignaturePacket.tag && packet.version !== 6); + return armor(enums.armor.signature, this.write(), undefined, undefined, undefined, emitChecksum, config); } /** diff --git a/test/general/armor.js b/test/general/armor.js index 870f4669..01df7c05 100644 --- a/test/general/armor.js +++ b/test/general/armor.js @@ -262,7 +262,7 @@ export default () => describe('ASCII armor', function() { 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' }); 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' });