diff --git a/test/fuzz/generateKey.js b/test/fuzz/generateKey.js deleted file mode 100644 index c192fcb0d..000000000 --- a/test/fuzz/generateKey.js +++ /dev/null @@ -1,26 +0,0 @@ -import { FuzzedDataProvider } from '@jazzer.js/core'; - -import { generateKey } from 'openpgp'; - -const MAX_NAME_LENGTH = 30; -const MAX_COMMENT_LENGTH = 500; - -/** - * @param { Buffer } inputData - */ -export function fuzz (inputData) { - - const data = new FuzzedDataProvider(inputData); - const asciiString = data.consumeString(MAX_COMMENT_LENGTH); - const utf8String = data.consumeString(MAX_NAME_LENGTH, 'utf-8'); - - return generateKey({ userIDs: [ - { name: utf8String }, - { email: utf8String }, - { comment: asciiString }, - { name: utf8String, email: utf8String, comment: asciiString } - ], - passphrase: asciiString, - format: 'object' }); -} - diff --git a/test/fuzz/userIdFromObject.js b/test/fuzz/userIdFromObject.js new file mode 100644 index 000000000..c7196b55e --- /dev/null +++ b/test/fuzz/userIdFromObject.js @@ -0,0 +1,30 @@ +import { FuzzedDataProvider } from '@jazzer.js/core'; + +import { UserIDPacket } from 'openpgp'; + +const expected = ['Invalid user ID format']; + +function ignoredError(error) { + return expected.some(message => error.message.includes(message)); +} + +const MAX_NAME_LENGTH = 30; +const MAX_COMMENT_LENGTH = 500; + +/** + * @param { Buffer } inputData + */ +export function fuzz (inputData) { + const data = new FuzzedDataProvider(inputData); + const asciiString = data.consumeString(MAX_COMMENT_LENGTH); + const utf8String = data.consumeString(MAX_NAME_LENGTH, 'utf-8'); + + try { + return UserIDPacket.fromObject({ name: utf8String, email: utf8String, comment: asciiString }); + } catch (error) { + if (error.message && !ignoredError(error)) { + throw error; + } + } +} +