METADATA 8.1 KB

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