diff --git a/helpers/gpg.js b/helpers/gpg.js new file mode 100644 index 0000000..18bfad7 --- /dev/null +++ b/helpers/gpg.js @@ -0,0 +1,16 @@ + +/** + * Extract a message from a GPG/PGP signed message + * @param {string} signed + * @returns string + */ +function extract(signed) { + let extract = signed; + extract = extract.replace(/(?<=-----BEGIN PGP SIGNED MESSAGE-----)\r{0,1}\n(.*: .*)(\r{0,1}\n){2}/gm, ''); + extract = extract.replace(/-----BEGIN PGP SIGNATURE-----(.|\r{0,1}\n)*-----END PGP SIGNATURE-----/gm, ''); + extract = extract.replace('-----BEGIN PGP SIGNED MESSAGE-----', ''); + extract = extract.replace(/(\n\n)$/gm, ''); + return extract; +} + +module.exports = { extract }; \ No newline at end of file