apsig.ld_signature
apsig.ld_signature provide signer and verifier implementation of Linked Data Signatures 1.0.
A class for signing and verifying Linked Data signatures using the RSA signature algorithm.
Attributes:
| Name | Type | Description |
|---|---|---|
|
|
The RSA private key used for signing. |
|
|
The corresponding RSA public key. |
Methods:
| Name | Description |
|---|---|
|
dict, creator: str, private_key: rsa.RSAPrivateKey, options: dict = None, created: datetime.datetime = None) -> dict: Signs the provided document using the specified RSA private key. |
|
dict, public_key: rsa.RSAPublicKey | str) -> bool: Verifies the signature of the provided document against the given public key. |
sign(doc, creator, private_key, options=None, created=None)
Signs the provided document using the specified RSA private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
|
The document to be signed. |
required |
creator
|
|
The identifier of the creator of the document. |
required |
private_key
|
|
The RSA private key used for signing. |
required |
options
|
|
Additional signing options. Defaults to None. |
None
|
created
|
|
The timestamp when the signature is created. Defaults to the current UTC time if not provided. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
The signed document containing the original data and the signature. |
verify(doc, public_key, raise_on_fail=False)
Verifies the signature of the provided document against the given public key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
|
The signed document to verify. |
required |
public_key
|
|
The RSA public key in PEM format or as a multibase-encoded string. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
|
True if the signature is valid; otherwise, an exception is raised. |
Raises:
| Type | Description |
|---|---|
|
If the signature section is missing in the document. |
|
If the signature type is not recognized. |
|
If the signature verification fails. |