Appease linter

This commit is contained in:
Daniel Huigens 2023-04-06 11:57:50 +02:00 committed by larabr
parent 33af3debc4
commit 21343f2bb8
4 changed files with 13 additions and 18 deletions

View File

@ -128,24 +128,21 @@ function verifyHeaders(headers) {
}
/**
* Splits a message into two parts, the body and the checksum. This is an internal function
* @param {String} text - OpenPGP armored message part
* @returns {Object} An object with attribute "body" containing the body.
* and an attribute "checksum" containing the checksum.
* Remove the (optional) checksum from an armored message.
* @param {String} text - OpenPGP armored message
* @returns {String} The body of the armored message.
* @private
*/
function splitChecksum(text) {
function removeChecksum(text) {
let body = text;
let checksum = '';
const lastEquals = text.lastIndexOf('=');
if (lastEquals >= 0 && lastEquals !== text.length - 1) { // '=' as the last char means no checksum
body = text.slice(0, lastEquals);
checksum = text.slice(lastEquals + 1).substr(0, 4);
}
return { body: body, checksum: checksum };
return body;
}
/**
@ -157,7 +154,7 @@ function splitChecksum(text) {
* @async
* @static
*/
export function unarmor(input, config = defaultConfig) {
export function unarmor(input) {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
try {
@ -170,8 +167,7 @@ export function unarmor(input, config = defaultConfig) {
let headersDone;
let text = [];
let textDone;
let checksum;
let data = base64.decode(stream.transformPair(input, async (readable, writable) => {
const data = base64.decode(stream.transformPair(input, async (readable, writable) => {
const reader = stream.getReader(readable);
try {
while (true) {
@ -236,9 +232,8 @@ export function unarmor(input, config = defaultConfig) {
if (parts.length === 1) {
throw new Error('Misformed armored text');
}
const split = splitChecksum(parts[0].slice(0, -1));
checksum = split.checksum;
await writer.write(split.body);
const body = removeChecksum(parts[0].slice(0, -1));
await writer.write(body);
break;
}
}

View File

@ -245,8 +245,8 @@ export class Message {
const serialisedPKESK = pkeskPacket.write(); // make copies to be able to decrypt the PKESK packet multiple times
await Promise.all((
expectedSymmetricAlgorithm ?
[expectedSymmetricAlgorithm] :
Array.from(config.constantTimePKCS1DecryptionSupportedSymmetricAlgorithms)
[expectedSymmetricAlgorithm] :
Array.from(config.constantTimePKCS1DecryptionSupportedSymmetricAlgorithms)
).map(async sessionKeyAlgorithm => {
const pkeskPacketCopy = new PublicKeyEncryptedSessionKeyPacket();
pkeskPacketCopy.read(serialisedPKESK);

View File

@ -37,7 +37,7 @@ class PaddingPacket {
* Read a padding packet
* @param {Uint8Array | ReadableStream<Uint8Array>} bytes
*/
read(bytes) {
read(bytes) { // eslint-disable-line no-unused-vars
// Padding packets are ignored, so this function is never called.
}

View File

@ -72,7 +72,7 @@ class SymEncryptedIntegrityProtectedDataPacket {
this.version = await reader.readByte();
// - A one-octet version number with value 1 or 2.
if (this.version !== 1 && this.version !== 2) {
throw new UnsupportedError(`Version ${version} of the SEIP packet is unsupported.`);
throw new UnsupportedError(`Version ${this.version} of the SEIP packet is unsupported.`);
}
if (this.version === 2) {