src/cleartext.js
function verifyHeaders(headers, packetlist) {
  const checkHashAlgos = function(hashAlgos) {
    const check = packet => algo => packet.hashAlgorithm === algo;

    for (let i = 0; i < packetlist.length; i++) {
      if (packetlist[i].tag === enums.packet.signature && !hashAlgos.some(check(packetlist[i]))) {
        return false;
      }
    }
    return true;
  };

  let oneHeader = null;
  let hashAlgos = [];
  headers.forEach(function(header) {
    oneHeader = header.match(/Hash: (.+)/); // get header value
    if (oneHeader) {
      oneHeader = oneHeader[1].replace(/\s/g, ''); // remove whitespace
      oneHeader = oneHeader.split(',');
      oneHeader = oneHeader.map(function(hash) {
        hash = hash.toLowerCase();
        try {
          return enums.write(enums.hash, hash);
        } catch (e) {
          throw new Error('Unknown hash algorithm in armor header: ' + hash);
        }
      });
      hashAlgos = hashAlgos.concat(oneHeader);
    } else {
      throw new Error('Only "Hash" header allowed in cleartext signed message');
    }
  });

  if (!hashAlgos.length && !checkHashAlgos([enums.hash.md5])) {
    throw new Error('If no "Hash" header in cleartext signed message, then only MD5 signatures allowed');
  } else if (hashAlgos.length && !checkHashAlgos(hashAlgos)) {
    throw new Error('Hash algorithm mismatch in armor header and signature');
  }
}
function verifyHeaders(headers, packetlist) {
  const checkHashAlgos = function(hashAlgos) {
    const check = packet => algo => packet.hashAlgorithm === algo;

    for (let i = 0; i < packetlist.length; i++) {
      if (packetlist[i].tag === enums.packet.signature && !hashAlgos.some(check(packetlist[i]))) {
        return false;
      }
    }
    return true;
  };

  let oneHeader = null;
  let hashAlgos = [];
  headers.forEach(function(header) {
    oneHeader = header.match(/Hash: (.+)/); // get header value
    if (oneHeader) {
      oneHeader = oneHeader[1].replace(/\s/g, ''); // remove whitespace
      oneHeader = oneHeader.split(',');
      oneHeader = oneHeader.map(function(hash) {
        hash = hash.toLowerCase();
        try {
          return enums.write(enums.hash, hash);
        } catch (e) {
          throw new Error('Unknown hash algorithm in armor header: ' + hash);
        }
      });
      hashAlgos = hashAlgos.concat(oneHeader);
    } else {
      throw new Error('Only "Hash" header allowed in cleartext signed message');
    }
  });

  if (!hashAlgos.length && !checkHashAlgos([enums.hash.md5])) {
    throw new Error('If no "Hash" header in cleartext signed message, then only MD5 signatures allowed');
  } else if (hashAlgos.length && !checkHashAlgos(hashAlgos)) {
    throw new Error('Hash algorithm mismatch in armor header and signature');
  }
}
function verifyHeaders ( headers , packetlist ) { const checkHashAlgos = function ( hashAlgos ) { const check = packet => algo => packet . hashAlgorithm === algo ; for ( let i = 0 ; i < packetlist . length ; i ++ ) { if ( packetlist [ i ] . tag === enums . packet . signature && ! hashAlgos . some ( check ( packetlist [ i ] ) ) ) { return false ; } } return true ; } ; let oneHeader = null ; let hashAlgos = [ ] ; headers . forEach ( function ( header ) { oneHeader = header . match ( / Hash: (.+) / ) ; // get header value if ( oneHeader ) { oneHeader = oneHeader [ 1 ] . replace ( / \s / g , '' ) ; // remove whitespace oneHeader = oneHeader . split ( ',' ) ; oneHeader = oneHeader . map ( function ( hash ) { hash = hash . toLowerCase ( ) ; try { return enums . write ( enums . hash , hash ) ; } catch ( e ) { throw new Error ( 'Unknown hash algorithm in armor header: ' + hash ) ; } } ) ; hashAlgos = hashAlgos . concat ( oneHeader ) ; } else { throw new Error ( 'Only "Hash" header allowed in cleartext signed message' ) ; } } ) ; if ( ! hashAlgos . length && ! checkHashAlgos ( [ enums . hash . md5 ] ) ) { throw new Error ( 'If no "Hash" header in cleartext signed message, then only MD5 signatures allowed' ) ; } else if ( hashAlgos . length && ! checkHashAlgos ( hashAlgos ) ) { throw new Error ( 'Hash algorithm mismatch in armor header and signature' ) ; } }
Compare hash algorithm specified in the armor header with signatures
@param  {Array<String>} headers    Armor headers
@param  {module:packet.List} packetlist The packetlist with signature packets
@private
Compare hash algorithm specified in the armor header with signatures