aboutsummaryrefslogtreecommitdiff
path: root/asn1crypto
diff options
context:
space:
mode:
authorwbond <will@wbond.net>2019-09-28 07:05:11 -0400
committerwbond <will@wbond.net>2019-09-28 07:05:11 -0400
commit60136d7dce4b8ae89d5d000d249587806f3d5371 (patch)
tree00ca0bc78f5c398c2fffdf5f48a6ddab03050001 /asn1crypto
parent3b330ff4d0fc59bacccc69972f3828286c18c97c (diff)
downloadasn1crypto-60136d7dce4b8ae89d5d000d249587806f3d5371.tar.gz
When copying a BER-encoded indefinite-length value, force it to be DER-encoded
Diffstat (limited to 'asn1crypto')
-rw-r--r--asn1crypto/core.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/asn1crypto/core.py b/asn1crypto/core.py
index 881620e..ebe2f5e 100644
--- a/asn1crypto/core.py
+++ b/asn1crypto/core.py
@@ -763,6 +763,20 @@ class Constructable(object):
return self.contents
+ def _setable_native(self):
+ """
+ Returns a native value that can be round-tripped into .set(), to
+ result in a DER encoding. This differs from .native in that .native
+ is designed for the end use, and may account for the fact that the
+ merged value is further parsed as ASN.1, such as in the case of
+ ParsableOctetString() and ParsableOctetBitString().
+
+ :return:
+ A python value that is valid to pass to .set()
+ """
+
+ return self.native
+
def _copy(self, other, copy_func):
"""
Copies the contents of another Constructable object to itself
@@ -776,8 +790,10 @@ class Constructable(object):
"""
super(Constructable, self)._copy(other, copy_func)
- self.method = other.method
- self._indefinite = other._indefinite
+ # We really don't want to dump BER encodings, so if we see an
+ # indefinite encoding, let's re-encode it
+ if other._indefinite:
+ self.set(other._setable_native())
class Void(Asn1Value):
@@ -2777,6 +2793,16 @@ class ParsableOctetString(Constructable, Castable, Primitive):
self._bytes = self._merge_chunks()
return self._bytes
+ def _setable_native(self):
+ """
+ Returns a byte string that can be passed into .set()
+
+ :return:
+ A python value that is valid to pass to .set()
+ """
+
+ return self.__bytes__()
+
def _copy(self, other, copy_func):
"""
Copies the contents of another ParsableOctetString object to itself