-PyDERASN -- ASN.1 DER library for Python
+PyDERASN -- ASN.1 DER/BER library for Python
I'm going to build my own ASN.1 library with slots and blobs!
(C) PyDERASN's author
+* BER/CER/DER decoding, DER encoding
* Basic ASN.1 data types (X.208): BOOLEAN, INTEGER, BIT STRING, OCTET
STRING, NULL, OBJECT IDENTIFIER, ENUMERATED, all strings, UTCTime,
GeneralizedTime, CHOICE, ANY, SEQUENCE (OF), SET (OF)
12 13 9 10
:0:
- Offset of the object, where its DER encoding begins.
+ Offset of the object, where its DER/BER encoding begins.
Pay attention that it does **not** include explicit tag.
:1:
If explicit tag exists, then this is its length (tag + encoded length).
As command line utility
-----------------------
-You can decode DER files using command line abilities and get the same
-picture as above by executing::
+You can decode DER/BER files using command line abilities and get the
+same picture as above by executing::
% python -m pyderasn --schema tests.test_crts:Certificate path/to/file
Descriptive errors
------------------
-If you have bad DER, then errors will show you where error occurred::
+If you have bad DER/BER, then errors will show you where error occurred::
% python -m pyderasn --schema tests.test_crts:Certificate path/to/bad/file
Traceback (most recent call last):
Features
========
+* BER/CER/DER decoding, DER encoding
* Basic ASN.1 data types (X.208): BOOLEAN, INTEGER, BIT STRING, OCTET
STRING, NULL, OBJECT IDENTIFIER, ENUMERATED, all strings, UTCTime,
GeneralizedTime, CHOICE, ANY, SEQUENCE (OF), SET (OF)
There are drawbacks:
* No old Python versions support
-* No BER/CER support
* PyDERASN does **not** have object recreation capable ``repr``-s::
pyderasn>>> repr(algo_id)
-========================================
-PyDERASN -- ASN.1 DER library for Python
-========================================
+============================================
+PyDERASN -- ASN.1 DER/BER library for Python
+============================================
..
(C) PyDERASN's author
`ASN.1 <https://en.wikipedia.org/wiki/ASN.1>`__ (Abstract Syntax
-Notation One) is a standard for abstract data serialization.
-`DER <https://en.wikipedia.org/wiki/Distinguished_Encoding_Rules>`__
-(Distinguished Encoding Rules) is a subset of encoding rules suitable
-and widely used in cryptography-related stuff. PyDERASN is yet another
-library for dealing with the data encoded that way. Although ASN.1 is
+Notation One) is a standard for abstract data serialization. PyDERASN is
+yet another library for dealing with ASN.1 structures, decoding them in
+`BER/CER/DER <https://en.wikipedia.org/wiki/X.690>`__ formats and
+encoding to DER (Distinguished Encoding Rules). Although ASN.1 is
written more than 30 years ago by wise Ancients (taken from ``pyasn1``'s
README), it is still often can be seen anywhere in our life.
News
====
+.. _release3.7:
+
+3.7
+---
+* Experimental BER decoding support (not extensively tested, but parses
+ ``gpgsm`` CMS output)
+* BitString's ''H notation support
+
.. _release3.6:
3.6
I am pleased to announce PyDERASN $release release availability!
-PyDERASN is free software pure Python ASN.1 DER library.
+PyDERASN is free software pure Python ASN.1 DER/BER library.
------------------------ >8 ------------------------
#!/usr/bin/env python
# coding: utf-8
-# PyDERASN -- Python ASN.1 DER codec with abstract structures
+# PyDERASN -- Python ASN.1 DER/BER codec with abstract structures
# Copyright (C) 2017-2018 Sergey Matveev <stargrave@stargrave.org>
#
# This program is free software: you can redistribute it and/or modify
# You should have received a copy of the GNU Lesser General Public
# License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
-"""Python ASN.1 DER codec with abstract structures
+"""Python ASN.1 DER/BER codec with abstract structures
-This library allows you to marshal and unmarshal various structures in
-ASN.1 DER format, like this:
+This library allows you to marshal various structures in ASN.1 DER
+format, unmarshal them in BER/CER/DER ones.
>>> i = Integer(123)
>>> raw = i.encode()
lesser than ``offset``), ``expl_tlen``, ``expl_llen``, ``expl_vlen``
(that actually equals to ordinary ``tlvlen``).
-When error occurs, then :py:exc:`pyderasn.DecodeError` is raised.
+When error occurs, :py:exc:`pyderasn.DecodeError` is raised.
.. _ctx:
Currently available context options:
+* :ref:`bered <bered_ctx>`
* :ref:`defines_by_path <defines_by_path_ctx>`
* :ref:`strict_default_existence <strict_default_existence_ctx>`
decoding is already done. ``any`` means literally any value it meet --
useful for SEQUENCE/SET OF-s.
+.. _bered_ctx:
+
+BER encoding
+------------
+
+.. warning::
+
+ Currently BER support is not extensively tested.
+
+By default PyDERASN accepts only DER encoded data. It always encodes to
+DER. But you can optionally enable BER decoding with setting ``bered``
+:ref:`context <ctx>` argument to True. Indefinite lengths and
+constructed primitive types should be parsed successfully.
+
+* If object is encoded in BER form (not the DER one), then ``bered``
+ attribute is set to True. Only ``BOOLEAN``, ``BIT STRING``, ``OCTET
+ STRING`` can contain it.
+* If object has an indefinite length encoding, then its ``lenindef``
+ attribute is set to True. Only ``BIT STRING``, ``OCTET STRING``,
+ ``SEQUENCE``, ``SET``, ``SEQUENCE OF``, ``SET OF``, ``ANY`` can
+ contain it.
+* If object has an indefinite length encoded explicit tag, then
+ ``expl_lenindef`` is set to True.
+
+EOC (end-of-contents) token's length is taken in advance in object's
+value length.
+
Primitive types
---------------
def main(): # pragma: no cover
import argparse
- parser = argparse.ArgumentParser(description="PyDERASN ASN.1 DER decoder")
+ parser = argparse.ArgumentParser(description="PyDERASN ASN.1 BER/DER decoder")
parser.add_argument(
"--skip",
type=int,
setup(
name="pyderasn",
version=version,
- description="Python ASN.1 DER codec with abstract structures",
+ description="Python ASN.1 DER/BER codec with abstract structures",
long_description=open("README", "rb").read().decode("utf-8"),
author="Sergey Matveev",
author_email="stargrave@stargrave.org",
# coding: utf-8
-# PyDERASN -- Python ASN.1 DER codec with abstract structures
+# PyDERASN -- Python ASN.1 DER/BER codec with abstract structures
# Copyright (C) 2017-2018 Sergey Matveev <stargrave@stargrave.org>
#
# This program is free software: you can redistribute it and/or modify