Skip to content

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
private_key RSAPrivateKey

The RSA private key used for signing.

public_key RSAPublicKey

The corresponding RSA public key.

Methods:

Name Description
sign

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.

verify

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 dict

The document to be signed.

required
creator str

The identifier of the creator of the document.

required
private_key RSAPrivateKey

The RSA private key used for signing.

required
options dict

Additional signing options. Defaults to None.

None
created datetime

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 dict

The signed document to verify.

required
public_key RSAPublicKey | str

The RSA public key in PEM format or as a multibase-encoded string.

required

Returns:

Name Type Description
bool Union[str, None]

True if the signature is valid; otherwise, an exception is raised.

Raises:

Type Description
MissingSignature

If the signature section is missing in the document.

UnknownSignature

If the signature type is not recognized.

VerificationFailed

If the signature verification fails.