File: gss_stub.py

package info (click to toggle)
python-asyncssh 2.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,464 kB
  • sloc: python: 40,306; makefile: 11
file content (51 lines) | stat: -rw-r--r-- 1,545 bytes parent folder | download | duplicates (4)
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
# Copyright (c) 2017-2018 by Ron Frederick <ronf@timeheart.net> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
# distribution and is available at:
#
#     http://www.eclipse.org/legal/epl-2.0/
#
# This program may also be made available under the following secondary
# licenses when the conditions for such availability set forth in the
# Eclipse Public License v2.0 are satisfied:
#
#    GNU General Public License, Version 2.0, or any later versions of
#    that license
#
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
#
# Contributors:
#     Ron Frederick - initial implementation, API, and documentation

"""Stub GSS module for unit tests"""


def step(host, token):
    """Perform next step in GSS authentication"""

    complete = False

    if token == b'errtok':
        return token, complete
    elif ((token is None and 'empty_init' in host) or
          (token == b'1' and 'empty_continue' in host)):
        return b'', complete
    elif token == b'0':
        if 'continue_token' in host:
            token = b'continue'
        else:
            complete = True
            token = b'extra' if 'extra_token' in host else None
    elif token:
        token = bytes((token[0]-1,))
    else:
        token = host[0].encode('ascii')

    if token == b'0':
        if 'step_error' in host:
            return (b'errtok' if 'errtok' in host else b'error'), complete

        complete = True

    return token, complete