File: chan_bindings.pyx

package info (click to toggle)
python-gssapi 1.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 876 kB
  • sloc: python: 3,707; sh: 198; makefile: 154; ansic: 60
file content (52 lines) | stat: -rw-r--r-- 2,008 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from libc.stdlib cimport calloc, free

from gssapi.raw.cython_types cimport *

cdef class ChannelBindings:
    # defined in pxd file
    # cdef public object initiator_address_type
    # cdef public bytes initiator_address

    # cdef public object acceptor_address_type
    # cdef public bytes acceptor_address

    # cdef public bytes application_data

    def __init__(ChannelBindings self, initiator_address_type=None,
                 initiator_address=None, acceptor_address_type=None,
                 acceptor_address=None, application_data=None):
        self.initiator_address_type = initiator_address_type
        self.initiator_address = initiator_address

        self.acceptor_address_type = acceptor_address_type
        self.acceptor_address = acceptor_address

        self.application_data = application_data

    cdef gss_channel_bindings_t __cvalue__(ChannelBindings self) except NULL:
        """Get the C struct version of the channel bindings"""
        cdef gss_channel_bindings_t res
        res = <gss_channel_bindings_t>calloc(1, sizeof(res[0]))

        # NB(directxman12): an addrtype of 0 as set by calloc is equivalent
        #                   to GSS_C_AF_UNSPEC as per RFC 2744

        if self.initiator_address_type is not None:
            res.initiator_addrtype = self.initiator_address_type

        if self.initiator_address is not None:
            res.initiator_address.value = self.initiator_address
            res.initiator_address.length = len(self.initiator_address)

        if self.acceptor_address_type is not None:
            res.acceptor_addrtype = self.acceptor_address_type

        if self.acceptor_address is not None:
            res.acceptor_address.value = self.acceptor_address
            res.acceptor_address.length = len(self.acceptor_address)

        if self.application_data is not None:
            res.application_data.value = self.application_data
            res.application_data.length = len(self.application_data)

        return res