add gpg helper

This commit is contained in:
b1ek 2023-02-24 20:07:55 +10:00
parent 03f71c7951
commit 601f70510e
Signed by: blek
GPG Key ID: 14546221E3595D0C
1 changed files with 16 additions and 0 deletions

16
helpers/gpg.js Normal file
View File

@ -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 };