src/encoding/armor.js
function armor(messagetype, body, partindex, parttotal, customComment) {
  let text;
  let hash;
  if (messagetype === enums.armor.signed) {
    text = body.text;
    hash = body.hash;
    body = body.data;
  }
  const bodyClone = stream.passiveClone(body);
  const result = [];
  switch (messagetype) {
    case enums.armor.multipart_section:
      result.push("-----BEGIN PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n");
      result.push(addheader(customComment));
      result.push(base64.encode(body));
      result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
      result.push("-----END PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n");
      break;
    case enums.armor.multipart_last:
      result.push("-----BEGIN PGP MESSAGE, PART " + partindex + "-----\r\n");
      result.push(addheader(customComment));
      result.push(base64.encode(body));
      result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
      result.push("-----END PGP MESSAGE, PART " + partindex + "-----\r\n");
      break;
    case enums.armor.signed:
      result.push("\r\n-----BEGIN PGP SIGNED MESSAGE-----\r\n");
      result.push("Hash: " + hash + "\r\n\r\n");
      result.push(text.replace(/^-/mg, "- -"));
      result.push("\r\n-----BEGIN PGP SIGNATURE-----\r\n");
      result.push(addheader(customComment));
      result.push(base64.encode(body));
      result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
      result.push("-----END PGP SIGNATURE-----\r\n");
      break;
    case enums.armor.message:
      result.push("-----BEGIN PGP MESSAGE-----\r\n");
      result.push(addheader(customComment));
      result.push(base64.encode(body));
      result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
      result.push("-----END PGP MESSAGE-----\r\n");
      break;
    case enums.armor.public_key:
      result.push("-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n");
      result.push(addheader(customComment));
      result.push(base64.encode(body));
      result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
      result.push("-----END PGP PUBLIC KEY BLOCK-----\r\n");
      break;
    case enums.armor.private_key:
      result.push("-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n");
      result.push(addheader(customComment));
      result.push(base64.encode(body));
      result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
      result.push("-----END PGP PRIVATE KEY BLOCK-----\r\n");
      break;
    case enums.armor.signature:
      result.push("-----BEGIN PGP SIGNATURE-----\r\n");
      result.push(addheader(customComment));
      result.push(base64.encode(body));
      result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
      result.push("-----END PGP SIGNATURE-----\r\n");
      break;
  }

  return util.concat(result);
}
function armor(messagetype, body, partindex, parttotal, customComment) {
  let text;
  let hash;
  if (messagetype === enums.armor.signed) {
    text = body.text;
    hash = body.hash;
    body = body.data;
  }
  const bodyClone = stream.passiveClone(body);
  const result = [];
  switch (messagetype) {
    case enums.armor.multipart_section:
      result.push("-----BEGIN PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n");
      result.push(addheader(customComment));
      result.push(base64.encode(body));
      result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
      result.push("-----END PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n");
      break;
    case enums.armor.multipart_last:
      result.push("-----BEGIN PGP MESSAGE, PART " + partindex + "-----\r\n");
      result.push(addheader(customComment));
      result.push(base64.encode(body));
      result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
      result.push("-----END PGP MESSAGE, PART " + partindex + "-----\r\n");
      break;
    case enums.armor.signed:
      result.push("\r\n-----BEGIN PGP SIGNED MESSAGE-----\r\n");
      result.push("Hash: " + hash + "\r\n\r\n");
      result.push(text.replace(/^-/mg, "- -"));
      result.push("\r\n-----BEGIN PGP SIGNATURE-----\r\n");
      result.push(addheader(customComment));
      result.push(base64.encode(body));
      result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
      result.push("-----END PGP SIGNATURE-----\r\n");
      break;
    case enums.armor.message:
      result.push("-----BEGIN PGP MESSAGE-----\r\n");
      result.push(addheader(customComment));
      result.push(base64.encode(body));
      result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
      result.push("-----END PGP MESSAGE-----\r\n");
      break;
    case enums.armor.public_key:
      result.push("-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n");
      result.push(addheader(customComment));
      result.push(base64.encode(body));
      result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
      result.push("-----END PGP PUBLIC KEY BLOCK-----\r\n");
      break;
    case enums.armor.private_key:
      result.push("-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n");
      result.push(addheader(customComment));
      result.push(base64.encode(body));
      result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
      result.push("-----END PGP PRIVATE KEY BLOCK-----\r\n");
      break;
    case enums.armor.signature:
      result.push("-----BEGIN PGP SIGNATURE-----\r\n");
      result.push(addheader(customComment));
      result.push(base64.encode(body));
      result.push("\r\n=", getCheckSum(bodyClone), "\r\n");
      result.push("-----END PGP SIGNATURE-----\r\n");
      break;
  }

  return util.concat(result);
}
function armor ( messagetype , body , partindex , parttotal , customComment ) { let text ; let hash ; if ( messagetype === enums . armor . signed ) { text = body . text ; hash = body . hash ; body = body . data ; } const bodyClone = stream . passiveClone ( body ) ; const result = [ ] ; switch ( messagetype ) { case enums . armor . multipart_section : result . push ( "-----BEGIN PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n" ) ; result . push ( addheader ( customComment ) ) ; result . push ( base64 . encode ( body ) ) ; result . push ( "\r\n=" , getCheckSum ( bodyClone ) , "\r\n" ) ; result . push ( "-----END PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n" ) ; break ; case enums . armor . multipart_last : result . push ( "-----BEGIN PGP MESSAGE, PART " + partindex + "-----\r\n" ) ; result . push ( addheader ( customComment ) ) ; result . push ( base64 . encode ( body ) ) ; result . push ( "\r\n=" , getCheckSum ( bodyClone ) , "\r\n" ) ; result . push ( "-----END PGP MESSAGE, PART " + partindex + "-----\r\n" ) ; break ; case enums . armor . signed : result . push ( "\r\n-----BEGIN PGP SIGNED MESSAGE-----\r\n" ) ; result . push ( "Hash: " + hash + "\r\n\r\n" ) ; result . push ( text . replace ( / ^- / mg , "- -" ) ) ; result . push ( "\r\n-----BEGIN PGP SIGNATURE-----\r\n" ) ; result . push ( addheader ( customComment ) ) ; result . push ( base64 . encode ( body ) ) ; result . push ( "\r\n=" , getCheckSum ( bodyClone ) , "\r\n" ) ; result . push ( "-----END PGP SIGNATURE-----\r\n" ) ; break ; case enums . armor . message : result . push ( "-----BEGIN PGP MESSAGE-----\r\n" ) ; result . push ( addheader ( customComment ) ) ; result . push ( base64 . encode ( body ) ) ; result . push ( "\r\n=" , getCheckSum ( bodyClone ) , "\r\n" ) ; result . push ( "-----END PGP MESSAGE-----\r\n" ) ; break ; case enums . armor . public_key : result . push ( "-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n" ) ; result . push ( addheader ( customComment ) ) ; result . push ( base64 . encode ( body ) ) ; result . push ( "\r\n=" , getCheckSum ( bodyClone ) , "\r\n" ) ; result . push ( "-----END PGP PUBLIC KEY BLOCK-----\r\n" ) ; break ; case enums . armor . private_key : result . push ( "-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n" ) ; result . push ( addheader ( customComment ) ) ; result . push ( base64 . encode ( body ) ) ; result . push ( "\r\n=" , getCheckSum ( bodyClone ) , "\r\n" ) ; result . push ( "-----END PGP PRIVATE KEY BLOCK-----\r\n" ) ; break ; case enums . armor . signature : result . push ( "-----BEGIN PGP SIGNATURE-----\r\n" ) ; result . push ( addheader ( customComment ) ) ; result . push ( base64 . encode ( body ) ) ; result . push ( "\r\n=" , getCheckSum ( bodyClone ) , "\r\n" ) ; result . push ( "-----END PGP SIGNATURE-----\r\n" ) ; break ; } return util . concat ( result ) ; }
Armor an OpenPGP binary packet block
@param {Integer} messagetype type of the message
@param body
@param {Integer} partindex
@param {Integer} parttotal
@param {String} customComment (optional) additional comment to add to the armored string
@returns {String | ReadableStream<String>} Armored text
@static
Armor an OpenPGP binary packet block