summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2016-03-12 10:54:36 +0100
committerIlya Etingof <etingof@gmail.com>2016-03-12 10:54:36 +0100
commitaa12ba0de2de5b75f7a9bf67d8b0d07fec2a8e92 (patch)
treeae7c91d590bae6dacdca5d35d3d5af323b383a45
parente2f30b80bbf73e8148918f964205824a4b1d729e (diff)
downloadpyasn1-git-aa12ba0de2de5b75f7a9bf67d8b0d07fec2a8e92.tar.gz
highlight code
-rw-r--r--MANIFEST.in2
-rw-r--r--README.md74
2 files changed, 43 insertions, 33 deletions
diff --git a/MANIFEST.in b/MANIFEST.in
index b764e0a..53ddd63 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,3 +1,3 @@
-include *.txt *.md *.sh
+include *.txt *.md
recursive-include test *.py
recursive-include doc *.html
diff --git a/README.md b/README.md
index 07d5b88..078b012 100644
--- a/README.md
+++ b/README.md
@@ -33,7 +33,9 @@ Installation
Download pyasn1 from [PyPI](https://pypi.python.org/pypi/pyasn1) or just run:
- $ pip install pyasn1
+```bash
+$ pip install pyasn1
+```
How to use pyasn1
-----------------
@@ -41,50 +43,58 @@ How to use pyasn1
With pyasn1 you can build ASN.1 structures from Python objects. For example, the
following ASN.1 structure:
- Record ::= SEQUENCE {
- id INTEGER,
- room [0] INTEGER OPTIONAL,
- house [1] INTEGER DEFAULT 0
- }
+```bash
+Record ::= SEQUENCE {
+ id INTEGER,
+ room [0] INTEGER OPTIONAL,
+ house [1] INTEGER DEFAULT 0
+}
+```
Could be expressed in pyasn1 like this:
-
- class Record(Sequence):
- componentType = NamedTypes(
- NamedType('id', Integer()),
- OptionalNamedType(
- 'room',
- Integer().subtype(
- implicitTag=Tag(tagClassContext, tagFormatSimple, 0)
- )
- ),
- DefaultedNamedType(
- 'house',
- Integer(0).subtype(
- implicitTag=Tag(tagClassContext, tagFormatSimple, 1)
- )
+
+```python
+class Record(Sequence):
+ componentType = NamedTypes(
+ NamedType('id', Integer()),
+ OptionalNamedType(
+ 'room',
+ Integer().subtype(
+ implicitTag=Tag(tagClassContext, tagFormatSimple, 0)
+ )
+ ),
+ DefaultedNamedType(
+ 'house',
+ Integer(0).subtype(
+ implicitTag=Tag(tagClassContext, tagFormatSimple, 1)
)
)
+ )
+```
Once you have your ASN.1 data structure defined, you can use it as a conventional
data structure:
-
- >>> record = Record()
- >>> record['id'] = 123
- >>> record[1] = 321
- >>> print(record.prettyPrint())
- Record:
- id=123
- room=321
- >>>
+
+```python
+>>> record = Record()
+>>> record['id'] = 123
+>>> record[1] = 321
+>>> print(record.prettyPrint())
+Record:
+ id=123
+ room=321
+>>>
+```
The power of ASN.1 comes with its serialization features. You can serialize your
initialized data structure and send it over the network. Conversely, you can
turn serialized ASN.1 content, as received from network or read from a file,
into a fully-fledged, initialized data structure.
- >>> encode(record)
- b'0\x07\x02\x01{\x80\x02\x01A'
+```python
+>>> encode(record)
+b'0\x07\x02\x01{\x80\x02\x01A'
+```
Many high-profile Internet protocols and file formats utilize ASN.1 serialization.
Quite a number of books cover the topic of ASN.1.