Skip to content

Signature

class SignSecretKey

SignSecretKey represents a secret key used for signing messages.

__init__(key)

Initialize a SignSecretKey instance.

Parameters:

Raises:

  • MemoryError

    If memory allocation for the key fails.

  • ValueError

    If the key is None or not of the correct length.

  • TypeError

    If the key is of an unsupported type.

check_public_key(other)

Check if the provided public key matches the one derived from this secret key.

Parameters:

Returns:

  • bool

    True if the public key matches, False otherwise.

read_from(reader) classmethod

Create a key from a reader.

Parameters:

  • reader (Reader) –

    A reader object that supports the read method.

Returns:

  • Self

    A new instance of SignSecretKey read from the provided reader.

Raises:

  • TypeError

    If the provided reader does not have a 'read' method.

  • ValueError

    If the read data is not 64 bytes long.

signer(ctx=None)

Create a Signer instance using this secret key.

The Signer can be used to sign messages.

Parameters:

Returns:

  • Signer

    An instance of Signer initialized with this secret key.

writeto(out)

Write the key to a writer.

Parameters:

  • out (Writer) –

    A writer object that supports the write method.

Returns:

  • int

    The number of bytes written, which should be 64.

Raises:

  • TypeError

    If the provided writer does not have a 'write' method.

class SignPublicKey

SignPublicKey represents a public key used for signature verification.

__init__(key)

Initialize a SignPublicKey instance.

Parameters:

Raises:

  • MemoryError

    If memory allocation for the key fails.

  • ValueError

    If the key is None or not of the correct length.

  • TypeError

    If the key is of an unsupported type.

read_from(reader) classmethod

Create a key from a reader.

Parameters:

  • reader (Reader) –

    A reader object that supports the read method.

Returns:

  • Self

    A new instance of SignPublicKey read from the provided reader.

Raises:

  • TypeError

    If the provided reader does not have a 'read' method.

  • ValueError

    If the read data is not 32 bytes long.

verifier(ctx=None)

Create a Verifier instance using this public key.

The Verifier can be used to verify signatures created with the corresponding secret key.

Parameters:

Returns:

  • Verifier

    An instance of Verifier initialized with this public key.

writeto(out)

Write the key to a writer.

Parameters:

  • out (Writer) –

    A writer object that supports the write method.

Returns:

  • int

    The number of bytes written, which should be 32.

Raises:

  • TypeError

    If the provided writer does not have a 'write' method.

class SignKeyPair

SignKeyPair represents a pair of secret and public keys used for signing and verifying messages.

All attributes are read-only after initialization.

Attributes:

__init__(kp)

Initialize a SignKeyPair instance.

Parameters:

Raises:

  • MemoryError

    If memory allocation for the key fails.

  • ValueError

    If the key is None or not of the correct length.

  • TypeError

    If the key is of an unsupported type.

gen() classmethod

Generate a random SignKeyPair.

Returns:

  • Self

    An instance of SignKeyPair initialized with a newly generated secret key.

signer(ctx=None)

Create a Signer instance using the secret key of this key pair.

The Signer can be used to sign messages.

Returns:

  • Signer

    An instance of Signer initialized with the secret key of this key pair.

verifier(ctx=None)

Create a Verifier instance using the public key of this key pair.

The Verifier can be used to verify signatures created with the corresponding secret key.

Returns:

  • Verifier

    An instance of Verifier initialized with the public key of this key pair.

class Signer

Bases: BaseSigner

Signer is used to create signatures for messages using a secret key.

Attributes:

__init__(private_key, *, ctx=None, data=None)

Initialize a Signer instance.

Parameters:

Raises:

sign()

Create a signature for the data that has been updated in the signer.

Returns:

  • bytes

    A bytes object containing the signature.

Raises:

update(data)

Update the signer or verifier with new data.

Parameters:

  • data (bytes | Buffer) –

    The data to update the signer or verifier with.

