l.s.g.i.IGPGHandler(Interface) : interface documentation

Part of lp.services.gpg.interfaces View In Hierarchy

Handler to perform OpenPGP operations.
Method sanitizeFingerprint Return sanitized fingerprint if well-formed.
Method getURLForKeyInServer Return the URL for that fingerprint on the configured keyserver.
Method getVerifiedSignatureResilient Wrapper for getVerifiedSignature.
Method getVerifiedSignature Returns a PymeSignature object if content is correctly signed.
Method importPublicKey Import the given public key into our local keyring.
Method importSecretKey Import the given secret key into our local keyring.
Method generateKey Generate a new GPG key with the given name.
Method encryptContent Encrypt the given content for the given key.
Method signContent Signs content with a given GPG key.
Method retrieveKey Retrieve the key information from the local keyring.
Method retrieveActiveKey Retrieve key information, raise errors if the key is not active.
Method uploadPublicKey Upload the specified public key to a keyserver.
Method localKeys Return an iterator of all keys locally known about.
Method resetLocalState Reset the local state.
def sanitizeFingerprint(fingerprint):
Return sanitized fingerprint if well-formed.

If the firgerprint cannot be sanitized return None.

def getURLForKeyInServer(fingerprint, action=None, public=False):
Return the URL for that fingerprint on the configured keyserver.

If public is True, return a URL for the public keyserver; otherwise, references the default (internal) keyserver. If action is provided, will attach that to the URL.

def getVerifiedSignatureResilient(content, signature=None):
Wrapper for getVerifiedSignature.

This calls the target method up to three times. Successful results are returned immediately, and GPGKeyExpired errors are raised immediately. Otherwise, captures the errors and raises GPGVerificationError with the accumulated error information.

def getVerifiedSignature(content, signature=None):
Returns a PymeSignature object if content is correctly signed.

If signature is None, we assume content is clearsigned. Otherwise it stores the detached signature and content should contain the plain text in question.

content and signature must be 8-bit encoded str objects. It's up to the caller to encode or decode as appropriate.

ParameterscontentThe content to be verified as string;
signatureThe signature as string (or None if content is clearsigned)
Returnsa PymeSignature object.
RaisesGPGVerificationErrorif the signature cannot be verified.
GPGKeyExpiredif the signature was made with an expired key.
GPGKeyNotFoundErrorif the key was not found on the keyserver.
def importPublicKey(content):
Import the given public key into our local keyring.

If the secret key's ASCII armored content is given, SecretGPGKeyDetected is raised.

If no key is found, GPGKeyNotFoundError is raised. On the other hand, if more than one key is found, MoreThanOneGPGKeyFound is raised.

Parameterscontentpublic key ASCII armored content (must be an ASCII string (it's up to the caller to encode or decode properly);
Returnsa PymeKey object referring to the public key imported.
def importSecretKey(content):
Import the given secret key into our local keyring.

If no key is found, GPGKeyNotFoundError is raised. On the other hand, if more than one key is found, MoreThanOneGPGKeyFound is raised.

Parameterscontentsecret key ASCII armored content (must be an ASCII string (it's up to the caller to encode or decode properly);
Returnsa PymeKey object referring to the secret key imported.
def generateKey(name):
Generate a new GPG key with the given name.

Currently only passwordless, signo-only 1024-bit RSA keys are generated.

Parametersnameunicode to be included in the key paramenters, 'comment' and 'email' will be empty. It's content will be encoded to 'utf-8' internally.
Returnsa PymeKey object for the just-generated secret key.
RaisesAssertionErrorif the key generation is not exaclty what we expect.
def encryptContent(content, key):
Encrypt the given content for the given key.

content must be a traditional string. It's up to the caller to encode or decode properly.

Parameterscontentthe Unicode content to be encrypted.
keythe IPymeKey to encrypt the content for.
Returnsthe encrypted content or None if failed.
def signContent(content, key, password='', mode=None):
Signs content with a given GPG key.
Parameterscontentthe content to sign.
keythe IPymeKey to use when signing the content.
passwordoptional password to the key identified by key_fingerprint, the default value is '',
modeoptional type of GPG signature to produce, the default mode is gpgme.SIG_MODE_CLEAR (clearsigned signatures)
ReturnsThe ASCII-armored signature for the content.
def retrieveKey(fingerprint):
Retrieve the key information from the local keyring.

If the key with the given fingerprint is not present in the local
keyring, first import it from the key server into the local keyring.

:param fingerprint: The key fingerprint, which must be an hexadecimal
    string.
:raise GPGKeyNotFoundError: if the key is not found neither in the
    local keyring nor in the key server.
:return: a `PymeKey`object containing the key information.
def retrieveActiveKey(fingerprint):
Retrieve key information, raise errors if the key is not active.

Exactly like `retrieveKey` except raises errors if the key is expired
or has been revoked.

:param fingerprint: The key fingerprint, which must be an hexadecimal
    string.
:raise GPGKeyNotFoundError: if the key is not found neither in the
    local keyring nor in the key server.
:return: a `PymeKey`object containing the key information.
def uploadPublicKey(fingerprint):
Upload the specified public key to a keyserver.

Use retrieveKey to get the public key content and upload an ASCII-armored export chunk.

ParametersfingerprintThe key fingerprint, which must be an hexadecimal string.
RaisesGPGUploadFailureif the keyserver could not be reaches.
AssertionErrorif the POST request doesn't succeed.
def localKeys(filter=None, secret=False):
Return an iterator of all keys locally known about.
Parametersfilteroptional string used to filter the results. By default gpgme tries to match '<name> [comment] [email]', the full fingerprint or the key ID (fingerprint last 8 digits);
secretoptional boolean, restrict the domain to secret or public keys available in the keyring. Defaults to False.
Returnsa PymeKey generator with the matching keys.
def resetLocalState():
Reset the local state.

Resets OpenPGP keyrings and trust database.

API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.