diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-02-13 19:18:03 -0600 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-02-14 10:12:26 -0600 |
commit | 2e776e20eb60378e0af9b7439000d0e80da7c7e3 (patch) | |
tree | e6864a606d3d9c420ad014fe7c5544e803b90c9a | |
parent | 42a87cbde14c23b2f10af665c6977697a1d0c034 (diff) | |
download | cryptography-2e776e20eb60378e0af9b7439000d0e80da7c7e3.tar.gz cryptography-2e776e20eb60378e0af9b7439000d0e80da7c7e3.tar.bz2 cryptography-2e776e20eb60378e0af9b7439000d0e80da7c7e3.zip |
refactor obj2txt to be a separate method
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/x509.py | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py index c69e9148..b712f1f9 100644 --- a/src/cryptography/hazmat/backends/openssl/x509.py +++ b/src/cryptography/hazmat/backends/openssl/x509.py @@ -122,14 +122,7 @@ class _Certificate(object): buf, lambda buf: self._backend._lib.OPENSSL_free(buf[0]) ) value = self._backend._ffi.buffer(buf[0], res)[:].decode('utf8') - # Set to 80 on the recommendation of - # https://www.openssl.org/docs/crypto/OBJ_nid2ln.html - buf_len = 80 - buf = self._backend._ffi.new("char[]", buf_len) - res = self._backend._lib.OBJ_obj2txt(buf, buf_len, obj, 1) - assert res > 0 - oid = self._backend._ffi.buffer(buf, res)[:].decode() - + oid = self._obj2txt(obj) attributes.append( x509.NameAttribute( x509.ObjectIdentifier(oid), value @@ -138,15 +131,18 @@ class _Certificate(object): return x509.Name(attributes) + def _obj2txt(self, obj): + # Set to 80 on the recommendation of + # https://www.openssl.org/docs/crypto/OBJ_nid2ln.html#return_values + buf_len = 80 + buf = self._backend._ffi.new("char[]", buf_len) + res = self._backend._lib.OBJ_obj2txt(buf, buf_len, obj, 1) + assert res > 0 + return self._backend._ffi.buffer(buf, res)[:].decode() + @property def signature_hash_algorithm(self): - buf_len = 50 - buf = self._backend._ffi.new("char[]", buf_len) - res = self._backend._lib.OBJ_obj2txt( - buf, buf_len, self._x509.sig_alg.algorithm, 1 - ) - assert res <= 50 and res > 0 - oid = self._backend._ffi.buffer(buf, res)[:].decode() + oid = self._obj2txt(self._x509.sig_alg.algorithm) try: return x509._SIG_OIDS_TO_HASH[oid] except KeyError: |