pharmaship.core.gpg

Utilities for GPG signature handling.

class pharmaship.core.gpg.KeyManager

Class used to manage PGP keys used for external data import.

add_key(import_file)

Add a key to the keyring.

Parameters

import_file (file-object) – File object containing the key data.

Returns

True if the key is successfully added.

Return type

bool

Example

>>> from pathlib import Path
>>> my_key_file = Path("pharmaship.pub").open()
>>> km = KeyManager()
>>> km.add_key(my_key_file)
True
check_signature(signed_data)

Check signed data has a valid known signature.

Parameters

signed_data (str) – GPG signed content to verify (armored).

Returns

validated data if the signature is valide, False otherwise.

Return type

bytes or False.

delete_key(fingerprint)

Delete key from the keyring.

Parameters

fingerprint (str) – The fingerprint of the key to delete.

Returns

True if the key is successfully deleted.

Return type

bool

Example

>>> km = KeyManager()
>>> km.delete_key("0123456789ABCDEF0123456789ABCDEF01234567")
True
get_key(fingerprint)

Return a key of the keyring from its fingerprint.

Parameters

fingerprint (str) – The fingerprint of the key to get.

Returns

key data in a dictionary object if found, None otherwise.

Return type

dict or None

key_list()

List trusted keys present in the keyring.

Returns

List of available keys in the keyring.

Return type

list(dict)

Example

>>> km = KeyManager()
>>> km.key_list()
[{'name': 'Pharmaship 2020 <pharmaship@devmaretique.com>',
'fingerprint': '86A7CC93CA482E093C28E5C236A33034D31E80F6'
}]