Skip to content

Commit b1bfab6

Browse files
committed
Documentation
1 parent 3216bb2 commit b1bfab6

File tree

6 files changed

+124
-92
lines changed

6 files changed

+124
-92
lines changed

CHANGELOG.rst

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
Changelog
22
=========
33

4+
3.0.0 (2025-03-03)
5+
------------------
6+
7+
* Encoding and decoding of the ASN.1 REAL type
8+
* Support of indefinite lengths
9+
* Encoding and decoding of complex data (lists, sets, ...)
10+
* Add support for streams (file-like objects) when encoding and decoding
11+
* Optionally return the number of unused bits when decoding a BitString (see also #276)
12+
* #286 - Add ASN.1:2008 compliance test suite
13+
414
2.8.0 (2025-02-20)
515
------------------
616

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ graft examples
33
graft src
44
graft ci
55
graft tests
6+
graft stubs
67

78
include .coveragerc
89
include .cookiecutterrc

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ Python-ASN1 is a simple ASN.1 encoder and decoder for Python 2.7 and 3.5+.
3838
Features
3939
========
4040

41-
- Support BER (parser) and DER (parser and generator) encoding (except indefinite lengths)
41+
- Support BER (parser) and DER (parser and generator) encoding (including indefinite lengths)
4242
- 100% python, compatible with version 2.7, 3.5 and higher
4343
- Can be integrated by just including a file into your project
44-
44+
- Support most common ASN.1 types including REAL (encoding and decoding).
4545

4646
Dependencies
4747
==============

docs/usage.rst

+26-14
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,13 @@ Null 0x05 None None
3030
ObjectIdentifier 0x06 str
3131
Real 0x09 float float
3232
Enumerated 0x0A int
33-
UTCTime 0x17
34-
GeneralizedTime 0x18
35-
Date 0x1F
36-
TimeOfDay 0x20
37-
DateTime 0x21
38-
Duration 0x22
3933
================ ========== =========== =============
4034

4135
Because ASN.1 has more data types than Python, the situation arises that one Python
4236
type corresponds to multiple ASN.1 types. In this situation, the to be encoded
4337
ASN.1 type cannot be determined from the Python type. The solution
4438
implemented in Python-ASN1 is that the most frequently used type will be the
45-
implicit default. This is indicated in the `Encoding` column.
39+
implicit default. This is indicated in the ``Encoding`` column.
4640
If another type is desired than that must be specified
4741
explicitly through the API.
4842

@@ -175,7 +169,7 @@ You can decode complex data structures. The decoder will automatically map ASN.1
175169

176170
.. code-block:: python
177171
178-
import asn1
172+
import asn1
179173
180174
with open('example7.der', 'rb') as f:
181175
decoder = asn1.Decoder()
@@ -184,6 +178,24 @@ You can decode complex data structures. The decoder will automatically map ASN.1
184178
print(tag)
185179
pprint.pprint(value)
186180
181+
You can ask the decoder to return the number of unused bits when decoding a BitString:
182+
183+
.. code-block:: python
184+
185+
import asn1
186+
187+
encoded = b'\x23\x0C\x03\x02\x00\x0B\x03\x02\x00\x0B\x03\x02\x04\x0F'
188+
decoder = asn1.Decoder()
189+
decoder.start(encoded)
190+
tag, (value, unused) = decoder.read(asn1.ReadFlags.WithUnused)
191+
print('Tag: ', tag)
192+
print('Value: ', value)
193+
print('Unused bits: ', unused)
194+
195+
The flag ``ReadFlags.WithUnused`` can be used with any ASN.1 type. When used, the read method will return a tuple with the value and the number of unused bits.
196+
If the type is not a BitString, the number of unused bits is always 0.
197+
198+
187199
Constants
188200
---------
189201

@@ -242,12 +254,12 @@ and constructed) for ASN.1 data types. As above they can be used with the
242254
`Decoder.peek()` and
243255
`Decoder.read()`.
244256