Returns:

  • Self

    The updated signer or verifier instance.

Raises:

update_from(fileobj, chunk_size=...)

Update the signer or verifier with data read from a file-like/path-like object.

Parameters:

  • fileobj (str | PathLike | BinaryIO) –

    A file-like or path-like object to read data from.

  • chunk_size (int, default: ... ) –

    The size of chunks to read from the file object.

Returns:

  • Self

    The updated signer or verifier instance.

Raises:

write(data)

Write data to the signer or verifier.

This method is similar to update but returns the length of the data written.

Parameters:

  • data (bytes | Buffer) –

    The data to write to the signer or verifier.

Returns:

  • int

    The length of the data written.

Raises:

class Verifier

Bases: BaseSigner

Verifier is used to verify signatures created with a corresponding secret key.

Attributes:

__init__(public_key, *, ctx=None, data=None)

Initialize a Verifier instance.

Parameters:

  • public_key (SignPublicKey | str | bytes | Buffer) –

    The public key used for signature verification.

  • ctx (str | bytes | Context | Buffer | None, default: None ) –

    Optional context for the verifier.

  • data (bytes | Buffer | None, default: None ) –

    Optional initial data to update the verifier with.

Raises:

update(data)

Update the signer or verifier with new data.

Parameters:

  • data (bytes | Buffer) –

    The data to update the signer or verifier with.

Returns:

  • Self

    The updated signer or verifier instance.

Raises:

update_from(fileobj, chunk_size=...)

Update the signer or verifier with data read from a file-like/path-like object.

Parameters:

  • fileobj (str | PathLike | BinaryIO) –

    A file-like or path-like object to read data from.

  • chunk_size (int, default: ... ) –

    The size of chunks to read from the file object.

Returns:

  • Self

    The updated signer or verifier instance.

Raises:

verify(signature)

Verify a signature against the data that has been updated in the verifier.

Parameters:

  • signature (bytes | Buffer) –

    The signature to verify, must be 64 bytes long.

Raises:

write(data)

Write data to the signer or verifier.

This method is similar to update but returns the length of the data written.

Parameters:

  • data (bytes | Buffer) –

    The data to write to the signer or verifier.

Returns:

  • int

    The length of the data written.

Raises:

sign_file(key, fileobj, ctx=None, chunk_size=...)

Sign a file using the provided secret key.

Parameters:

  • key (SignSecretKey | str | bytes | Buffer) –

    The secret key used for signing.

  • fileobj (str | PathLike | BinaryIO) –

    A file-like or path-like object to read data from.

  • ctx (str | bytes | Context | Buffer | None, default: None ) –

    Optional context for the signer.

  • chunk_size (int, default: ... ) –

    The size of chunks to read from the file object.

Returns:

  • bytes

    A bytes object containing the signature.

Raises:

  • ValueError

    If the key or file object is None.

  • TypeError

    If the key is not a SignSecretKey, fileobj is not a file-like object, or the context is invalid.

  • SignException

    If the signing process fails.

verify_file(key, fileobj, signature, ctx=None, chunk_size=...)

Verify a signature against the data read from a file using the provided public key.

Parameters:

  • key (SignPublicKey | str | bytes | Buffer) –

    The public key used for signature verification.

  • fileobj (str | PathLike | BinaryIO) –

    A file-like or path-like object to read data from.

  • signature (bytes | Buffer) –

    The signature to verify, must be 64 bytes long.

  • ctx (str | bytes | Context | Buffer | None, default: None ) –

    Optional context for the verifier.

  • chunk_size (int, default: ... ) –

    The size of chunks to read from the file object.

Raises:

  • ValueError

    If the key, file object, or signature is None, or if the signature is not of the correct length.

  • TypeError

    If the key is not a SignPublicKey, fileobj is not a file-like object, or the context is invalid.

  • VerifyException

    If the verification process fails.