Module bastionlab.keys
Classes
Identity()-
Static methods
create(name: Optional[str] = 'bastionlab-identity', password: Optional[bytes] = None) ‑> bastionlab.keys.SigningKey-
Generate a new signing key with the given name and password.
Args: name: The name to use for the signing key. If not provided, the default name "bastionlab-identity" will be used. password: The password to use to encrypt the signing key. If not provided, the key will not be encrypted.
Returns: The generated signing key.
load(name: str) ‑> bastionlab.keys.SigningKey-
Load a signing key with the given name.
Args: name: The name of the signing key to load.
Returns: The signing key with the given name.
PublicKey()-
A class for representing a public key. This class provides methods for encrypting and verifying messages, as well as converting the key to and from various formats (e.g. bytes, PEM).
Initialize a
PublicKeyinstance with a given public key type.Args: key: An EC public key type.
Static methods
from_bytes_content(content: bytes) ‑> bastionlab.keys.PublicKey-
Load a
PublicKeyinstance from a DER-encoded byte string.Args: content: The DER-encoded byte string to load the key from.
Returns: The
PublicKeyinstance loaded from the given byte string. from_pem(path: str) ‑> bastionlab.keys.PublicKey-
Load a
PublicKeyinstance from a PEM-encoded file.Args: path: The path to the file to load the key from.
Returns: The
PublicKeyinstance loaded from the given file. from_pem_content(content: bytes) ‑> bastionlab.keys.PublicKey-
Load a
PublicKeyinstance from a PEM-encoded byte string.Args: content: The PEM-encoded byte string to load the key from.
Returns: The
PublicKeyinstance loaded from the given byte string.
Instance variables
hash: bytes-
Get the hash of this
PublicKeyinstance.Returns: The hash of this
PublicKeyinstance. pem: str-
Get the PEM encoding of this
PublicKeyinstance.Returns: The PEM encoding of this
PublicKeyinstance.
Methods
__eq__(self, o: object) ‑> bool-
Compare this
PublicKeyinstance with another object for equality.Args: o: The object to compare with.
Returns: True if the objects are equal, False otherwise.
as_bytes(self) ‑> bytes-
Get the DER encoding of this
PublicKeyinstance.Returns: The DER encoding of this
PublicKeyinstance. save_pem(self, path: str) ‑> bastionlab.keys.PublicKey-
Save this
PublicKeyinstance to a PEM-encoded file.Args: path: The path to save the key to.
Returns: This
PublicKeyinstance. verify(self, signature: bytes, data: bytes) ‑> None-
Verify that the given signature is valid for the given data.
Args: signature: A signature to verify. data: The data that the signature should be for.
Raises: ValueError: if the signature is not valid for the given data.
SigningKey()-
A class for representing a signing key. This class is used for creating digital signatures and verifying them. It contains both the private key (used for signing) and the corresponding public key (used for verification).
Static methods
from_pem(path: str, password: Optional[bytes] = None) ‑> bastionlab.keys.SigningKey-
Load a
PublicKeyinstance from a PEM-encoded file.Args: path: The path to the file to load the key from.
Returns: The
PublicKeyinstance loaded from the given file. from_pem_content(content: bytes, password: Optional[bytes] = None) ‑> bastionlab.keys.SigningKey-
Load a
SigningKeyinstance from a PEM-encoded byte string.Args: content: The PEM-encoded byte string to load the key from. password: The password to use to decrypt the key, if it is encrypted.
Returns: The
SigningKeyinstance loaded from the given byte string. generate() ‑> bastionlab.keys.SigningKey-
Generate a new
SigningKeyinstance.Returns: A new
SigningKeyinstance. keygen(path: str, password: Optional[bytes] = None) ‑> bastionlab.keys.SigningKey-
Generate a new signing key and save it to the given file.
Args: path: The path to the file to save the signing key to. password: The password to use to encrypt the signing key. If not provided, the key will not be encrypted.
Returns: The generated signing key.
Instance variables
pubkey: bastionlab.keys.PublicKey-
Get the public key associated with this
SigningKeyinstance.Returns: The public key associated with this
SigningKeyinstance.
Methods
__eq__(self, o: object) ‑> bool- Return self==value.
save_pem(self, path: str, password: Optional[bytes] = None) ‑> bastionlab.keys.SigningKey-
Save this
PublicKeyinstance to a PEM-encoded file.Args: path: The path to save the key to.
Returns: This
PublicKeyinstance. sign(self, data: bytes) ‑> bytes-
Sign the given data with this
SigningKeyinstance's private key.Args: data: The data to sign.
Returns: The signature for the given data.