1from libc.string cimport memcmp
2
3from gssapi.raw.cython_types cimport gss_OID, gss_OID_set, gss_OID_desc
4from gssapi.raw.cython_types cimport OM_uint32
5from gssapi.raw.cython_types cimport GSS_C_INDEFINITE
6from gssapi.raw.oids cimport OID
7
8from gssapi.raw.types import MechType, NameType
9
10
11cdef gss_OID_set c_get_mech_oid_set(object mechs)
12cdef bint c_compare_oids(gss_OID a, gss_OID b)
13cdef object c_create_oid_set(gss_OID_set mech_set, bint free=*)
14cdef OID c_make_oid(gss_OID oid)
15
16cdef inline OM_uint32 c_py_ttl_to_c(object ttl) except? 1:
17    """Converts None to GSS_C_INDEFINITE, otherwise returns input."""
18    if ttl is None:
19        return GSS_C_INDEFINITE
20    else:
21        return <OM_uint32>ttl
22
23
24cdef inline object c_c_ttl_to_py(OM_uint32 ttl):
25    """Converts GSS_C_INDEFINITE to None, otherwise return input."""
26    if ttl == GSS_C_INDEFINITE:
27        return None
28    else:
29        return ttl
30
31
32cdef inline bint c_compare_oids(gss_OID a, gss_OID b):
33    """Compare two OIDs to see if they are the same."""
34
35    return (a.length == b.length and not
36            memcmp(a.elements, b.elements, a.length))
37