PGPy API¶
Exceptions¶
PGPEncryptionError¶
-
exception
pgpy.errors.PGPEncryptionError¶ Raised when encryption fails
PGPDecryptionError¶
-
exception
pgpy.errors.PGPDecryptionError¶ Raised when decryption fails
PGPOpenSSLCipherNotSupported¶
-
exception
pgpy.errors.PGPOpenSSLCipherNotSupported¶ Raised when OpenSSL does not support the requested cipher
PGPInsecureCipher¶
-
exception
pgpy.errors.PGPInsecureCipher¶ Raised when a cipher known to be insecure is attempted to be used to encrypt data
WontImplementError¶
-
exception
pgpy.errors.WontImplementError¶ Raised when something that is not implemented, will not be implemented
Constants¶
EllipticCurveOID¶
-
class
pgpy.constants.EllipticCurveOID¶ An enumeration.
-
Curve25519¶ DJB’s fast elliptic curve
Warning
This curve is not currently usable by PGPy
-
Ed25519¶ Twisted Edwards variant of Curve25519
Warning
This curve is not currently usable by PGPy
-
NIST_P256¶ NIST P-256, also known as SECG curve secp256r1
-
NIST_P384¶ NIST P-384, also known as SECG curve secp384r1
-
NIST_P521¶ NIST P-521, also known as SECG curve secp521r1
-
Brainpool_P256¶ Brainpool Standard Curve, 256-bit
Note
Requires OpenSSL >= 1.0.2
-
Brainpool_P384¶ Brainpool Standard Curve, 384-bit
Note
Requires OpenSSL >= 1.0.2
-
Brainpool_P512¶ Brainpool Standard Curve, 512-bit
Note
Requires OpenSSL >= 1.0.2
-
SECP256K1¶ SECG curve secp256k1
-
SymmetricKeyAlgorithm¶
-
class
pgpy.constants.SymmetricKeyAlgorithm¶ Supported symmetric key algorithms.
-
IDEA¶ Warning
IDEA is insecure. PGPy only allows it to be used for decryption, not encryption!
-
TripleDES¶ Triple-DES with 168-bit key derived from 192
-
CAST5¶ CAST5 (or CAST-128) with 128-bit key
-
Blowfish¶ Blowfish with 128-bit key and 16 rounds
-
AES128¶ AES with 128-bit key
-
AES192¶ AES with 192-bit key
-
AES256¶ AES with 256-bit key
-
Camellia128¶ Camellia with 128-bit key
-
Camellia192¶ Camellia with 192-bit key
-
Camellia256¶ Camellia with 256-bit key
-
KeyFlags¶
-
class
pgpy.constants.KeyFlags¶ An enumeration.
-
Certify¶ Signifies that a key may be used to certify keys and user ids. Primary keys always have this, even if it is not specified.
-
Sign¶ Signifies that a key may be used to sign messages and documents.
-
EncryptCommunications¶ Signifies that a key may be used to encrypt messages.
-
EncryptStorage¶ Signifies that a key may be used to encrypt storage. Currently equivalent to
EncryptCommunications.
-
Split¶ Signifies that the private component of a given key may have been split by a secret-sharing mechanism. Split keys are not currently supported by PGPy.
-
Authentication¶ Signifies that a key may be used for authentication.
-
MultiPerson¶ Signifies that the private component of a key may be in the possession of more than one person.
-
RevocationReason¶
-
class
pgpy.constants.RevocationReason¶ An enumeration.
-
NotSpecified¶ No reason was specified. This is the default reason.
-
Superseded¶ The key was superseded by a new key. Only meaningful when revoking a key.
-
Compromised¶ Key material has been compromised. Only meaningful when revoking a key.
-
Retired¶ Key is retired and no longer used. Only meaningful when revoking a key.
-
UserID¶ User ID information is no longer valid. Only meaningful when revoking a certification of a user id.
-
Classes¶
PGPKey¶
-
class
pgpy.PGPKey¶ PGPKey objects represent OpenPGP compliant keys along with all of their associated data.
PGPKey implements the __str__ method, the output of which will be the key composition in OpenPGP-compliant ASCII-armored format.
PGPKey implements the __bytes__ method, the output of which will be the key composition in OpenPGP-compliant binary format.
Any signatures within the PGPKey that are marked as being non-exportable will not be included in the output of either of those methods.
-
ascii_header= OrderedDict([('Version', 'PGPy v|version|')])¶ An
OrderedDictof headers that appear, in order, in the ASCII-armored form of this object.
-
classmethod
from_file(filename)¶ Create a new
PGPKeyobject, with contents loaded from a file. May be binary or ASCII armored.Parameters: filename ( str) – The path to the file to load.Raises: ValueErrorif a properly formed PGP block was not found in the file atfilenameRaises: PGPErrorif de-armoring or parsing failedReturns: A two element tupleofPGPKey,OrderedDict. TheOrderedDicthas the following format:key, others = PGPKey.from_file('path/to/keyfile') # others: { (Fingerprint, bool(key.is_public)): PGPKey }
-
classmethod
from_blob(blob)¶ Create a new
PGPKeyobject, with contents loaded from a blob. May be binary or ASCII armored.Parameters: blob ( str,bytes,unicode,bytearray) – The data to load.Raises: TypeErrorif blob is not in the expected types aboveRaises: ValueErrorif a properly formed PGP block was not found inblobRaises: PGPErrorif de-armoring or parsing failedReturns: A two element tupleofPGPKey,OrderedDict. TheOrderedDicthas the following format:key, others = PGPKey.from_file('path/to/keyfile') # others: { (Fingerprint, bool(key.is_public)): PGPKey }
-
created¶ A
datetimeobject of the creation date and time of the key, in UTC.
-
expires_at¶ A
datetimeobject of when this key is to be considered expired, if any. Otherwise,None
-
fingerprint¶ The fingerprint of this key, as a
Fingerprintobject.
-
is_expired¶ Trueif this key is expired, otherwiseFalse
-
is_primary¶ Trueif this is a primary key;Falseif this is a subkey
-
is_protected¶ Trueif this is a private key that is protected with a passphrase, otherwiseFalse
-
is_public¶ Trueif this is a public key, otherwiseFalse
-
is_unlocked¶ Falseif this is a private key that is protected with a passphrase and has not yet been unlocked, otherwiseTrue
-
key_algorithm¶ The
constants.PubKeyAlgorithmpertaining to this key
-
key_size¶ new in 0.4.1 The size pertaining to this key.
intfor non-EC key algorithms;constants.EllipticCurveOIDfor EC keys.
-
pubkey¶ If the
PGPKeyobject is a private key, this method returns a corresponding public key object with all the trimmings. Otherwise, returnsNone
-
signers¶ A
setof key ids of keys that were used to sign this key
-
subkeys¶ An
OrderedDictof subkeys bound to this primary key, if applicable, selected by 16-character keyid.
-
classmethod
new(key_algorithm, key_size)¶ Generate a new PGP key
Parameters: - key_algorithm (A
PubKeyAlgorithm) – Key algorithm to use. - key_size (
intorEllipticCurveOID) – Key size in bits, unless key_algorithm isECDSAorECDH, in which case it should be the Curve OID to use.
Returns: A newly generated
PGPKey- key_algorithm (A
-
protect(passphrase, enc_alg, hash_alg)¶ Add a passphrase to a private key. If the key is already passphrase protected, it should be unlocked before a new passphrase can be specified.
Has no effect on public keys.
Parameters: - passphrase (
str,unicode) – A passphrase to protect the key with - enc_alg (
SymmetricKeyAlgorithm) – Symmetric encryption algorithm to use to protect the key - hash_alg (
HashAlgorithm) – Hash algorithm to use in the String-to-Key specifier
- passphrase (
-
unlock(passphrase)¶ Context manager method for unlocking passphrase-protected private keys. Has no effect if the key is not both private and passphrase-protected.
When the context managed block is exited, the unprotected private key material is removed.
Example:
privkey = PGPKey() privkey.parse(keytext) assert privkey.is_protected assert privkey.is_unlocked is False # privkey.sign("some text") <- this would raise an exception with privkey.unlock("TheCorrectPassphrase"): # privkey is now unlocked assert privkey.is_unlocked # so you can do things with it sig = privkey.sign("some text") # privkey is no longer unlocked assert privkey.is_unlocked is False
Emits a
UserWarningif the key is public or not passphrase protected.Parameters: passphrase (str) – The passphrase to be used to unlock this key. Raises: PGPDecryptionErrorif the passphrase is incorrect
-
add_uid(uid, selfsign=True, **prefs)¶ Add a User ID to this key.
Parameters: - uid (
PGPUID) – The user id to add - selfsign (
bool) – Whether or not to self-sign the user id before adding it
Valid optional keyword arguments are identical to those of self-signatures for
PGPKey.certify(). Any such keyword arguments are ignored if selfsign isFalse- uid (
-
get_uid(search)¶ Find and return a User ID that matches the search string given.
Parameters: search ( str,unicode) – A text string to match name, comment, or email address againstReturns: The first matching PGPUID, orNoneif no matches were found.
-
del_uid(search)¶ Find and remove a user id that matches the search string given. This method does not modify the corresponding
PGPUIDobject; it only removes it from the list of user ids on the key.Parameters: search ( str,unicode) – A text string to match name, comment, or email address against
-
add_subkey(key, **prefs)¶ Add a key as a subkey to this key. :param key: A private
PGPKeythat does not have any subkeys of its ownParameters: usage ( set) – Asetof key usage flags, asKeyFlagsfor the subkey to be added.Other valid optional keyword arguments are identical to those of self-signatures for
PGPKey.certify()
-
sign(subject, **prefs)¶ Sign text, a message, or a timestamp using this key.
Parameters: subject ( str,PGPMessage,None) – The text to be signedRaises: PGPErrorif the key is passphrase-protected and has not been unlockedRaises: PGPErrorif the key is publicReturns: PGPSignatureThe following optional keyword arguments can be used with
PGPKey.sign(), as well asPGPKey.certify(),PGPKey.revoke(), andPGPKey.bind():Parameters: - expires (
datetime,timedelta) – Set an expiration date for this signature - notation (
dict) – Add arbitrary notation data to this signature. - policy_uri (
str) – Add a URI to the signature that should describe the policy under which the signature was issued. - revocable (
bool) – IfFalse, this signature will be marked non-revocable - user (
str) – Specify which User ID to use when creating this signature. Also adds a “Signer’s User ID” to the signature.
- expires (
-
certify(subject, level=<SignatureType.Generic_Cert: 16>, **prefs)¶ Sign a key or a user id within a key.
Parameters: - subject (
PGPKey,PGPUID) – The user id or key to be certified. - level –
Generic_Cert,Persona_Cert,Casual_Cert, orPositive_Cert. Only used if subject is aPGPUID; otherwise, it is ignored.
Raises: PGPErrorif the key is passphrase-protected and has not been unlockedRaises: PGPErrorif the key is publicReturns: In addition to the optional keyword arguments accepted by
PGPKey.sign(), the following optional keyword arguments can be used withPGPKey.certify().These optional keywords only make sense, and thus only have an effect, when self-signing a key or User ID:
Parameters: - usage (
set) – Asetof key usage flags, asKeyFlags. This keyword is ignored for non-self-certifications. - ciphers (
list) – A list of preferred symmetric ciphers, asSymmetricKeyAlgorithm. This keyword is ignored for non-self-certifications. - hashes (
list) – A list of preferred hash algorithms, asHashAlgorithm. This keyword is ignored for non-self-certifications. - compression (
list) – A list of preferred compression algorithms, asCompressionAlgorithm. This keyword is ignored for non-self-certifications. - key_expiration (
datetime.datetime,datetime.timedelta) – Specify a key expiration date for when this key should expire, or atimedeltaof how long after the key was created it should expire. This keyword is ignored for non-self-certifications. - keyserver (
str,unicode,bytes) – Specify the URI of the preferred key server of the user. This keyword is ignored for non-self-certifications. - primary (
bool) – Whether or not to consider the certified User ID as the primary one. This keyword is ignored for non-self-certifications, and any certifications directly on keys.
These optional keywords only make sense, and thus only have an effect, when signing another key or User ID:
Parameters: - trust (
tupleof twoints) – Specify the level and amount of trust to assert when certifying a public key. Should be a tuple of twoints, specifying the trust level and trust amount. See RFC 4880 Section 5.2.3.13. Trust Signature for more on what these values mean. - regex (
str) – Specify a regular expression to constrain the specified trust signature in the resulting signature. Symbolically signifies that the specified trust signature only applies to User IDs which match this regular expression. This is meaningless without also specifying trust level and amount.
- subject (
-
revoke(target, **prefs)¶ Revoke a key, a subkey, or all current certification signatures of a User ID that were generated by this key so far.
Parameters: target ( PGPKey,PGPUID) – The key to revokeRaises: PGPErrorif the key is passphrase-protected and has not been unlockedRaises: PGPErrorif the key is publicReturns: PGPSignatureIn addition to the optional keyword arguments accepted by
PGPKey.sign(), the following optional keyword arguments can be used withPGPKey.revoke().Parameters: - reason (One of
constants.RevocationReason.) – Defaults toconstants.RevocationReason.NotSpecified - comment (
str) – Defaults to an empty string.
- reason (One of
-
revoker(revoker, **prefs)¶ Generate a signature that specifies another key as being valid for revoking this key.
Parameters: revoker ( PGPKey) – ThePGPKeyto specify as a valid revocation key.Raises: PGPErrorif the key is passphrase-protected and has not been unlockedRaises: PGPErrorif the key is publicReturns: PGPSignatureIn addition to the optional keyword arguments accepted by
PGPKey.sign(), the following optional keyword arguments can be used withPGPKey.revoker().Parameters: sensitive ( bool) – IfTrue, this sets the sensitive flag on the RevocationKey subpacket. Currently, this has no other effect.
-
bind(key, **prefs)¶ Bind a subkey to this key.
Valid optional keyword arguments are identical to those of self-signatures for
PGPkey.certify()
-
verify(subject, signature=None)¶ Verify a subject with a signature using this key.
Parameters: - subject (
str,unicode,None,PGPMessage,PGPKey,PGPUID) – The subject to verify - signature (
PGPSignature) – If the signature is detached, it should be specified here.
Returns: - subject (
-
encrypt(message, sessionkey=None, **prefs)¶ Encrypt a PGPMessage using this key.
Parameters: message (
PGPMessage) – The message to encrypt.Optional param sessionkey: Provide a session key to use when encrypting something. Default is
None. IfNone, a session key of the appropriate length will be generated randomly.Warning
Care should be taken when making use of this option! Session keys absolutely need to be unpredictable! Use the
gen_key()method on the desiredSymmetricKeyAlgorithmto generate the session key!Raises: PGPEncryptionErrorif encryption failed for any reason.Returns: A new
PGPMessagewith the encrypted contents ofmessageThe following optional keyword arguments can be used with
PGPKey.encrypt():Parameters: - cipher (
SymmetricKeyAlgorithm) – Specifies the symmetric block cipher to use when encrypting the message. - user (
str,unicode) – Specifies the User ID to use as the recipient for this encryption operation, for the purposes of preference defaults and selection validation.
- cipher (
-
decrypt(message)¶ Decrypt a PGPMessage using this key.
Parameters: message – An encrypted PGPMessageRaises: PGPErrorif the key is not private, or protected but not unlocked.Raises: PGPDecryptionErrorif decryption fails for any other reason.Returns: A new PGPMessagewith the decrypted contents ofmessage.
-
PGPKeyring¶
-
class
pgpy.PGPKeyring(*args)¶ PGPKeyring objects represent in-memory keyrings that can contain any combination of supported private and public keys. It can not currently be conveniently exported to a format that can be understood by GnuPG.
-
ascii_header¶ An
OrderedDictof headers that appear, in order, in the ASCII-armored form of this object.
-
load(*args)¶ Load all keys provided into this keyring object.
Parameters: *args ( list,tuple,str,unicode,bytes,bytearray) – Each arg inargscan be any of the formats supported byPGPKey.from_path()andPGPKey.from_blob(), or alistortupleof these.Returns: a setcontaining the unique fingerprints of all of the keys that were loaded during this operation.
-
key(identifier)¶ A context-manager method. Yields the first
PGPKeyobject that matches the provided identifier.Parameters: identifier ( PGPMessage,PGPSignature,str) – The identifier to use to select a loaded key.Raises: KeyErrorif there is no loaded key that satisfies the identifier.
-
fingerprints(keyhalf='any', keytype='any')¶ List loaded fingerprints with some optional filtering.
Parameters: - keyhalf (str) – Can be ‘any’, ‘public’, or ‘private’. If ‘public’, or ‘private’, the fingerprints of keys of the the other type will not be included in the results.
- keytype (str) – Can be ‘any’, ‘primary’, or ‘sub’. If ‘primary’ or ‘sub’, the fingerprints of keys of the the other type will not be included in the results.
Returns: a
setof fingerprints of keys matching the filters specified.
-
unload(key)¶ Unload a loaded key and its subkeys.
The easiest way to do this is to select a key using
PGPKeyring.key()first:with keyring.key("DSA von TestKey") as key: keyring.unload(key)
Parameters: key ( PGPKey) – The key to unload.
-
PGPMessage¶
-
class
pgpy.PGPMessage¶ PGPMessage objects represent OpenPGP message compositions.
PGPMessage implements the __str__ method, the output of which will be the message composition in OpenPGP-compliant ASCII-armored format.
PGPMessage implements the __bytes__ method, the output of which will be the message composition in OpenPGP-compliant binary format.
Any signatures within the PGPMessage that are marked as being non-exportable will not be included in the output of either of those methods.
-
ascii_header¶ An
OrderedDictof headers that appear, in order, in the ASCII-armored form of this object.
-
classmethod
from_file(filename)¶ Create a new
PGPMessageobject, with contents loaded from a file. May be binary or ASCII armored.Parameters: filename ( str) – The path to the file to load.Raises: ValueErrorif a properly formed PGP block was not found in the file atfilenameRaises: PGPErrorif de-armoring or parsing failedReturns: PGPMessage
-
classmethod
from_blob(blob)¶ Create a new
PGPMessageobject, with contents loaded from a blob. May be binary or ASCII armored.Parameters: blob ( str,bytes,unicode,bytearray) – The data to load.Raises: TypeErrorif blob is not in the expected types aboveRaises: ValueErrorif a properly formed PGP block was not found inblobRaises: PGPErrorif de-armoring or parsing failedReturns: PGPMessage
-
encrypters¶ A
setcontaining all key ids (if any) to which this message was encrypted.
-
filename¶ If applicable, returns the original filename of the message. Otherwise, returns an empty string.
-
is_compressed¶ Trueif this message will be compressed when exported
-
is_encrypted¶ Trueif this message is encrypted; otherwise,False
-
is_sensitive¶ Trueif this message is marked sensitive; otherwiseFalse
-
is_signed¶ Trueif this message is signed; otherwise,False. Should always beFalseif the message is encrypted.
-
issuers¶ A
setcontaining all key ids (if any) which have signed or encrypted this message.
-
message¶ The message contents
-
signatures¶ A
setcontaining all key ids (if any) which have signed this message.
-
signers¶ A
setcontaining all key ids (if any) which have signed this message.
-
classmethod
new(message, **kwargs)¶ Create a new PGPMessage object.
Parameters: message ( str,unicode,bytes,bytearray) – The message to be stored.Returns: PGPMessageThe following optional keyword arguments can be used with
PGPMessage.new():Parameters: - file (
bool) – if True,messageshould be a path to a file. The contents of that file will be read and used as the contents of the message. - cleartext (
bool) – if True, the message will be cleartext with inline signatures. - sensitive (
bool) – if True, the filename will be set to ‘_CONSOLE’ to signal other OpenPGP clients to treat this message as being ‘for your eyes only’. Ignored if cleartext is True. - format (
str) – Set the message format identifier. Ignored if cleartext is True. - compression – Set the compression algorithm for the new message.
Defaults to
CompressionAlgorithm.ZIP. Ignored if cleartext is True. - encoding (
strrepresenting a valid codec in codecs) – Set the Charset header for the message.
- file (
-
encrypt(passphrase, sessionkey=None, **prefs)¶ Encrypt the contents of this message using a passphrase. :param passphrase: The passphrase to use for encrypting this message. :type passphrase:
str,unicode,bytesOptional param sessionkey: Provide a session key to use when encrypting something. Default is
None. IfNone, a session key of the appropriate length will be generated randomly.Warning
Care should be taken when making use of this option! Session keys absolutely need to be unpredictable! Use the
gen_key()method on the desiredSymmetricKeyAlgorithmto generate the session key!Raises: Returns: A new
PGPMessagecontaining the encrypted contents of this message.
-
decrypt(passphrase)¶ Attempt to decrypt this message using a passphrase.
Parameters: passphrase ( str,unicode,bytes) – The passphrase to use to attempt to decrypt this message.Raises: PGPDecryptionErrorif decryption failed for any reason.Returns: A new PGPMessagecontaining the decrypted contents of this message
-
PGPSignature¶
-
class
pgpy.PGPSignature¶ PGPSignature objects represent OpenPGP compliant signatures.
PGPSignature implements the
__str__method, the output of which will be the signature object in OpenPGP-compliant ASCII-armored format.PGPSignature implements the
__bytes__method, the output of which will be the signature object in OpenPGP-compliant binary format.-
ascii_header¶ An
OrderedDictof headers that appear, in order, in the ASCII-armored form of this object.
-
classmethod
from_file(filename)¶ Create a new
PGPSignatureobject, with contents loaded from a file. May be binary or ASCII armored.Parameters: filename ( str) – The path to the file to load.Raises: ValueErrorif a properly formed PGP block was not found in the file atfilenameRaises: PGPErrorif de-armoring or parsing failedReturns: PGPSignature
-
classmethod
from_blob(blob)¶ Create a new
PGPSignatureobject, with contents loaded from a blob. May be binary or ASCII armored.Parameters: blob ( str,bytes,unicode,bytearray) – The data to load.Raises: TypeErrorif blob is not in the expected types aboveRaises: ValueErrorif a properly formed PGP block was not found inblobRaises: PGPErrorif de-armoring or parsing failedReturns: PGPSignature
-
cipherprefs¶ A
listof preferred symmetric algorithms specified in this signature, if any. Otherwise, an emptylist.
-
compprefs¶ A
listof preferred compression algorithms specified in this signature, if any. Otherwise, an emptylist.
-
created¶ A
datetimeof when this signature was created.
-
expires_at¶ A
datetimeof when this signature expires, if a signature expiration date is specified. Otherwise,None
-
exportable¶ Falseif this signature is marked as being not exportable. Otherwise,True.
-
features¶ A
setof implementation features specified in this signature, if any. Otherwise, an emptyset.
-
hashprefs¶ A
listof preferred hash algorithms specified in this signature, if any. Otherwise, an emptylist.
-
hash_algorithm¶ The
HashAlgorithmused when computing this signature.
-
is_expired¶ Trueif the signature has an expiration date, and is expired. Otherwise,False
-
key_algorithm¶ The
PubKeyAlgorithmof the key that generated this signature.
-
keyserver¶ The preferred key server specified in this signature, if any. Otherwise, an empty
str.
-
keyserverprefs¶ A
listofKeyServerPreferencesin this signature, if any. Otherwise, an emptylist.
-
notation¶ A
dictof notation data in this signature, if any. Otherwise, an emptydict.
-
policy_uri¶ The policy URI specified in this signature, if any. Otherwise, an empty
str.
-
revocable¶ Falseif this signature is marked as being not revocable. Otherwise,True.
-
signer¶ The 16-character Key ID of the key that generated this signature.
-
type¶ The
SignatureTypeof this signature.
-
PGPUID¶
-
class
pgpy.PGPUID¶ PGPUID objects represent User IDs and User Attributes for keys.
PGPUID implements the
__format__method for User IDs, returning a string in the format ‘name (comment) <email>’, leaving out any comment or email fields that are not present.-
name¶ If this is a User ID, the stored name. If this is not a User ID, this will be an empty string.
-
comment¶ If this is a User ID, this will be the stored comment. If this is not a User ID, or there is no stored comment, this will be an empty string.,
-
email¶ If this is a User ID, this will be the stored email address. If this is not a User ID, or there is no stored email address, this will be an empty string.
-
image¶ If this is a User Attribute, this will be the stored image. If this is not a User Attribute, this will be
None.
-
is_primary¶ If the most recent, valid self-signature specifies this as being primary, this will be True. Otherwise, Faqlse.
-
is_uid¶ Trueif this is a User ID, otherwise False.
-
is_ua¶ Trueif this is a User Attribute, otherwise False.
-
selfsig¶ This will be the most recent, self-signature of this User ID or Attribute. If there isn’t one, this will be
None.
-
signers¶ This will be a set of all of the key ids which have signed this User ID or Attribute.
-
classmethod
new(pn, comment='', email='')¶ Create a new User ID or photo.
Parameters: - pn (
bytearray,str,unicode) – User ID name, or photo. If this is abytearray, it will be loaded as a photo. Otherwise, it will be used as the name field for a User ID. - comment (
str,unicode) – The comment field for a User ID. Ignored if this is a photo. - email (
str,unicode) – The email address field for a User ID. Ignored if this is a photo.
Returns: - pn (
-
Other Objects¶
These are objects that are returned during certain operations, but are probably not useful to instantiate directly.
SignatureVerification¶
-
class
pgpy.types.SignatureVerification¶ Returned by
PGPKey.verify()Can be compared directly as a boolean to determine whether or not the specified signature verified.
-
good_signatures¶ A generator yielding namedtuples of all signatures that were successfully verified in the operation that returned this instance. The namedtuple has the following attributes:
sigsubj.verified-boolof whether the signature verified successfully or not.sigsubj.by- thePGPKeythat was used in this verify operation.sigsubj.signature- thePGPSignaturethat was verified.sigsubj.subject- the subject that was verified using the signature.
-
bad_signatures¶ A generator yielding namedtuples of all signatures that were not verified in the operation that returned this instance. The namedtuple has the following attributes:
sigsubj.verified-boolof whether the signature verified successfully or not.sigsubj.by- thePGPKeythat was used in this verify operation.sigsubj.signature- thePGPSignaturethat was verified.sigsubj.subject- the subject that was verified using the signature.
-
Fingerprint¶
-
class
pgpy.types.Fingerprint¶ A subclass of
str. Can be compared using == and != tostr,unicode, and otherFingerprintinstances.Primarily used as a key for internal dictionaries, so it ignores spaces when comparing and hashing