METADATA 8.2 KB

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