METADATA 8.4 KB

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