summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Matveev <stargrave@stargrave.org>2020-02-14 17:34:18 +0300
committerSergey Matveev <stargrave@stargrave.org>2020-02-16 21:25:49 +0300
commite9ab3a6d6679d825d0e48523cec13ff710f0220d (patch)
tree055189f7e18185843d0682a91ab2b89bfcd23834
parent71e8cd567991a1ea9d32f86739a5183aef0677f6 (diff)
downloadpyderasn-e9ab3a6d6679d825d0e48523cec13ff710f0220d.tar.xz
CLI --evgen
-rw-r--r--doc/news.rst3
-rwxr-xr-xpyderasn.py21
2 files changed, 18 insertions, 6 deletions
diff --git a/doc/news.rst b/doc/news.rst
index 7e11078..5665a42 100644
--- a/doc/news.rst
+++ b/doc/news.rst
@@ -15,7 +15,8 @@ News
encoded representation storage
* Initial support for so called ``evgen_mode``: event generation mode,
where no in-memory objects storing happens, giving ability to process
- ASN.1 data without fully parsing it first
+ ASN.1 data without fully parsing it first. ``python -m pyderasn`` has
+ ``--evgen`` mode switcher
* Initial experimental CER encoding mode, allowing streaming encoding of
the data directly to some writeable object
* Ability to use mmap-ed memoryviews to skip files loading to memory
diff --git a/pyderasn.py b/pyderasn.py
index 002f060..fe1d4ab 100755
--- a/pyderasn.py
+++ b/pyderasn.py
@@ -1943,6 +1943,7 @@ def pprint(
with_colours=False,
with_decode_path=False,
decode_path_only=(),
+ decode_path=(),
):
"""Pretty print object
@@ -1995,7 +1996,7 @@ def pprint(
else:
for row in _pprint_pps(pp):
yield row
- return "\n".join(_pprint_pps(obj.pps()))
+ return "\n".join(_pprint_pps(obj.pps(decode_path)))
########################################################################
@@ -6707,6 +6708,11 @@ def main(): # pragma: no cover
help="Allow explicit tag out-of-bound",
)
parser.add_argument(
+ "--evgen",
+ action="store_true",
+ help="Turn on event generation mode",
+ )
+ parser.add_argument(
"RAWFile",
type=argparse.FileType("rb"),
help="Path to BER/CER/DER file you want to decode",
@@ -6734,10 +6740,9 @@ def main(): # pragma: no cover
}
if args.defines_by_path is not None:
ctx["defines_by_path"] = obj_by_path(args.defines_by_path)
- obj, tail = schema().decode(raw, ctx=ctx)
from os import environ
- print(pprinter(
- obj,
+ pprinter = partial(
+ pprinter,
oid_maps=oid_maps,
with_colours=environ.get("NO_COLOR") is None,
with_decode_path=args.print_decode_path,
@@ -6745,7 +6750,13 @@ def main(): # pragma: no cover
() if args.decode_path_only is None else
tuple(args.decode_path_only.split(":"))
),
- ))
+ )
+ if args.evgen:
+ for decode_path, obj, tail in schema().decode_evgen(raw, ctx=ctx):
+ print(pprinter(obj, decode_path=decode_path))
+ else:
+ obj, tail = schema().decode(raw, ctx=ctx)
+ print(pprinter(obj))
if tail != b"":
print("\nTrailing data: %s" % hexenc(tail))