pki.util.keys

Utility methods for private key generation and hash algorithm retrieval.

Classes

AutoGenPkiKeyAlgorithm

The key algorithms supported by the AutoGenPKI.

KeyGenerator

Utility class for generating private keys.

CryptographyUtils

Utilities methods for cryptography corresponding to Trustpoint models.

Functions

is_supported_public_key(public_key)

TypeGuard function that narrows down the public key type.

Module Contents

class pki.util.keys.AutoGenPkiKeyAlgorithm(*args, **kwds)[source]

Bases: django.db.models.TextChoices

The key algorithms supported by the AutoGenPKI.

RSA2048 = ('RSA2048SHA256', 'RSA2048')[source]
RSA4096 = ('RSA4096SHA256', 'RSA4096')[source]
SECP256R1 = ('SECP256R1SHA256', 'SECP256R1')[source]
to_public_key_info()[source]

Gets the corresponding public key info for the key algorithm.

Return type:

trustpoint_core.oid.PublicKeyInfo

class pki.util.keys.KeyGenerator[source]

Utility class for generating private keys.

static generate_private_key_for_public_key_info(key_info)[source]

Generates a private key for a public key info.

Returns:

The generated private key.

Parameters:

key_info (trustpoint_core.oid.PublicKeyInfo)

Return type:

trustpoint_core.crypto_types.PrivateKey

static generate_private_key(domain)[source]

Generates a key pair of the type corresponding to the domain model.

Parameters:

domain (pki.models.domain.DomainModel) – The domain to consider.

Returns:

The generated private key / key pair serializer.

Return type:

trustpoint_core.serializer.PrivateKeySerializer

class pki.util.keys.CryptographyUtils[source]

Utilities methods for cryptography corresponding to Trustpoint models.

static get_hash_algorithm_for_private_key(private_key)[source]

Gets a suitable hash algorithm for a given private key.

Parameters:

private_key (trustpoint_core.crypto_types.PrivateKey) – The private key to consider.

Returns:

The hash algorithm to use.

Return type:

cryptography.hazmat.primitives.hashes.HashAlgorithm

pki.util.keys.is_supported_public_key(public_key)[source]

TypeGuard function that narrows down the public key type.

Parameters:

public_key (Any) – The loaded public key to check if it is supported.

Returns:

True if it is supported, False otherwise.

Return type:

TypeGuard[trustpoint_core.crypto_types.PublicKey]