feat(fuzz): userId.fromObject

This commit is contained in:
hulkoba 2023-12-18 10:43:46 +01:00
parent 227c12cde4
commit 08cda81233
No known key found for this signature in database
GPG Key ID: ACB6C4A3A4F2BE2F
2 changed files with 30 additions and 26 deletions

View File

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

View File

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