| 1 |
Metadata-Version: 2.4 |
| 2 |
Name: pyasn1 |
| 3 |
Version: 0.6.3 |
| 4 |
Summary: Pure-Python implementation of ASN.1 types and DER/BER/CER codecs (X.208) |
| 5 |
Author-email: Ilya Etingof <[email protected]> |
| 6 |
Maintainer: pyasn1 maintenance organization |
| 7 |
Maintainer-email: Christian Heimes <[email protected]> |
| 8 |
License: BSD-2-Clause |
| 9 |
Project-URL: Homepage, https://github.com/pyasn1/pyasn1 |
| 10 |
Project-URL: Documentation, https://pyasn1.readthedocs.io |
| 11 |
Project-URL: Source, https://github.com/pyasn1/pyasn1 |
| 12 |
Project-URL: Issues, https://github.com/pyasn1/pyasn1/issues |
| 13 |
Project-URL: Changelog, https://pyasn1.readthedocs.io/en/latest/changelog.html |
| 14 |
Platform: any |
| 15 |
Classifier: Development Status :: 5 - Production/Stable |
| 16 |
Classifier: Environment :: Console |
| 17 |
Classifier: Intended Audience :: Developers |
| 18 |
Classifier: Intended Audience :: Education |
| 19 |
Classifier: Intended Audience :: Information Technology |
| 20 |
Classifier: Intended Audience :: System Administrators |
| 21 |
Classifier: Intended Audience :: Telecommunications Industry |
| 22 |
Classifier: Natural Language :: English |
| 23 |
Classifier: Operating System :: OS Independent |
| 24 |
Classifier: Programming Language :: Python :: 3 |
| 25 |
Classifier: Programming Language :: Python :: 3.8 |
| 26 |
Classifier: Programming Language :: Python :: 3.9 |
| 27 |
Classifier: Programming Language :: Python :: 3.10 |
| 28 |
Classifier: Programming Language :: Python :: 3.11 |
| 29 |
Classifier: Programming Language :: Python :: 3.12 |
| 30 |
Classifier: Programming Language :: Python :: 3.13 |
| 31 |
Classifier: Programming Language :: Python :: 3.14 |
| 32 |
Classifier: Programming Language :: Python :: Implementation :: CPython |
| 33 |
Classifier: Programming Language :: Python :: Implementation :: PyPy |
| 34 |
Classifier: Topic :: Communications |
| 35 |
Classifier: Topic :: Software Development :: Libraries :: Python Modules |
| 36 |
Requires-Python: >=3.8 |
| 37 |
Description-Content-Type: text/markdown |
| 38 |
License-File: LICENSE.rst |
| 39 |
Dynamic: license-file |
| 40 |
|
| 41 |
|
| 42 |
ASN.1 library for Python |
| 43 |
------------------------ |
| 44 |
[](https://pypi.org/project/pyasn1) |
| 45 |
[](https://pypi.org/project/pyasn1/) |
| 46 |
[](https://github.com/pyasn1/pyasn1/actions/workflows/main.yml) |
| 47 |
[](https://codecov.io/github/pyasn1/pyasn1) |
| 48 |
[](https://raw.githubusercontent.com/pyasn1/pyasn1/master/LICENSE.txt) |
| 49 |
|
| 50 |
This is a free and open source implementation of ASN.1 types and codecs |
| 51 |
as a Python package. It has been first written to support particular |
| 52 |
protocol (SNMP) but then generalized to be suitable for a wide range |
| 53 |
of protocols based on |
| 54 |
[ASN.1 specification](https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-X.208-198811-W!!PDF-E&type=items). |
| 55 |
|
| 56 |
**NOTE:** The package is now maintained by *Christian Heimes* and |
| 57 |
*Simon Pichugin* in project https://github.com/pyasn1/pyasn1. |
| 58 |
|
| 59 |
Features |
| 60 |
-------- |
| 61 |
|
| 62 |
* Generic implementation of ASN.1 types (X.208) |
| 63 |
* Standards compliant BER/CER/DER codecs |
| 64 |
* Can operate on streams of serialized data |
| 65 |
* Dumps/loads ASN.1 structures from Python types |
| 66 |
* 100% Python, works with Python 3.8+ |
| 67 |
* MT-safe |
| 68 |
* Contributed ASN.1 compiler [Asn1ate](https://github.com/kimgr/asn1ate) |
| 69 |
|
| 70 |
Why using pyasn1 |
| 71 |
---------------- |
| 72 |
|
| 73 |
ASN.1 solves the data serialisation problem. This solution was |
| 74 |
designed long ago by the wise Ancients. Back then, they did not |
| 75 |
have the luxury of wasting bits. That is why ASN.1 is designed |
| 76 |
to serialise data structures of unbounded complexity into |
| 77 |
something compact and efficient when it comes to processing |
| 78 |
the data. |
| 79 |
|
| 80 |
That probably explains why many network protocols and file formats |
| 81 |
still rely on the 30+ years old technology. Including a number of |
| 82 |
high-profile Internet protocols and file formats. |
| 83 |
|
| 84 |
Quite a number of books cover the topic of ASN.1. |
| 85 |
[Communication between heterogeneous systems](http://www.oss.com/asn1/dubuisson.html) |
| 86 |
by Olivier Dubuisson is one of those high quality books freely |
| 87 |
available on the Internet. |
| 88 |
|
| 89 |
The pyasn1 package is designed to help Python programmers tackling |
| 90 |
network protocols and file formats at the comfort of their Python |
| 91 |
prompt. The tool struggles to capture all aspects of a rather |
| 92 |
complicated ASN.1 system and to represent it on the Python terms. |
| 93 |
|
| 94 |
How to use pyasn1 |
| 95 |
----------------- |
| 96 |
|
| 97 |
With pyasn1 you can build Python objects from ASN.1 data structures. |
| 98 |
For example, the following ASN.1 data structure: |
| 99 |
|
| 100 |
```bash |
| 101 |
Record ::= SEQUENCE { |
| 102 |
id INTEGER, |
| 103 |
room [0] INTEGER OPTIONAL, |
| 104 |
house [1] INTEGER DEFAULT 0 |
| 105 |
} |
| 106 |
``` |
| 107 |
|
| 108 |
Could be expressed in pyasn1 like this: |
| 109 |
|
| 110 |
```python |
| 111 |
class Record(Sequence): |
| 112 |
componentType = NamedTypes( |
| 113 |
NamedType('id', Integer()), |
| 114 |
OptionalNamedType( |
| 115 |
'room', Integer().subtype( |
| 116 |
implicitTag=Tag(tagClassContext, tagFormatSimple, 0) |
| 117 |
) |
| 118 |
), |
| 119 |
DefaultedNamedType( |
| 120 |
'house', Integer(0).subtype( |
| 121 |
implicitTag=Tag(tagClassContext, tagFormatSimple, 1) |
| 122 |
) |
| 123 |
) |
| 124 |
) |
| 125 |
``` |
| 126 |
|
| 127 |
It is in the spirit of ASN.1 to take abstract data description |
| 128 |
and turn it into a programming language specific form. |
| 129 |
Once you have your ASN.1 data structure expressed in Python, you |
| 130 |
can use it along the lines of similar Python type (e.g. ASN.1 |
| 131 |
`SET` is similar to Python `dict`, `SET OF` to `list`): |
| 132 |
|
| 133 |
```python |
| 134 |
>>> record = Record() |
| 135 |
>>> record['id'] = 123 |
| 136 |
>>> record['room'] = 321 |
| 137 |
>>> str(record) |
| 138 |
Record: |
| 139 |
id=123 |
| 140 |
room=321 |
| 141 |
>>> |
| 142 |
``` |
| 143 |
|
| 144 |
Part of the power of ASN.1 comes from its serialisation features. You |
| 145 |
can serialise your data structure and send it over the network. |
| 146 |
|
| 147 |
```python |
| 148 |
>>> from pyasn1.codec.der.encoder import encode |
| 149 |
>>> substrate = encode(record) |
| 150 |
>>> hexdump(substrate) |
| 151 |
00000: 30 07 02 01 7B 80 02 01 41 |
| 152 |
``` |
| 153 |
|
| 154 |
Conversely, you can turn serialised ASN.1 content, as received from |
| 155 |
network or read from a file, into a Python object which you can |
| 156 |
introspect, modify, encode and send back. |
| 157 |
|
| 158 |
```python |
| 159 |
>>> from pyasn1.codec.der.decoder import decode |
| 160 |
>>> received_record, rest_of_substrate = decode(substrate, asn1Spec=Record()) |
| 161 |
>>> |
| 162 |
>>> for field in received_record: |
| 163 |
>>> print('{} is {}'.format(field, received_record[field])) |
| 164 |
id is 123 |
| 165 |
room is 321 |
| 166 |
house is 0 |
| 167 |
>>> |
| 168 |
>>> record == received_record |
| 169 |
True |
| 170 |
>>> received_record.update(room=123) |
| 171 |
>>> substrate = encode(received_record) |
| 172 |
>>> hexdump(substrate) |
| 173 |
00000: 30 06 02 01 7B 80 01 7B |
| 174 |
``` |
| 175 |
|
| 176 |
The pyasn1 classes struggle to emulate their Python prototypes (e.g. int, |
| 177 |
list, dict etc.). But ASN.1 types exhibit more complicated behaviour. |
| 178 |
To make life easier for a Pythonista, they can turn their pyasn1 |
| 179 |
classes into Python built-ins: |
| 180 |
|
| 181 |
```python |
| 182 |
>>> from pyasn1.codec.native.encoder import encode |
| 183 |
>>> encode(record) |
| 184 |
{'id': 123, 'room': 321, 'house': 0} |
| 185 |
``` |
| 186 |
|
| 187 |
Or vice-versa -- you can initialize an ASN.1 structure from a tree of |
| 188 |
Python objects: |
| 189 |
|
| 190 |
```python |
| 191 |
>>> from pyasn1.codec.native.decoder import decode |
| 192 |
>>> record = decode({'id': 123, 'room': 321, 'house': 0}, asn1Spec=Record()) |
| 193 |
>>> str(record) |
| 194 |
Record: |
| 195 |
id=123 |
| 196 |
room=321 |
| 197 |
>>> |
| 198 |
``` |
| 199 |
|
| 200 |
With ASN.1 design, serialisation codecs are decoupled from data objects, |
| 201 |
so you could turn every single ASN.1 object into many different |
| 202 |
serialised forms. As of this moment, pyasn1 supports BER, DER, CER and |
| 203 |
Python built-ins codecs. The extremely compact PER encoding is expected |
| 204 |
to be introduced in the upcoming pyasn1 release. |
| 205 |
|
| 206 |
More information on pyasn1 APIs can be found in the |
| 207 |
[documentation](https://pyasn1.readthedocs.io/en/latest/pyasn1/contents.html), |
| 208 |
compiled ASN.1 modules for different protocols and file formats |
| 209 |
could be found in the pyasn1-modules |
| 210 |
[repo](https://github.com/pyasn1/pyasn1-modules). |
| 211 |
|
| 212 |
How to get pyasn1 |
| 213 |
----------------- |
| 214 |
|
| 215 |
The pyasn1 package is distributed under terms and conditions of 2-clause |
| 216 |
BSD [license](https://pyasn1.readthedocs.io/en/latest/license.html). Source code is freely |
| 217 |
available as a GitHub [repo](https://github.com/pyasn1/pyasn1). |
| 218 |
|
| 219 |
You could `pip install pyasn1` or download it from [PyPI](https://pypi.org/project/pyasn1). |
| 220 |
|
| 221 |
If something does not work as expected, |
| 222 |
[open an issue](https://github.com/epyasn1/pyasn1/issues) at GitHub or |
| 223 |
post your question [on Stack Overflow](https://stackoverflow.com/questions/ask) |
| 224 |
or try browsing pyasn1 |
| 225 |
[mailing list archives](https://sourceforge.net/p/pyasn1/mailman/pyasn1-users/). |
| 226 |
|
| 227 |
Copyright (c) 2005-2020, [Ilya Etingof](mailto:[email protected]). |
| 228 |
All rights reserved. |