245-
================== ===========
246-
Constant Value (hex)
247-
================== ============
248-
Types.Constructed 0x20
249-
Types.Primitive 0x00
250-
================== ===========
257+
=================== ===========
258+
Constant Value (hex)
259+
=================== ===========
260+
Types.Constructed 0x20
261+
Types.Primitive 0x00
262+
=================== ===========
251263

252264
Finally the constants below define the different ASN.1 classes. As above
253265
they can be used with the `Encoder.write()` and are

examples/examples.py

+79-71
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717

1818
def example1():
19+
"""Encoding an object identifier."""
1920
print('Example 1')
2021
encoder = asn1.Encoder()
2122
encoder.start()
@@ -25,13 +26,15 @@ def example1():
2526

2627

2728
def example2():
29+
"""Encoding an object identifier directly to a file."""
2830
print('Example 2')
2931
with open('example2.der', 'wb') as f:
3032
encoder = asn1.Encoder()
3133
encoder.start(f)
3234
encoder.write('1.2.3', asn1.Numbers.ObjectIdentifier)
3335

3436
def example3():
37+
"""Encoding of a complex data."""
3538
print('Example 3')
3639
with open('example3.der', 'wb') as f:
3740
encoder = asn1.Encoder()
@@ -45,6 +48,7 @@ def example3():
4548

4649

4750
def example4():
51+
"""Decoding from a file."""
4852
print('Example 4')
4953
with open('example3.der', 'rb') as f:
5054
decoder = asn1.Decoder()
@@ -56,10 +60,11 @@ def example4():
5660

5761

5862
def example5():
63+
"""Decoding of a bit string with unused bits."""
5964
print('Example 5')
60-
example5 = b'\x23\x0C\x03\x02\x00\x0B\x03\x02\x00\x0B\x03\x02\x04\x0F'
65+
encoded = b'\x23\x0C\x03\x02\x00\x0B\x03\x02\x00\x0B\x03\x02\x04\x0F'
6166
decoder = asn1.Decoder()
62-
decoder.start(example5)
67+
decoder.start(encoded)
6368
tag, (val, unused) = decoder.read(asn1.ReadFlags.WithUnused)
6469
print('Tag:', tag)
6570
print('Value:', val)
@@ -68,6 +73,7 @@ def example5():
6873

6974

7075
def example6():
76+
"""Encoding of sequences."""
7177
print('Example 6')
7278
encoder = asn1.Encoder()
7379
encoder.start()
@@ -85,87 +91,89 @@ def example6():
8591

8692

8793
def example7():
94+
"""Decoding of sequences."""
8895
print('Example 7')
89-
example7 = b'\x30\x80\x13\x05\x74\x65\x73\x74\x31\x13\x05\x74\x65\x73\x74\x32\x30\x80\x02\x01\x01\x09\x03\x80\xFD\x01\x04\x03\x01\x02\x03\x00\x00\x00\x00'
96+
encoded = b'\x30\x80\x13\x05\x74\x65\x73\x74\x31\x13\x05\x74\x65\x73\x74\x32\x30\x80\x02\x01\x01\x09\x03\x80\xFD\x01\x04\x03\x01\x02\x03\x00\x00\x00\x00'
9097
decoder = asn1.Decoder()
91-
decoder.start(example7)
98+
decoder.start(encoded)
9299
tag, value = decoder.read()
93100
print(tag)
94101
pprint.pprint(value)
95102
print()
96103

97104

