]> www.wagner.pp.ru Git - oss/ctypescrypto.git/blob - ctypescrypto/oid.py
81bea92a05f59cf583dff60df9607a3cdccf5b39
[oss/ctypescrypto.git] / ctypescrypto / oid.py
1 """     
2  Interface to OpenSSL object identifier database
3 """
4 from ctypescrypto import libcrypto
5 class Oid:
6         def __init__(self,value):
7                 if type(value) == type(""):
8                         self.nid=libcrypto.OBJ_txt2nid(value)
9                         if self.nid==0:
10                                 raise LibCryptoError("Cannot find object %s in the
11                                 database"%(value))
12                 elif type(value) == type(0):
13                         self.nid=value
14                 else:
15                         raise TypeError("Cannot convert this type to object identifier")
16         def __cmp__(self,other):
17                 return self.nid-other.nid
18         def __str__(self):
19                 return self.dotted()
20         def shorttname(self):
21                 return libcrypto.OBJ_nid2sn(self.nid)
22         def longname(self):
23                 return  libcrypto.OBJ_nid2ln(self.nid)
24         def dotted(self)
25                 obj=libcrypto.OBJ_nid2obj(self.nid)
26                 buf=create_string_buffer(256)
27                 libcrypto.OBJ_obj2txt(buf,256,obj,1)
28                 return buf.value
29