openssh_key.private_key_list.PrivateKeyList¶
- class openssh_key.private_key_list.PrivateKeyList(initlist, byte_string=None, header=None, cipher_bytes=None, kdf_options=None, decipher_bytes=None, decipher_bytes_header=None, decipher_padding=None)¶
Bases:
collections.UserListA container for multiple pairs of
PublicKeyandPrivateKey.The format of an OpenSSH private key list file is specified in the openssh-key-v1 vendor extension, base64-encoded with a PEM-style header and footer (wrapped at 70 characters per line).
At present, OpenSSH only supports one key in a private key list file.
- Parameters
initlist (
List[PublicPrivateKeyPair]) – A list of pairs ofPublicKeyandPrivateKey.byte_string (
Optional[bytes]) – The original byte string from whichinitlistwas parsed.header (
Optional[Mapping[str,Any]]) – The values in the encoded header of the key list.cipher_bytes (
Optional[bytes]) – The original encrypted private byte string.kdf_options (
Optional[KDFOptions]) – The values in the key derivation function parameters.decipher_bytes (
Optional[bytes]) – The original decrypted private byte string.decipher_bytes_header (
Optional[Mapping[str,Any]]) – The values in the header of the decrypted private byte string.decipher_padding (
Optional[bytes]) – The values that pad the decrypted private byte string.
- __init__(initlist, byte_string=None, header=None, cipher_bytes=None, kdf_options=None, decipher_bytes=None, decipher_bytes_header=None, decipher_padding=None)¶
Methods
__init__(initlist[, byte_string, header, ...])append(item)S.append(value) -- append value to the end of the sequence
clear()copy()count(value)extend(other)S.extend(iterable) -- extend sequence by appending elements from the iterable
from_bytes(byte_string[, passphrase])Parses a private key list from a given byte string.
from_list(key_pair_list[, cipher, kdf, ...])Constructs and initializes a private key list from a given list of key pairs and metadata.
from_string(string[, passphrase])Parses a private key list from a given string.
The Pascal-style byte stream format instructions for the header of the decrypted private byte string.
The Pascal-style byte stream format instructions for the encoded header of the key list.
get_openssh_private_key_footer()- rtype
get_openssh_private_key_header()- rtype
get_wrap_col()- rtype
index(value, [start, [stop]])Raises ValueError if the value is not present.
insert(i, item)S.insert(index, value) -- insert value before index
pack_bytes([passphrase, include_indices, ...])Packs the private key list into a byte string.
pack_string([passphrase, include_indices, ...])Packs the private key list into a string.
pop([index])Raise IndexError if list is empty or index is out of range.
remove(item)S.remove(value) -- remove first occurrence of value.
reverse()S.reverse() -- reverse IN PLACE
sort(*args, **kwds)Attributes
The Pascal-style byte stream format instructions for the header of the decrypted private byte string.
The Pascal-style byte stream format instructions for the encoded header of the key list.
OPENSSH_PRIVATE_KEY_FOOTEROPENSSH_PRIVATE_KEY_HEADERWRAP_COL- DECIPHER_BYTES_HEADER_FORMAT_INSTRUCTIONS_DICT = mappingproxy({'check_int_1': '>I', 'check_int_2': '>I'})¶
The Pascal-style byte stream format instructions for the header of the decrypted private byte string.
- HEADER_FORMAT_INSTRUCTIONS_DICT = mappingproxy({'auth_magic': '15s', 'cipher': <PascalStyleFormatInstruction.STRING: <class 'str'>>, 'kdf': <PascalStyleFormatInstruction.STRING: <class 'str'>>, 'kdf_options': <PascalStyleFormatInstruction.BYTES: <class 'bytes'>>, 'num_keys': '>i'})¶
The Pascal-style byte stream format instructions for the encoded header of the key list.
- append(item)¶
S.append(value) – append value to the end of the sequence
- clear() None -- remove all items from S¶
- count(value) integer -- return number of occurrences of value¶
- extend(other)¶
S.extend(iterable) – extend sequence by appending elements from the iterable
- classmethod from_bytes(byte_string, passphrase=None)¶
Parses a private key list from a given byte string.
- Parameters
- Return type
TypeVar(PrivateKeyListTypeVar, bound=PrivateKeyList)- Returns
A
PrivateKeyListobject containing the private key list.- Raises
ValueError – The provided byte string is not an
openssh-key-v1key list or the declared key count is negative.UserWarning – The check numbers in the decrypted private byte string do not match (likely due to an incorrect passphrase), the key type or parameter values of a private key do not match that of the corresponding public key in the list, or the padding bytes at the end of the decrypted private byte string are not as expected.
- classmethod from_list(key_pair_list, cipher='none', kdf='none', kdf_options=None)¶
Constructs and initializes a private key list from a given list of key pairs and metadata.
- Parameters
key_pair_list (
List[PublicPrivateKeyPair]) – The list of key pairs to add to the returned private key list.cipher (
str) – The cipher type to add to the header of the private key list.kdf (
str) – The key derivation function type to add to the header of the private key list.kdf_options (
Optional[KDFOptions]) – The key derivation function parameters to add to the private key list.
- Return type
TypeVar(PrivateKeyListTypeVar, bound=PrivateKeyList)- Returns
A
PrivateKeyListobject containing the given list of key pairs and metadata.- Raises
ValueError – The given list contains an item that is not a key pair.
- classmethod from_string(string, passphrase=None)¶
Parses a private key list from a given string.
- Parameters
- Return type
TypeVar(PrivateKeyListTypeVar, bound=PrivateKeyList)- Returns
A
PrivateKeyListobject containing the private key list.- Raises
ValueError – The file does not have the expected PEM-style headers, the provided byte string is not an
openssh-key-v1key list, or the declared key count is negative.UserWarning – The check numbers in the decrypted private byte string do not match (likely due to an incorrect passphrase), the key type or parameter values of a private key do not match that of the corresponding public key in the list, or the padding bytes at the end of the decrypted private byte string are not as expected.
- static get_decipher_bytes_header_format_instructions_dict()¶
The Pascal-style byte stream format instructions for the header of the decrypted private byte string.
- static get_header_format_instructions_dict()¶
The Pascal-style byte stream format instructions for the encoded header of the key list.
- index(value[, start[, stop]]) integer -- return first index of value.¶
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- insert(i, item)¶
S.insert(index, value) – insert value before index
- pack_bytes(passphrase=None, include_indices=None, override_public_with_private=True, retain_kdf_options_if_present=False)¶
Packs the private key list into a byte string.
- Parameters
passphrase (
Optional[str]) – The passphrase with which to encrypt the private byte string. If not provided, will be prompted for at standard input if needed.include_indices (
Optional[List[int]]) – A list of indices into the private key list for the key pairs to include in the returned byte string.override_public_with_private (
bool) – IfFalse, packs the public bytes of each key from the public key of each key pair. IfTrue, ignores the public key of each key pair, instead packing the public bytes from the public parameters of the private key.retain_kdf_options_if_present (
bool) – IfFalse, packs the key derivation function parameters in this private key list object. IfTrue, generates and packs new key derivation function parameters.
- Return type
- Returns
A byte string containing the private key list.
- Raises
IndexError –
include_indicescontains an index that is out of range for this private key list.
- pack_string(passphrase=None, include_indices=None, override_public_with_private=True, retain_kdf_options_if_present=False)¶
Packs the private key list into a string.
- Parameters
passphrase (
Optional[str]) – The passphrase with which to encrypt the private byte string. If not provided, will be prompted for at standard input if needed.include_indices (
Optional[List[int]]) – A list of indices into the private key list for the key pairs to include in the returned byte string.override_public_with_private (
bool) – IfFalse, packs the public bytes of each key from the public key of each key pair. IfTrue, ignores the public key of each key pair, instead packing the public bytes from the public parameters of the private key.retain_kdf_options_if_present (
bool) – IfFalse, packs the key derivation function parameters in this private key list object. IfTrue, generates and packs new key derivation function parameters.
- Return type
- Returns
A string containing the private key list.
- Raises
IndexError –
include_indicescontains an index that is out of range for this private key list.
- pop([index]) item -- remove and return item at index (default last).¶
Raise IndexError if list is empty or index is out of range.
- remove(item)¶
S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.
- reverse()¶
S.reverse() – reverse IN PLACE