98105
def example8():
106+
"""Decoding of a complex data."""
99107
print('Example 8')
100-
example8 = (b'\x30\x82\x04\x0e\x30\x82\x03\x77\xa0\x03\x02\x01\x02\x02\x02\x15'
101-
b'\x30\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x05\x00'
102-
b'\x30\x81\xbb\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x2d\x2d'
103-
b'\x31\x12\x30\x10\x06\x03\x55\x04\x08\x13\x09\x53\x6f\x6d\x65\x53'
104-
b'\x74\x61\x74\x65\x31\x11\x30\x0f\x06\x03\x55\x04\x07\x13\x08\x53'
105-
b'\x6f\x6d\x65\x43\x69\x74\x79\x31\x19\x30\x17\x06\x03\x55\x04\x0a'
106-
b'\x13\x10\x53\x6f\x6d\x65\x4f\x72\x67\x61\x6e\x69\x7a\x61\x74\x69'
107-
b'\x6f\x6e\x31\x1f\x30\x1d\x06\x03\x55\x04\x0b\x13\x16\x53\x6f\x6d'
108-
b'\x65\x4f\x72\x67\x61\x6e\x69\x7a\x61\x74\x69\x6f\x6e\x61\x6c\x55'
109-
b'\x6e\x69\x74\x31\x1e\x30\x1c\x06\x03\x55\x04\x03\x13\x15\x6c\x6f'
110-
b'\x63\x61\x6c\x68\x6f\x73\x74\x2e\x6c\x6f\x63\x61\x6c\x64\x6f\x6d'
111-
b'\x61\x69\x6e\x31\x29\x30\x27\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01'
112-
b'\x09\x01\x16\x1a\x72\x6f\x6f\x74\x40\x6c\x6f\x63\x61\x6c\x68\x6f'
113-
b'\x73\x74\x2e\x6c\x6f\x63\x61\x6c\x64\x6f\x6d\x61\x69\x6e\x30\x1e'
114-
b'\x17\x0d\x30\x38\x30\x32\x30\x35\x30\x39\x32\x33\x33\x31\x5a\x17'
115-
b'\x0d\x30\x39\x30\x32\x30\x34\x30\x39\x32\x33\x33\x31\x5a\x30\x81'
116-
b'\xbb\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x2d\x2d\x31\x12'
117-
b'\x30\x10\x06\x03\x55\x04\x08\x13\x09\x53\x6f\x6d\x65\x53\x74\x61'
118-
b'\x74\x65\x31\x11\x30\x0f\x06\x03\x55\x04\x07\x13\x08\x53\x6f\x6d'
119-
b'\x65\x43\x69\x74\x79\x31\x19\x30\x17\x06\x03\x55\x04\x0a\x13\x10'
120-
b'\x53\x6f\x6d\x65\x4f\x72\x67\x61\x6e\x69\x7a\x61\x74\x69\x6f\x6e'
121-
b'\x31\x1f\x30\x1d\x06\x03\x55\x04\x0b\x13\x16\x53\x6f\x6d\x65\x4f'
122-
b'\x72\x67\x61\x6e\x69\x7a\x61\x74\x69\x6f\x6e\x61\x6c\x55\x6e\x69'
123-
b'\x74\x31\x1e\x30\x1c\x06\x03\x55\x04\x03\x13\x15\x6c\x6f\x63\x61'
124-
b'\x6c\x68\x6f\x73\x74\x2e\x6c\x6f\x63\x61\x6c\x64\x6f\x6d\x61\x69'
125-
b'\x6e\x31\x29\x30\x27\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x09\x01'
126-
b'\x16\x1a\x72\x6f\x6f\x74\x40\x6c\x6f\x63\x61\x6c\x68\x6f\x73\x74'
127-
b'\x2e\x6c\x6f\x63\x61\x6c\x64\x6f\x6d\x61\x69\x6e\x30\x81\x9f\x30'
128-
b'\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01\x05\x00\x03\x81'
129-
b'\x8d\x00\x30\x81\x89\x02\x81\x81\x00\xd5\x18\xcd\x40\x91\x90\x27'
130-
b'\x5a\x77\x37\x22\xca\xba\x05\xdf\x13\x31\xe8\x74\x43\x4f\x7e\x08'
131-
b'\xa3\xa5\x76\xcd\x7b\xdd\x37\xd0\x7f\x12\x9e\x81\x73\x87\x55\x66'
132-
b'\x0d\xda\x68\xee\x38\xeb\x34\xe2\xf4\xeb\x95\xd5\xe0\xde\xef\x08'
133-
b'\x57\xf9\x03\x14\x69\xa8\x6f\x7c\xa4\xfa\x64\x51\x39\x36\xd5\x09'
134-
b'\x37\x61\x83\x13\x8c\x41\x25\xba\x60\x91\x20\x86\x5b\x60\xb5\xe2'
135-
b'\x83\x65\x66\xad\x06\xb3\x45\x71\x83\x67\xd2\xe5\x5f\x40\x42\x4b'
136-
b'\x37\xf8\x87\xd0\x09\x49\xb8\xad\x34\x76\xa3\x1b\xbf\xc1\x0f\xb7'
137-
b'\xfb\x43\xbe\x62\x33\x02\x02\x10\x61\x02\x03\x01\x00\x01\xa3\x82'
138-
b'\x01\x1d\x30\x82\x01\x19\x30\x1d\x06\x03\x55\x1d\x0e\x04\x16\x04'
139-
b'\x14\x0a\x4b\xfa\x87\x54\x17\x7e\x30\xb4\x21\x71\x56\x51\x0f\xd2'
140-
b'\x91\xc3\x30\x02\x36\x30\x81\xe9\x06\x03\x55\x1d\x23\x04\x81\xe1'
141-
b'\x30\x81\xde\x80\x14\x0a\x4b\xfa\x87\x54\x17\x7e\x30\xb4\x21\x71'
142-
b'\x56\x51\x0f\xd2\x91\xc3\x30\x02\x36\xa1\x81\xc1\xa4\x81\xbe\x30'
143-
b'\x81\xbb\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x2d\x2d\x31'
144-
b'\x12\x30\x10\x06\x03\x55\x04\x08\x13\x09\x53\x6f\x6d\x65\x53\x74'
145-
b'\x61\x74\x65\x31\x11\x30\x0f\x06\x03\x55\x04\x07\x13\x08\x53\x6f'
146-
b'\x6d\x65\x43\x69\x74\x79\x31\x19\x30\x17\x06\x03\x55\x04\x0a\x13'
147-
b'\x10\x53\x6f\x6d\x65\x4f\x72\x67\x61\x6e\x69\x7a\x61\x74\x69\x6f'
148-
b'\x6e\x31\x1f\x30\x1d\x06\x03\x55\x04\x0b\x13\x16\x53\x6f\x6d\x65'
149-
b'\x4f\x72\x67\x61\x6e\x69\x7a\x61\x74\x69\x6f\x6e\x61\x6c\x55\x6e'
150-
b'\x69\x74\x31\x1e\x30\x1c\x06\x03\x55\x04\x03\x13\x15\x6c\x6f\x63'
151-
b'\x61\x6c\x68\x6f\x73\x74\x2e\x6c\x6f\x63\x61\x6c\x64\x6f\x6d\x61'
152-
b'\x69\x6e\x31\x29\x30\x27\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x09'
153-
b'\x01\x16\x1a\x72\x6f\x6f\x74\x40\x6c\x6f\x63\x61\x6c\x68\x6f\x73'
154-
b'\x74\x2e\x6c\x6f\x63\x61\x6c\x64\x6f\x6d\x61\x69\x6e\x82\x02\x15'
155-
b'\x30\x30\x0c\x06\x03\x55\x1d\x13\x04\x05\x30\x03\x01\x01\xff\x30'
156-
b'\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x05\x00\x03\x81'
157-
b'\x81\x00\x4e\x12\x46\x58\xa3\x57\xc5\x9a\xab\xfa\x32\xf5\xde\x87'
158-
b'\xfb\x77\xa8\x79\x38\x1d\x4f\xd3\x7c\x3a\x16\x60\x82\x7d\x92\xa1'
159-
b'\x58\xd2\x53\x7b\x11\x90\xec\x6d\xb0\xb0\x58\xee\x33\xb4\x7b\x1d'
160-
b'\xb8\x95\xd8\x98\xc3\x10\x81\x83\x08\x46\xe8\x9a\xb9\x6c\xbf\x8f'
161-
b'\x9e\x73\xf7\x61\x89\xc4\x6a\x1b\xc1\x98\xc6\xab\xfc\x91\xb6\x59'
162-
b'\xb8\xa5\x05\x91\x2a\xbb\xc4\x30\x16\x53\xbf\x1a\xfe\x2f\x01\x25'
163-
b'\xae\xef\xc7\xb9\xfa\xa5\x53\xf8\xd9\xf5\x8f\xae\x91\xea\x57\x28'
164-
b'\xfa\xdf\x34\x03\x29\xe8\x97\xee\x2e\x9e\x8a\x62\x45\xc7\xfc\x58'
165-
b'\xb4\x5a')
108+
encoded = (b'\x30\x82\x04\x0e\x30\x82\x03\x77\xa0\x03\x02\x01\x02\x02\x02\x15'
109+
b'\x30\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x05\x00'
110+
b'\x30\x81\xbb\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x2d\x2d'
111+
b'\x31\x12\x30\x10\x06\x03\x55\x04\x08\x13\x09\x53\x6f\x6d\x65\x53'
112+
b'\x74\x61\x74\x65\x31\x11\x30\x0f\x06\x03\x55\x04\x07\x13\x08\x53'
113+
b'\x6f\x6d\x65\x43\x69\x74\x79\x31\x19\x30\x17\x06\x03\x55\x04\x0a'
114+
b'\x13\x10\x53\x6f\x6d\x65\x4f\x72\x67\x61\x6e\x69\x7a\x61\x74\x69'
115+
b'\x6f\x6e\x31\x1f\x30\x1d\x06\x03\x55\x04\x0b\x13\x16\x53\x6f\x6d'
116+
b'\x65\x4f\x72\x67\x61\x6e\x69\x7a\x61\x74\x69\x6f\x6e\x61\x6c\x55'
117+
b'\x6e\x69\x74\x31\x1e\x30\x1c\x06\x03\x55\x04\x03\x13\x15\x6c\x6f'
118+
b'\x63\x61\x6c\x68\x6f\x73\x74\x2e\x6c\x6f\x63\x61\x6c\x64\x6f\x6d'
119+
b'\x61\x69\x6e\x31\x29\x30\x27\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01'
120+
b'\x09\x01\x16\x1a\x72\x6f\x6f\x74\x40\x6c\x6f\x63\x61\x6c\x68\x6f'
121+
b'\x73\x74\x2e\x6c\x6f\x63\x61\x6c\x64\x6f\x6d\x61\x69\x6e\x30\x1e'
122+
b'\x17\x0d\x30\x38\x30\x32\x30\x35\x30\x39\x32\x33\x33\x31\x5a\x17'
123+
b'\x0d\x30\x39\x30\x32\x30\x34\x30\x39\x32\x33\x33\x31\x5a\x30\x81'
124+
b'\xbb\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x2d\x2d\x31\x12'
125+
b'\x30\x10\x06\x03\x55\x04\x08\x13\x09\x53\x6f\x6d\x65\x53\x74\x61'
126+
b'\x74\x65\x31\x11\x30\x0f\x06\x03\x55\x04\x07\x13\x08\x53\x6f\x6d'
127+
b'\x65\x43\x69\x74\x79\x31\x19\x30\x17\x06\x03\x55\x04\x0a\x13\x10'
128+
b'\x53\x6f\x6d\x65\x4f\x72\x67\x61\x6e\x69\x7a\x61\x74\x69\x6f\x6e'
129+
b'\x31\x1f\x30\x1d\x06\x03\x55\x04\x0b\x13\x16\x53\x6f\x6d\x65\x4f'
130+
b'\x72\x67\x61\x6e\x69\x7a\x61\x74\x69\x6f\x6e\x61\x6c\x55\x6e\x69'
131+
b'\x74\x31\x1e\x30\x1c\x06\x03\x55\x04\x03\x13\x15\x6c\x6f\x63\x61'
132+
b'\x6c\x68\x6f\x73\x74\x2e\x6c\x6f\x63\x61\x6c\x64\x6f\x6d\x61\x69'
133+
b'\x6e\x31\x29\x30\x27\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x09\x01'
134+
b'\x16\x1a\x72\x6f\x6f\x74\x40\x6c\x6f\x63\x61\x6c\x68\x6f\x73\x74'
135+
b'\x2e\x6c\x6f\x63\x61\x6c\x64\x6f\x6d\x61\x69\x6e\x30\x81\x9f\x30'
136+
b'\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01\x05\x00\x03\x81'
137+
b'\x8d\x00\x30\x81\x89\x02\x81\x81\x00\xd5\x18\xcd\x40\x91\x90\x27'
138+
b'\x5a\x77\x37\x22\xca\xba\x05\xdf\x13\x31\xe8\x74\x43\x4f\x7e\x08'
139+
b'\xa3\xa5\x76\xcd\x7b\xdd\x37\xd0\x7f\x12\x9e\x81\x73\x87\x55\x66'
140+
b'\x0d\xda\x68\xee\x38\xeb\x34\xe2\xf4\xeb\x95\xd5\xe0\xde\xef\x08'
141+
b'\x57\xf9\x03\x14\x69\xa8\x6f\x7c\xa4\xfa\x64\x51\x39\x36\xd5\x09'
142+
b'\x37\x61\x83\x13\x8c\x41\x25\xba\x60\x91\x20\x86\x5b\x60\xb5\xe2'
143+
b'\x83\x65\x66\xad\x06\xb3\x45\x71\x83\x67\xd2\xe5\x5f\x40\x42\x4b'
144+
b'\x37\xf8\x87\xd0\x09\x49\xb8\xad\x34\x76\xa3\x1b\xbf\xc1\x0f\xb7'
145+
b'\xfb\x43\xbe\x62\x33\x02\x02\x10\x61\x02\x03\x01\x00\x01\xa3\x82'
146+
b'\x01\x1d\x30\x82\x01\x19\x30\x1d\x06\x03\x55\x1d\x0e\x04\x16\x04'
147+
b'\x14\x0a\x4b\xfa\x87\x54\x17\x7e\x30\xb4\x21\x71\x56\x51\x0f\xd2'
148+
b'\x91\xc3\x30\x02\x36\x30\x81\xe9\x06\x03\x55\x1d\x23\x04\x81\xe1'
149+
b'\x30\x81\xde\x80\x14\x0a\x4b\xfa\x87\x54\x17\x7e\x30\xb4\x21\x71'
150+
b'\x56\x51\x0f\xd2\x91\xc3\x30\x02\x36\xa1\x81\xc1\xa4\x81\xbe\x30'
151+
b'\x81\xbb\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x2d\x2d\x31'
152+
b'\x12\x30\x10\x06\x03\x55\x04\x08\x13\x09\x53\x6f\x6d\x65\x53\x74'
153+
b'\x61\x74\x65\x31\x11\x30\x0f\x06\x03\x55\x04\x07\x13\x08\x53\x6f'
154+
b'\x6d\x65\x43\x69\x74\x79\x31\x19\x30\x17\x06\x03\x55\x04\x0a\x13'
155+
b'\x10\x53\x6f\x6d\x65\x4f\x72\x67\x61\x6e\x69\x7a\x61\x74\x69\x6f'
156+
b'\x6e\x31\x1f\x30\x1d\x06\x03\x55\x04\x0b\x13\x16\x53\x6f\x6d\x65'
157+
b'\x4f\x72\x67\x61\x6e\x69\x7a\x61\x74\x69\x6f\x6e\x61\x6c\x55\x6e'
158+
b'\x69\x74\x31\x1e\x30\x1c\x06\x03\x55\x04\x03\x13\x15\x6c\x6f\x63'
159+
b'\x61\x6c\x68\x6f\x73\x74\x2e\x6c\x6f\x63\x61\x6c\x64\x6f\x6d\x61'
160+
b'\x69\x6e\x31\x29\x30\x27\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x09'
161+
b'\x01\x16\x1a\x72\x6f\x6f\x74\x40\x6c\x6f\x63\x61\x6c\x68\x6f\x73'
162+
b'\x74\x2e\x6c\x6f\x63\x61\x6c\x64\x6f\x6d\x61\x69\x6e\x82\x02\x15'
163+
b'\x30\x30\x0c\x06\x03\x55\x1d\x13\x04\x05\x30\x03\x01\x01\xff\x30'
164+
b'\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x05\x00\x03\x81'
165+
b'\x81\x00\x4e\x12\x46\x58\xa3\x57\xc5\x9a\xab\xfa\x32\xf5\xde\x87'
166+
b'\xfb\x77\xa8\x79\x38\x1d\x4f\xd3\x7c\x3a\x16\x60\x82\x7d\x92\xa1'
167+
b'\x58\xd2\x53\x7b\x11\x90\xec\x6d\xb0\xb0\x58\xee\x33\xb4\x7b\x1d'
168+
b'\xb8\x95\xd8\x98\xc3\x10\x81\x83\x08\x46\xe8\x9a\xb9\x6c\xbf\x8f'
169+
b'\x9e\x73\xf7\x61\x89\xc4\x6a\x1b\xc1\x98\xc6\xab\xfc\x91\xb6\x59'
170+
b'\xb8\xa5\x05\x91\x2a\xbb\xc4\x30\x16\x53\xbf\x1a\xfe\x2f\x01\x25'
171+
b'\xae\xef\xc7\xb9\xfa\xa5\x53\xf8\xd9\xf5\x8f\xae\x91\xea\x57\x28'
172+
b'\xfa\xdf\x34\x03\x29\xe8\x97\xee\x2e\x9e\x8a\x62\x45\xc7\xfc\x58'
173+
b'\xb4\x5a')
166174

