Skip to content

Commit

Permalink
feat(fuzz): userId.fromObject
Browse files Browse the repository at this point in the history
  • Loading branch information
hulkoba committed Dec 18, 2023
1 parent 227c12c commit 9c6c094
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
26 changes: 0 additions & 26 deletions test/fuzz/generateKey.js

This file was deleted.

30 changes: 30 additions & 0 deletions 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;
}
}
}

0 comments on commit 9c6c094

Please sign in to comment.