How to use the sshpubkeys.exceptions.InvalidOptionsError function in sshpubkeys

To help you get started, we’ve selected a few sshpubkeys examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ojarva / python-sshpubkeys / tests / invalid_options.py View on Github external
from sshpubkeys.exceptions import (InvalidOptionNameError, InvalidOptionsError, MissingMandatoryOptionValueError,
                                   UnknownOptionNameError)

options = [
    ["includes_space", "no-user-rc ", InvalidOptionsError],
    ["includes_space_multiple", "no-user-rc, port-forwarding", InvalidOptionsError],
    ["includes_space_before_comma", "no-user-rc ,port-forwarding", InvalidOptionsError],
    ["empty_option_end", "no-user-rc,", InvalidOptionsError],
    ["empty_option_beginning", ",no-user-rc", InvalidOptionsError],
    ["empty_option_middle", "no-user-rc,,port-forwarding", InvalidOptionsError],
    ["unbalanced_quotes", 'from="asdf', InvalidOptionsError],
    ["invalid_characters_in_key_percent", 'from%', InvalidOptionNameError],
    ["invalid_characters_in_key_parenthesis", 'from)', InvalidOptionNameError],
    ["invalid_characters_in_key_space", 'fr om', InvalidOptionNameError],
    ["unknown_option_name", "random-option-name", UnknownOptionNameError],
    ["unbalanced_quotes_complex", 'from="asdf",no-user-rc"', InvalidOptionsError],
    ["parameter_missing", 'from,no-user-rc"', MissingMandatoryOptionValueError],
]
github ojarva / python-sshpubkeys / sshpubkeys / keys.py View on Github external
i = 1  # Need to be set for empty options strings
        for i, character in enumerate(options):
            if character == '"':  # only double quotes are allowed, no need to care about single quotes
                quote_open = not quote_open
            if quote_open:
                continue
            if character == ",":
                opt = options[start_of_current_opt:i]
                parse_add_single_option(opt)
                start_of_current_opt = i + 1
                # Data begins after the first space
        if start_of_current_opt + 1 != i:
            opt = options[start_of_current_opt:]
            parse_add_single_option(opt)
        if quote_open:
            raise InvalidOptionsError("Unbalanced quotes.")
        return parsed_options
github ojarva / python-sshpubkeys / sshpubkeys / exceptions.py View on Github external
"""Invalid option name (contains disallowed characters, or is unrecognized.)."""


class InvalidOptionNameError(InvalidOptionNameException):
    """Invalid option name (contains disallowed characters, or is unrecognized.)."""


class UnknownOptionNameException(InvalidOptionsError):
    """Unrecognized option name."""


class UnknownOptionNameError(UnknownOptionNameException):
    """Unrecognized option name."""


class MissingMandatoryOptionValueException(InvalidOptionsError):
    """Mandatory option value is missing."""


class MissingMandatoryOptionValueError(MissingMandatoryOptionValueException):
    """Mandatory option value is missing."""
github ojarva / python-sshpubkeys / sshpubkeys / keys.py View on Github external
# Check key type
        current_position, unpacked_key_type = self._unpack_by_int(self._decoded_key, 0)
        if key_type is not None and key_type != unpacked_key_type.decode():
            raise InvalidTypeError("Keytype mismatch: %s != %s" % (key_type, unpacked_key_type))

        self.key_type = unpacked_key_type

        key_data_length = self._process_key(self._decoded_key[current_position:])
        current_position = current_position + key_data_length

        if current_position != len(self._decoded_key):
            raise MalformedDataError("Leftover data: %s bytes" % (len(self._decoded_key) - current_position))

        if self.disallow_options and self.options:
            raise InvalidOptionsError("Options are disallowed.")
github ojarva / python-sshpubkeys / sshpubkeys / exceptions.py View on Github external
"""Options string is invalid: it contains invalid characters, unrecognized options, or is otherwise malformed."""


class InvalidOptionsError(InvalidOptionsException):
    """Options string is invalid: it contains invalid characters, unrecognized options, or is otherwise malformed."""


class InvalidOptionNameException(InvalidOptionsError):
    """Invalid option name (contains disallowed characters, or is unrecognized.)."""


class InvalidOptionNameError(InvalidOptionNameException):
    """Invalid option name (contains disallowed characters, or is unrecognized.)."""


class UnknownOptionNameException(InvalidOptionsError):
    """Unrecognized option name."""


class UnknownOptionNameError(UnknownOptionNameException):
    """Unrecognized option name."""


class MissingMandatoryOptionValueException(InvalidOptionsError):
    """Mandatory option value is missing."""


class MissingMandatoryOptionValueError(MissingMandatoryOptionValueException):
    """Mandatory option value is missing."""
github ojarva / python-sshpubkeys / sshpubkeys / exceptions.py View on Github external
"""The key is invalid - unable to parse the data. The data may be corrupted, truncated, or includes extra content that is not allowed."""


class MalformedDataError(MalformedDataException):
    """The key is invalid - unable to parse the data. The data may be corrupted, truncated, or includes extra content that is not allowed."""


class InvalidOptionsException(MalformedDataError):
    """Options string is invalid: it contains invalid characters, unrecognized options, or is otherwise malformed."""


class InvalidOptionsError(InvalidOptionsException):
    """Options string is invalid: it contains invalid characters, unrecognized options, or is otherwise malformed."""


class InvalidOptionNameException(InvalidOptionsError):
    """Invalid option name (contains disallowed characters, or is unrecognized.)."""


class InvalidOptionNameError(InvalidOptionNameException):
    """Invalid option name (contains disallowed characters, or is unrecognized.)."""


class UnknownOptionNameException(InvalidOptionsError):
    """Unrecognized option name."""


class UnknownOptionNameError(UnknownOptionNameException):
    """Unrecognized option name."""


class MissingMandatoryOptionValueException(InvalidOptionsError):