"""
from ctypescrypto import libcrypto
from ctypes import c_char_p, c_void_p, c_int, create_string_buffer
-class Oid:
+
+__all__ = ['Oid','create','cleanup']
+
+class Oid(object):
"""
Represents an OID. It can be consturucted by textual
representation like Oid("commonName") or Oid("CN"),
def __init__(self,value):
" Object constuctor. Accepts string or integer"
- if type(value) == type(""):
+ if isinstance(value,unicode):
+ value=value.encode('ascii')
+ if isinstance(value,str):
self.nid=libcrypto.OBJ_txt2nid(value)
if self.nid==0:
raise ValueError("Cannot find object %s in the database"%(value))
- elif type(value) == type(0):
+ elif isinstance(value,(int,long)):
cn=libcrypto.OBJ_nid2sn(value)
if cn is None:
raise ValueError("No such nid %d in the database"%(value))
" Returns logn name if any "
return libcrypto.OBJ_nid2ln(self.nid)
def dotted(self):
- " Returns dotted-decimal reperesntation "
+ " Returns dotted-decimal reperesentation "
obj=libcrypto.OBJ_nid2obj(self.nid)
buf=create_string_buffer(256)
libcrypto.OBJ_obj2txt(buf,256,obj,1)
return buf.value
+ @staticmethod
+ def fromobj(obj):
+ """
+ Creates an OID object from the pointer to ASN1_OBJECT c structure.
+ Strictly for internal use
+ """
+ nid=libcrypto.OBJ_obj2nid(obj)
+ if nid==0:
+ buf=create_string_buffer(80)
+ l=libcrypto.OBJ_obj2txt(buf,80,obj,1)
+ oid=create(buf[0:l],buf[0:l],buf[0:l])
+ else:
+ oid=Oid(nid)
+ return oid
def create(dotted,shortname,longname):
"""