openpgpjs/test/fuzz/readKeyBinary.js
hulkoba 4c0a324980
test(fuzz): turn everything into esm
since coverage does not work as expected at all, we can use esm. So if jazzer at some point, add esm support for esm, we can easily add it
2023-12-13 15:09:46 +01:00

23 lines
611 B
JavaScript

import openpgp from '../initOpenpgp.js';
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
*/
export function fuzz (inputData) {
const binaryKey = new Uint8Array(`-----BEGIN PGP PRIVATE KEY BLOCK-----\n ${inputData.toString('base64')} -----END PGP PRIVATE KEY BLOCK-----`);
return openpgp.readKey({ binaryKey })
.catch(error => {
if (error.message && !ignoredError(error)) {
throw error;
}
});
}