|
Revision 27079, 0.9 kB
(checked in by therve, 2 days ago)
|
Merge dsa-key-failure-3391-2
Authors: z3p, therve
Reviewers: glyph, jml
Fixes #3391
Replace Conch custom ASN1 parser by pyasn1. It introduces a new dependency for
Conch, and solve a bunch of problems related to the previously custom parser.
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
""" |
|---|
| 5 |
A basic ASN.1 parser. Deprecated since Twisted 9.0 in favor of PyASN1. |
|---|
| 6 |
|
|---|
| 7 |
Maintainer: Paul Swartz |
|---|
| 8 |
""" |
|---|
| 9 |
|
|---|
| 10 |
import itertools |
|---|
| 11 |
from pyasn1.type import univ |
|---|
| 12 |
from pyasn1.codec.ber import decoder, encoder |
|---|
| 13 |
from twisted.python.deprecate import deprecated |
|---|
| 14 |
from twisted.python import versions |
|---|
| 15 |
|
|---|
| 16 |
Twisted9point0 = versions.Version('Twisted', 9, 0, 0) |
|---|
| 17 |
|
|---|
| 18 |
def parse(data): |
|---|
| 19 |
return decoder.decode(data)[0] |
|---|
| 20 |
|
|---|
| 21 |
parse = deprecated(Twisted9point0)(parse) |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
def pack(data): |
|---|
| 25 |
asn1Sequence = univ.Sequence() |
|---|
| 26 |
for index, value in itertools.izip(itertools.count(), data): |
|---|
| 27 |
try: |
|---|
| 28 |
valueAsInteger = univ.Integer(value) |
|---|
| 29 |
except TypeError: |
|---|
| 30 |
raise ValueError("cannot pack %r" % (value,)) |
|---|
| 31 |
asn1Sequence.setComponentByPosition(index, univ.Integer(value)) |
|---|
| 32 |
return encoder.encode(asn1Sequence) |
|---|
| 33 |
|
|---|
| 34 |
pack = deprecated(Twisted9point0)(pack) |
|---|