openpgpjs/test/fuzz/readKeyBinary.cjs
2023-12-13 14:56:27 +01:00

23 lines
634 B
JavaScript

const ignored = ['This message / key probably does not conform to a valid OpenPGP format'];
function ignoredError(error) {
return ignored.some(message => error.message.includes(message));
}
/**
* @param { Buffer } inputData
*/
module.exports.fuzz = function(inputData) {
import('../initOpenpgp.js').then(openpgp => {
const binaryKey = new Uint8Array(`-----BEGIN PGP PRIVATE KEY BLOCK----- ${inputData} -----END PGP PRIVATE KEY BLOCK-----`);
return openpgp.default.readKey({ binaryKey })
.catch(error => {
if (error.message && !ignoredError(error)) {
throw error;
}
});
});
};