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:
-
other(SignPublicKey) –The public key to check against.
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)
¶
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.
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:
-
public_key(SignPublicKey) –The public key for verification.
-
secret_key(SignSecretKey) –The secret key for signing.
__init__(kp)
¶
Initialize a SignKeyPair instance.
Parameters:
-
kp(str | bytes | Self | SignSecretKey | Buffer) –The key pair to initialize with. This can be a SignSecretKey or a bytes-like object.
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.
class Signer ¶
Bases: BaseSigner
Signer is used to create signatures for messages using a secret key.
Attributes:
-
key(SignSecretKey) –The secret key used for signing.
__init__(private_key, *, ctx=None, data=None)
¶
Initialize a Signer instance.
Parameters:
-
private_key(SignSecretKey | str | bytes | Buffer) –The secret key used for signing.
-
ctx(str | bytes | Context | Buffer | None, default:None) –Optional context for the signer.
-
data(bytes | Buffer | None, default:None) –Optional initial data to update the signer with.
Raises:
-
ValueError–If the private key is None.
-
TypeError–If the private key is of an unsupported type.
-
SignException–If the signer fails to initialize.
sign()
¶
Create a signature for the data that has been updated in the signer.
Returns:
-
bytes–A bytes object containing the signature.
Raises:
-
RuntimeError–If the signer has already been finalized.
-
SignException–If the signature creation fails.
update(data)
¶
Update the signer or verifier with new data.
Parameters:
Returns:
-
Self–The updated signer or verifier instance.
Raises:
-
SignException–If the update fails.
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:
-
ValueError–If the file object is None.
-
TypeError–If fileobj is not a file-like or path-like object.
-
SignException–If the update fails.
write(data)
¶
Write data to the signer or verifier.
This method is similar to update but returns the length of the data written.
Parameters:
Returns:
-
int–The length of the data written.
Raises:
-
SignException–If the write fails.
class Verifier ¶
Bases: BaseSigner
Verifier is used to verify signatures created with a corresponding secret key.
Attributes:
-
key(SignPublicKey) –The public key used for verification.
__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:
-
ValueError–If the public key is None.
-
TypeError–If the public key is of an unsupported type.
-
SignException–If the verifier fails to initialize.
update(data)
¶
Update the signer or verifier with new data.
Parameters:
Returns:
-
Self–The updated signer or verifier instance.
Raises:
-
SignException–If the update fails.
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:
-
ValueError–If the file object is None.
-
TypeError–If fileobj is not a file-like or path-like object.
-
SignException–If the update fails.
verify(signature)
¶
Verify a signature against the data that has been updated in the verifier.
Parameters:
Raises:
-
ValueError–If the signature is None or not of the correct length.
-
RuntimeError–If the verifier has already been finalized.
-
VerifyException–If the verification fails.
write(data)
¶
Write data to the signer or verifier.
This method is similar to update but returns the length of the data written.
Parameters:
Returns:
-
int–The length of the data written.
Raises:
-
SignException–If the write fails.
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.