forked from hiero-ledger/hiero-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeys_fuzzer.py
More file actions
45 lines (33 loc) · 1.16 KB
/
Copy pathkeys_fuzzer.py
File metadata and controls
45 lines (33 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Atheris fuzz target: PrivateKey and PublicKey parsing."""
from __future__ import annotations
import sys
import warnings
import atheris
with atheris.instrument_imports():
from hiero_sdk_python import PrivateKey, PublicKey
def _quiet(fn, *args):
"""Call *fn* with *args*, suppressing UserWarning."""
with warnings.catch_warnings():
warnings.simplefilter("ignore", UserWarning)
return fn(*args)
def TestOneInput(data: bytes) -> None:
"""Feed arbitrary bytes/strings into key parsers."""
fdp = atheris.FuzzedDataProvider(data)
choice = fdp.ConsumeIntInRange(0, 3)
try:
if choice == 0:
text = fdp.ConsumeUnicodeNoSurrogates(256)
_quiet(PrivateKey.from_string, text)
elif choice == 1:
raw = fdp.ConsumeBytes(128)
_quiet(PrivateKey.from_bytes, raw)
elif choice == 2:
text = fdp.ConsumeUnicodeNoSurrogates(256)
_quiet(PublicKey.from_string, text)
else:
raw = fdp.ConsumeBytes(128)
_quiet(PublicKey.from_bytes, raw)
except ValueError:
pass
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()