diff options
author | wbond <will@wbond.net> | 2019-10-01 00:21:13 -0400 |
---|---|---|
committer | wbond <will@wbond.net> | 2019-10-01 00:26:47 -0400 |
commit | c29117fd57deb80fb345cf76cad9d0d48e8bbf17 (patch) | |
tree | 6b8241697d633d06a33a427c3163c0d8034ad5d6 /asn1crypto | |
parent | 6d2ad8f5cd9495928367963f736f72031247a1b3 (diff) | |
download | asn1crypto-c29117fd57deb80fb345cf76cad9d0d48e8bbf17.tar.gz |
Handle BER-encoded indefinite length values better
- Ensure when we have trailing EOC bytes to include them when dumping
- If we know the encoding is indefinite length, re-encode using DER
Diffstat (limited to 'asn1crypto')
-rw-r--r-- | asn1crypto/core.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/asn1crypto/core.py b/asn1crypto/core.py index 490be13..1f5eddd 100644 --- a/asn1crypto/core.py +++ b/asn1crypto/core.py @@ -628,6 +628,10 @@ class Asn1Value(object): contents = self.contents + # If the length is indefinite, force the re-encoding + if self._header is not None and self._header[-1:] == b'\x80': + force = True + if self._header is None or force: if isinstance(self, Constructable) and self._indefinite: self.method = 0 @@ -641,7 +645,7 @@ class Asn1Value(object): self._header = header self._trailer = b'' - return self._header + contents + return self._header + contents + self._trailer class ValueMap(): @@ -1330,6 +1334,10 @@ class Choice(Asn1Value): A byte string of the DER-encoded value """ + # If the length is indefinite, force the re-encoding + if self._header is not None and self._header[-1:] == b'\x80': + force = True + self._contents = self.chosen.dump(force=force) if self._header is None or force: self._header = b'' @@ -1703,6 +1711,10 @@ class Primitive(Asn1Value): A byte string of the DER-encoded value """ + # If the length is indefinite, force the re-encoding + if self._header is not None and self._header[-1:] == b'\x80': + force = True + if force: native = self.native self.contents = None @@ -2862,6 +2874,10 @@ class ParsableOctetString(Constructable, Castable, Primitive): A byte string of the DER-encoded value """ + # If the length is indefinite, force the re-encoding + if self._indefinite: + force = True + if force: if self._parsed is not None: native = self.parsed.dump(force=force) @@ -4071,6 +4087,10 @@ class Sequence(Asn1Value): A byte string of the DER-encoded value """ + # If the length is indefinite, force the re-encoding + if self._header is not None and self._header[-1:] == b'\x80': + force = True + if force: self._set_contents(force=force) @@ -4535,6 +4555,10 @@ class SequenceOf(Asn1Value): A byte string of the DER-encoded value """ + # If the length is indefinite, force the re-encoding + if self._header is not None and self._header[-1:] == b'\x80': + force = True + if force: self._set_contents(force=force) |