167175
decoder = asn1.Decoder()
168-
decoder.start(example8)
176+
decoder.start(encoded)
169177
tag, value = decoder.read()
170178
print(tag)
171179
pprint.pprint(value)

src/asn1.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -725,16 +725,17 @@ def peek(self): # type: () -> Union[Tag, None]
725725
def read(self, flags=ReadFlags.OnlyValue): # type: (ReadFlags) -> Tuple[Union[Tag, None], Any]
726726
"""
727727
This method decodes one ASN.1 tag from the input and returns it as a
728-
``(tag, value, unused)`` tuple. ``tag`` is a 3-tuple ``(nr, typ, cls)``,
728+
``(tag, value)`` tuple. ``tag`` is a 3-tuple ``(nr, typ, cls)``,
729729
while ``value`` is a Python object representing the ASN.1 value.
730+
The number of unused bits can be requested in the ``flags`` parameter.
731+
When ``ReadFlags.OnlyValue`` is specified, the method the tuple ``(tag, (value, unused))``.
730732
``unused`` is the number of unused bits removed from the value.
731-
The offset in the input is increased so that the next `Decoder.read()`
732-
or `Decoder.read_with_unused()` call will return the next tag. In case
733-
no more data is available from the input, this method returns ``None``
733+
The offset in the input is increased so that the next `Decoder.read()` call will return the next tag.
734+
In case no more data is available from the input, this method returns ``None``
734735
to signal end-of-file.
735736
736737
Args:
737-
flags (DecoderFlags): Return only the value or the value and the number of unused bits as a tuple.
738+
flags (asn1.DecoderFlags): Return only the value or the value and the number of unused bits as a tuple.
738739
739740
Returns:
740741
`Tag`, value: The current ASN.1 tag, its value and the

0 commit comments

Comments
 (0)