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
49 lines (32 loc) · 1.19 KB
/
Copy pathkeys_fuzzer.py
File metadata and controls
49 lines (32 loc) · 1.19 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
46
47
48
49
from __future__ import annotations
import sys
import warnings
import atheris
from cryptography.exceptions import UnsupportedAlgorithm
with atheris.instrument_imports():
from hiero_sdk_python import PrivateKey, PublicKey
EXPECTED_EXCEPTIONS = (TypeError, UnsupportedAlgorithm, ValueError)
BYTE_PARSERS = (PrivateKey.from_bytes, PublicKey.from_bytes)
STRING_PARSERS = (PrivateKey.from_string, PublicKey.from_string)
def _try_parse(parser, value: bytes | str) -> None:
try:
parser(value)
except EXPECTED_EXCEPTIONS:
return
def TestOneInput(data: bytes) -> None:
provider = atheris.FuzzedDataProvider(data)
raw_bytes = provider.ConsumeBytes(512)
raw_text = provider.ConsumeUnicodeNoSurrogates(1024)
hex_text = raw_bytes.hex()
with warnings.catch_warnings():
warnings.simplefilter("ignore", UserWarning)
for parser in BYTE_PARSERS:
_try_parse(parser, raw_bytes)
for candidate in (raw_text, hex_text, f"0x{hex_text}"):
for parser in STRING_PARSERS:
_try_parse(parser, candidate)
def main() -> None:
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()
if __name__ == "__main__":
main()