Skip to content

Commit 509447a

Browse files
author
434b
committed
First approach to for a toggable printableStringConsumer
1 parent 28a1259 commit 509447a

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

packages/core/FuzzedDataProvider.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -404,28 +404,15 @@ export class FuzzedDataProvider {
404404
return result;
405405
}
406406

407-
/**
408-
* Wrapping subtraction function that returns a number within a set limit
409-
* @param min is a number representing the minuend
410-
* @param sub is a number representing the subtrahend
411-
* @param lim sets the upper boundary
412-
* @returns a number n with the constraint 0 <= n < lim, as long as lim >=2
413-
*/
414-
wrappingSub(min: number, sub: number, lim: number): number {
415-
if (lim < 2) {
416-
throw new Error("Upper boundary should be greater than or equal to 2");
417-
}
418-
return (min - sub + lim) % lim;
419-
}
420-
421407
/**
422408
* A simple conversion helper that yields the ASCII representaion of a character.
423409
* @param char is a single character from a string represented as a number
424410
* @returns a 'string' from a single character that was represented by a number
425411
*/
426412
toAscii(char: number): number {
427413
if (char < 32 || char > 126) {
428-
char = (this.wrappingSub(char, 32, 255) % 95) + 32;
414+
const moduloInRange = (char - 32 + 256) % 256;
415+
return (moduloInRange % 95) + 32;
429416
}
430417
return char;
431418
}
@@ -436,6 +423,8 @@ export class FuzzedDataProvider {
436423
* (non-smart) but printable strings, IFF the entropy of the input buffer is
437424
* high enough. Limitations are that there are collisions such that, e.g.:
438425
* the conversion of values: `0x1`, `0x42`, and `0xa2` all yield the character `B`.
426+
* Elements in `buf` that are already in ASCII printable range are not undergoing
427+
* any conversion.
439428
* @param buf - Buffer that contains arbitrary values
440429
* @param min - lower bound at which processing of the provided `Buffer` shall begin
441430
* @param max - upper bound, analogous to the lower bound

0 commit comments

Comments
 (0)