aboutsummaryrefslogtreecommitdiffstats
path: root/src/cryptography/x509/extensions.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2019-07-28 22:58:04 -0400
committerPaul Kehrer <paul.l.kehrer@gmail.com>2019-07-28 21:58:04 -0500
commit9cd41ac714d9bff819ece6d8cdcde064d403c671 (patch)
tree4ed2502ced1db85417fbf6fe214f59a1525893ff /src/cryptography/x509/extensions.py
parent2c83570f6310cb36553af274eb41dd8e2b96b58e (diff)
downloadcryptography-9cd41ac714d9bff819ece6d8cdcde064d403c671.tar.gz
cryptography-9cd41ac714d9bff819ece6d8cdcde064d403c671.tar.bz2
cryptography-9cd41ac714d9bff819ece6d8cdcde064d403c671.zip
Make DER reader into a context manager (#4957)
* Make DER reader into a context manager * Added another test case * flake8
Diffstat (limited to 'src/cryptography/x509/extensions.py')
-rw-r--r--src/cryptography/x509/extensions.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py
index c78c76c2..5bef9945 100644
--- a/src/cryptography/x509/extensions.py
+++ b/src/cryptography/x509/extensions.py
@@ -48,17 +48,17 @@ def _key_identifier_from_public_key(public_key):
serialization.PublicFormat.SubjectPublicKeyInfo
)
- public_key_info = DERReader(serialized).read_single_element(SEQUENCE)
- algorithm = public_key_info.read_element(SEQUENCE)
- public_key = public_key_info.read_element(BIT_STRING)
- public_key_info.check_empty()
+ reader = DERReader(serialized)
+ with reader.read_single_element(SEQUENCE) as public_key_info:
+ algorithm = public_key_info.read_element(SEQUENCE)
+ public_key = public_key_info.read_element(BIT_STRING)
# Double-check the algorithm structure.
- algorithm.read_element(OBJECT_IDENTIFIER)
- if not algorithm.is_empty():
- # Skip the optional parameters field.
- algorithm.read_any_element()
- algorithm.check_empty()
+ with algorithm:
+ algorithm.read_element(OBJECT_IDENTIFIER)
+ if not algorithm.is_empty():
+ # Skip the optional parameters field.
+ algorithm.read_any_element()
# BIT STRING contents begin with the number of padding bytes added. It
# must be zero for SubjectPublicKeyInfo structures.