Exemple #1
0
 def test_do_all_sorted(self):
     names = set()
     def add_name(obj, _):
         names.add(obj.name)
     callback = api.callback('void(*)(const OBJ_NAME*, void *arg)', add_name)
     api.OBJ_NAME_do_all_sorted(api.OBJ_NAME_TYPE_MD_METH, callback, api.NULL)
     self.assertGreater(len(names), 0)
Exemple #2
0
def all_obj_type_names(objtype, unique_names=True):
    """Return a set of object names for an OpenSSL object type

    Requires an objtype argument that identifies the OpenSSL object type, such
    as tls.c.api.OBJ_NAME_TYPE_MD_METH. The unique_names argument controls
    whether just one or all aliases for the same object are returned. It
    defaults to True meaing that only a single name is returned for each object
    type.
    """

    def add_to_names(obj, _):
        if obj.alias:
            return
        name = obj.name
        nid = api.OBJ_sn2nid(name)
        if nid == api.NID_undef:
            nid = api.OBJ_ln2nid(name)
        if nid != api.NID_undef:
            hashes.setdefault(nid, set()).add(api.string(name))

    selection = slice(1) if unique_names else slice(sys.maxint)
    algorithms = set()
    hashes = {}
    callback = api.callback('void(*)(const OBJ_NAME*, void *arg)',
            add_to_names)
    api.OBJ_NAME_do_all(objtype, callback, api.NULL)
    for nid in hashes:
        name = sorted(hashes[nid])[selection]
        algorithms.update(name)
    return algorithms
Exemple #3
0
 def __init__(self, fileobj):
     method = api.new('BIO_METHOD*')
     method.type = api.BIO_TYPE_SOURCE_SINK | 0xFF
     method.name = self._name = api.new('char[]', repr(fileobj).encode())
     method.bwrite = self._bwrite = api.callback(
         'int (*)(BIO*, const char*, int)', self.write)
     method.bread = self._bread = api.callback('int (*)(BIO*, char*, int)',
                                               self.read)
     method.bputs = self._bputs = api.callback('int (*)(BIO*, const char*)',
                                               self.puts)
     method.bgets = self._bgets = api.callback('int (*)(BIO*, char*, int)',
                                               self.gets)
     method.ctrl = self._ctrl = api.callback(
         'long (*)(BIO*, int, long, void*)', self.ctrl)
     method.create = self._create = api.callback('int (*)(BIO*)',
                                                 self.create)
     method.destroy = api.NULL
     method.callback_ctrl = api.NULL
     self.method = method
     self.fileobj = fileobj
Exemple #4
0
 def __init__(self, fileobj):
     method = api.new('BIO_METHOD*', coown=True)
     method.type = api.BIO_TYPE_SOURCE_SINK | 0xFF
     method.name = api.new('char[]', repr(fileobj).encode())
     method.bwrite = api.callback('int (*)(BIO*, const char*, int)',
             self.write)
     method.bread = api.callback('int (*)(BIO*, char*, int)',
             self.read)
     method.bputs = api.callback('int (*)(BIO*, const char*)',
             self.puts)
     method.bgets = api.callback('int (*)(BIO*, char*, int)',
             self.gets)
     method.ctrl = api.callback('long (*)(BIO*, int, long, void*)',
             self.ctrl)
     method.create = api.callback('int (*)(BIO*)',
             self.create)
     method.destroy = api.NULL
     method.callback_ctrl = api.NULL
     self.method = method._unwrap()
     self.fileobj = fileobj