X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=pyderasn.py;h=885f816b2097c93589d9cc2e44af0cc2c5ac5961;hb=eb67733960022e82168120c03b5c0e81272ddb2b;hp=3ed23da12c2fb486359224fc1275413b9da44980;hpb=dc78d31d6f27b6cbcfafe8973257a3acb0ce692c;p=pyderasn.git diff --git a/pyderasn.py b/pyderasn.py index 3ed23da..885f816 100755 --- a/pyderasn.py +++ b/pyderasn.py @@ -289,7 +289,7 @@ Following types can be automatically decoded (DEFINED BY): * :py:class:`pyderasn.BitString` (that is multiple of 8 bits) * :py:class:`pyderasn.OctetString` * :py:class:`pyderasn.SequenceOf`/:py:class:`pyderasn.SetOf` - ``Any``/``OctetString``-s + ``Any``/``BitString``/``OctetString``-s When any of those fields is automatically decoded, then ``.defined`` attribute contains ``(OID, value)`` tuple. ``OID`` tells by which OID it @@ -472,6 +472,7 @@ from collections import namedtuple from collections import OrderedDict from datetime import datetime from math import ceil +from os import environ from six import add_metaclass from six import binary_type @@ -1130,9 +1131,9 @@ def pp_console_row( ): cols.append(_colorize("%s:" % oids[value], "green", with_colours)) else: - cols.append(_colorize("%s:" % value, "white", with_colours)) + cols.append(_colorize("%s:" % value, "white", with_colours, ("reverse",))) else: - cols.append(_colorize("%s:" % ent, "yellow", with_colours)) + cols.append(_colorize("%s:" % ent, "yellow", with_colours, ("reverse",))) if pp.expl is not None: klass, _, num = pp.expl col = "[%s%d] EXPLICIT" % (TagClassReprs[klass], num) @@ -1146,7 +1147,7 @@ def pp_console_row( cols.append(_colorize(pp.asn1_type_name, "cyan", with_colours)) if pp.value is not None: value = pp.value - cols.append(_colorize(value, "white", with_colours)) + cols.append(_colorize(value, "white", with_colours, ("reverse",))) if ( oids is not None and pp.asn1_type_name == ObjectIdentifier.asn1_type_name and @@ -2013,7 +2014,7 @@ class BitString(Obj): decode_path=decode_path, offset=offset, ) - if byte2int(v[-1:]) & ((1 << pad_size) - 1) != 0: + if byte2int(v[l - 1:l]) & ((1 << pad_size) - 1) != 0: raise DecodeError( "invalid pad", klass=self.__class__, @@ -4499,11 +4500,6 @@ def main(): # pragma: no cover "--defines-by-path", help="Python path to decoder's defines_by_path", ) - parser.add_argument( - "--with-colours", - action='store_true', - help="Enable coloured output", - ) parser.add_argument( "DERFile", type=argparse.FileType("rb"), @@ -4530,7 +4526,7 @@ def main(): # pragma: no cover print(pprinter( obj, oids=oids, - with_colours=True if args.with_colours else False, + with_colours=True if environ.get("NO_COLOR") is None else False, )) if tail != b"": print("\nTrailing data: %s" % hexenc(tail))