mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-11-26 07:25:51 +00:00
feat(fuzz): userId.fromObject
This commit is contained in:
parent
227c12cde4
commit
08cda81233
@ -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' });
|
||||
}
|
||||
|
||||
30
test/fuzz/userIdFromObject.js
Normal file
30
test/fuzz/userIdFromObject.js
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user