openssh_key.key.Key

class openssh_key.key.Key(header, params, footer, clear=None)

Bases: Generic[openssh_key.key_params.common.PublicKeyParamsTypeVar], abc.ABC

A container for a PublicKeyParams, an encoded header and footer, and cleartext key details.

Parameters
__init__(header, params, footer, clear=None)

Methods

__init__(header, params, footer[, clear])

create_key_params(key_type, key_params_dict)

Converts a typing.Mapping of parameter values to a PublicKeyParams object of a given key type.

create_key_params_dict(key_type, byte_stream)

Reads parameter values from a given bytestream for a given key type.

from_byte_stream(byte_stream[, clear])

Reads parameter values, encoded header, and encoded footer from a given bytestream.

from_bytes(byte_string[, clear])

Parses parameter values, encoded header, and encoded footer from a given byte string.

from_string(string)

Parses parameter values, encoded header, encoded footer, and cleartext key details from a given string in OpenSSH public key format.

get_footer_format_instructions_dict()

The Pascal-style byte stream format instructions for the encoded footer.

get_header_format_instructions_dict()

The Pascal-style byte stream format instructions for the encoded header.

pack_public_bytes()

Packs the public parameter values, encoded header, and encoded footer into a byte string.

pack_public_string([use_footer_comment, ...])

Packs the parameter values, encoded header, encoded footer, and cleartext key details into a string in OpenSSH public key format.

Attributes

FOOTER_FORMAT_INSTRUCTIONS_DICT

The Pascal-style byte stream format instructions for the encoded footer.

HEADER_FORMAT_INSTRUCTIONS_DICT

The Pascal-style byte stream format instructions for the encoded header.

FOOTER_FORMAT_INSTRUCTIONS_DICT = mappingproxy({})

The Pascal-style byte stream format instructions for the encoded footer.

HEADER_FORMAT_INSTRUCTIONS_DICT = mappingproxy({})

The Pascal-style byte stream format instructions for the encoded header.

abstract static create_key_params(key_type, key_params_dict)

Converts a typing.Mapping of parameter values to a PublicKeyParams object of a given key type.

Parameters
  • key_type (str) – The key type name.

  • key_params_dict (Mapping[str, Any]) – The parameter values.

Return type

TypeVar(PublicKeyParamsTypeVar, bound= PublicKeyParams)

Returns

A PublicKeyParams containing the parameter values in key_params_dict.

static create_key_params_dict(key_type, byte_stream)

Reads parameter values from a given bytestream for a given key type.

Parameters
Return type

Mapping[str, Any]

Returns

A typing.Mapping containing the read parameter values.

classmethod from_byte_stream(byte_stream, clear=None)

Reads parameter values, encoded header, and encoded footer from a given bytestream.

Parameters
Return type

TypeVar(KeyTypeVar, bound= Key[Any])

Returns

A Key object containing the parameter values, encoded header, encoded footer, and cleartext key details.

classmethod from_bytes(byte_string, clear=None)

Parses parameter values, encoded header, and encoded footer from a given byte string.

Parameters
  • byte_string (bytes) – The byte string from which to parse.

  • clear (Optional[Mapping[str, Any]]) – Cleartext key details to add to the returned object.

Return type

TypeVar(KeyTypeVar, bound= Key[Any])

Returns

A Key object containing the parameter values, encoded header, encoded footer, and cleartext key details.

Raises

UserWarning – There are additional bytes in the encoded key than would be expected from the key count.

classmethod from_string(string)

Parses parameter values, encoded header, encoded footer, and cleartext key details from a given string in OpenSSH public key format.

Parameters

string (str) – The string from which to parse.

Return type

TypeVar(KeyTypeVar, bound= Key[Any])

Returns

A Key object containing the parameter values, encoded header, encoded footer, and cleartext key details.

Raises

UserWarning – The cleartext key type and the encoded key type do not match, or there are additional bytes in the encoded key than would be expected from the key count.

The Pascal-style byte stream format instructions for the encoded footer.

Return type

Mapping[str, Union[str, PascalStyleFormatInstruction, PascalStyleFormatInstructionStringLengthSize]]

abstract static get_header_format_instructions_dict()

The Pascal-style byte stream format instructions for the encoded header.

Return type

Mapping[str, Union[str, PascalStyleFormatInstruction, PascalStyleFormatInstructionStringLengthSize]]

pack_public_bytes()

Packs the public parameter values, encoded header, and encoded footer into a byte string.

Return type

bytes

Returns

A byte string containing the public parameter values, encoded header, and encoded footer.

pack_public_string(use_footer_comment=True, use_clear_comment=True)

Packs the parameter values, encoded header, encoded footer, and cleartext key details into a string in OpenSSH public key format.

Parameters
  • use_footer_comment (bool) – Append the comment in the footer, if any, as cleartext to the encoded string.

  • use_clear_comment (bool) – Append the comment in the cleartext key details, if any, to the encoded string (if use_footer_comment is true, appends after the comment in the footer).

Return type

str

Returns

A string containing the parameter values, encoded header, encoded footer, and cleartext key details.