Skip to content

Commit dc99309

Browse files
James-E-ALegrandin
authored andcommitted
Add DerSequence.insert()
Use-case: ease semantic creation of optional fields, such as https://www.rfc-editor.org/rfc/rfc5652#section-6.2.4 Brief illustration: def construct_pwri(encrypted_cek, ke_alg, kdf_alg=None): recipient = DerSequence([DerInteger(0), ke_alg, DerOctetString(encrypted_cek)]) if kdf_alg is not None: if kdf_alg._tag_octet != 0xa0: raise ValueError("keyDerivationAlgorithm is of type [0] IMPLICIT SEQUENCE OPTIONAL") recipient.insert(1, kdf_alg) return recipient
1 parent 0be2f1a commit dc99309

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/Crypto/Util/asn1.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,10 @@ def append(self, item):
530530
self._seq.append(item)
531531
return self
532532

533+
def insert(self, index, item):
534+
self._seq.insert(index, item)
535+
return self
536+
533537
def hasInts(self, only_non_negative=True):
534538
"""Return the number of items in this sequence that are
535539
integers.

0 commit comments

Comments
 (0)