Пример #1
0
 def testFromObj(self):
     from ctypescrypto import libcrypto
     from ctypes import c_int, c_char_p, c_void_p
     libcrypto.OBJ_txt2obj.argtypes = (c_char_p, c_int)
     libcrypto.OBJ_txt2obj.restype = c_void_p
     obj = libcrypto.OBJ_txt2obj("1.2.643.100.9", 1)
     oid = Oid.fromobj(obj)
     self.assertEqual(str(oid), '1.2.643.100.9')
Пример #2
0
 def __getitem__(self, key):
     if isinstance(key, Oid):
         # Return first matching field
         idx = libcrypto.X509_NAME_get_index_by_NID(self.ptr, key.nid, -1)
         if idx < 0:
             raise KeyError("Key not found " + str(Oid))
         entry = libcrypto.X509_NAME_get_entry(self.ptr, idx)
         value = libcrypto.X509_NAME_ENTRY_get_data(entry)
         bio = Membio()
         libcrypto.ASN1_STRING_print_ex(bio.bio, value, self.PRINT_FLAG)
         return chartype(bio)
     elif isinstance(key, inttype):
         # Return OID, string tuple
         entry = libcrypto.X509_NAME_get_entry(self.ptr, key)
         if entry is None:
             raise IndexError("name entry index out of range")
         oid = Oid.fromobj(libcrypto.X509_NAME_ENTRY_get_object(entry))
         value = libcrypto.X509_NAME_ENTRY_get_data(entry)
         bio = Membio()
         libcrypto.ASN1_STRING_print_ex(bio.bio, value, self.PRINT_FLAG)
         return (oid, chartype(bio))
     else:
         raise TypeError("X509 NAME can be indexed by Oids or integers only")
Пример #3
0
 def oid(self):
     "Returns OID of the extension"
     return Oid.fromobj(self.ptr[0].object)
Пример #4
0
	def oid(self):
		return Oid.fromobj(self.ptr[0].object)