Debian Codegraph @

src/spnego/iov.py

raw
1 # Copyright: (c) 2020, Jordan Borean (@jborean93) <[email protected]>
2 # MIT License (see LICENSE or https://opensource.org/licenses/MIT)
3
4 import enum
5 import typing
6
7
8 class BufferType(enum.IntEnum):
9 """Buffer types to use for an IOVBuffer type.
10
11 These are the IOVBuffer type flags that can be set for an IOVBuffer. The keys are a generified name for the
12 respective SSPI and GSSAPI flags.
13 """
14
15 empty = 0 # SECBUFFER_EMPTY | GSS_IOV_BUFFER_TYPE_EMPTY
16 data = 1 # SECBUFFER_DATA | GSS_IOV_BUFFER_TYPE_DATA
17 header = 2 # SECBUFFER_TOKEN | GSS_IOV_BUFFER_TYPE_HEADER
18 pkg_params = 3 # SECBUFFER_PKG_PARAMS | GSS_IOV_BUFFER_TYPE_MECH_PARAMS
19 trailer = 7 # SECBUFFER_STREAM_HEADER | GSS_IOV_BUFFER_TYPE_TRAILER
20 padding = 9 # SECBUFFER_PADDING | GSS_IOV_BUFFER_TYPE_PADDING
21 stream = 10 # SECBUFFER_STREAM | GSS_IOV_BUFFER_TYPE_STREAM
22 sign_only = 11 # (SECBUFFER_DATA | SECBUFFER_READONLY_WITH_CHECKSUM) | GSS_IOV_BUFFER_TYPE_SIGN_ONLY
23 mic_token = 12 # SECBUFFER_MECHLIST_SIGNATURE | GSS_IOV_BUFFER_TYPE_MIC_TOKEN
24
25 # This doesn't have an equivalent in GSSAPI but is mapped internally to
26 # the SSPI data + readonly buffer. Luckily GSSAPI seems to treat an empty
27 # buffer as the same as SSPI so that will be used there.
28 data_readonly = 4096 # (SECBUFFER_DATA | SECBUFFER_READONLY) | GSS_IOV_BUFFER_TYPE_EMPTY
29
30
31 class IOVBuffer(typing.NamedTuple):
32 """A buffer to pass as a list to :meth:`wrap_iov()`.
33
34 Defines the buffer inside a list that is passed to :meth:`wrap_iov()`. A list of these buffers are also returned in
35 the `IOVUnwrapResult` under the `buffers` attribute.
36
37 On SSPI only a buffer of the type `header`, `trailer`, or `padding` can be auto allocated. On GSSAPI all buffers
38 can be auto allocated when `data=True` but the behaviour behind this is dependent on the mech it is run for.
39
40 On the output from the `*_iov` functions the data is the bytes buffer or `None` if the buffer wasn't set. When used
41 as an input to the `*_iov` functions the data can be the buffer bytes, the length of buffer to allocate or a bool
42 to state whether the buffer is auto allocated or not.
43 """
44
45 type: BufferType #: The type of IOV buffer
46 data: typing.Optional[typing.Union[bytes, int, bool]] #: The IOV buffer type.
47
48
49 class IOVResBuffer(typing.NamedTuple):
50 """Results of an IOV operation.
51
52 Unlike :class:`IOVBuffer` this limits the value of `data` to just an
53 optionally set bytes. It is used as the return value of an IOV operation to
54 better match what the expected values would be.
55 """
56
57 type: BufferType
58 data: typing.Optional[bytes]