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
OrderedDict
of headers that appear, in order, in the ASCII-armored form of this object.
-
classmethod
from_file
(filename)¶ Create a new
PGPKey
object, with contents loaded from a file. May be binary or ASCII armored.Parameters: filename ( str
) – The path to the file to load.Raises: ValueError
if a properly formed PGP block was not found in the file atfilename
Raises: PGPError
if de-armoring or parsing failedReturns: A two element tuple
ofPGPKey
,OrderedDict
. TheOrderedDict
has 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
PGPKey
object, with contents loaded from a blob. May be binary or ASCII armored.Parameters: blob ( str
,bytes
,unicode
,bytearray
) – The data to load.Raises: TypeError
if blob is not in the expected types aboveRaises: ValueError
if a properly formed PGP block was not found inblob
Raises: PGPError
if de-armoring or parsing failedReturns: A two element tuple
ofPGPKey
,OrderedDict
. TheOrderedDict
has the following format:key, others = PGPKey.from_file('path/to/keyfile') # others: { (Fingerprint, bool(key.is_public)): PGPKey }
-
created
¶ A
datetime
object of the creation date and time of the key, in UTC.
-
expires_at
¶ A
datetime
object of when this key is to be considered expired, if any. Otherwise,None
-
fingerprint
¶ The fingerprint of this key, as a
Fingerprint
object.
-
is_expired
¶ True
if this key is expired, otherwiseFalse
-
is_primary
¶ True
if this is a primary key;False
if this is a subkey
-
is_protected
¶ True
if this is a private key that is protected with a passphrase, otherwiseFalse
-
is_public
¶ True
if this is a public key, otherwiseFalse
-
is_unlocked
¶ False
if this is a private key that is protected with a passphrase and has not yet been unlocked, otherwiseTrue
-
key_algorithm
¶ The
constants.PubKeyAlgorithm
pertaining to this key
-
key_size
¶ new in 0.4.1 The size pertaining to this key.
int
for non-EC key algorithms;constants.EllipticCurveOID
for EC keys.
-
pubkey
¶ If the
PGPKey
object is a private key, this method returns a corresponding public key object with all the trimmings. Otherwise, returnsNone
-
signers
¶ A
set
of key ids of keys that were used to sign this key
-
subkeys
¶ An
OrderedDict
of 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 (
int
orEllipticCurveOID
) – Key size in bits, unless key_algorithm isECDSA
orECDH
, 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
UserWarning
if the key is public or not passphrase protected.Parameters: passphrase (str) – The passphrase to be used to unlock this key. Raises: PGPDecryptionError
if 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
, orNone
if 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
PGPUID
object; 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
PGPKey
that does not have any subkeys of its ownParameters: usage ( set
) – Aset
of key usage flags, asKeyFlags
for 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: PGPError
if the key is passphrase-protected and has not been unlockedRaises: PGPError
if the key is publicReturns: PGPSignature
The 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: PGPError
if the key is passphrase-protected and has not been unlockedRaises: PGPError
if 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
) – Aset
of 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 atimedelta
of 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 (
tuple
of twoint
s) – Specify the level and amount of trust to assert when certifying a public key. Should be a tuple of twoint
s, 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: PGPError
if the key is passphrase-protected and has not been unlockedRaises: PGPError
if the key is publicReturns: PGPSignature
In 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
) – ThePGPKey
to specify as a valid revocation key.Raises: PGPError
if the key is passphrase-protected and has not been unlockedRaises: PGPError
if the key is publicReturns: PGPSignature
In 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 desiredSymmetricKeyAlgorithm
to generate the session key!Raises: PGPEncryptionError
if encryption failed for any reason.Returns: A new
PGPMessage
with the encrypted contents ofmessage
The 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 PGPMessage
Raises: PGPError
if the key is not private, or protected but not unlocked.Raises: PGPDecryptionError
if decryption fails for any other reason.Returns: A new PGPMessage
with 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
OrderedDict
of 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 inargs
can be any of the formats supported byPGPKey.from_path()
andPGPKey.from_blob()
, or alist
ortuple
of these.Returns: a set
containing the unique fingerprints of all of the keys that were loaded during this operation.
-
key
(identifier)¶ A context-manager method. Yields the first
PGPKey
object that matches the provided identifier.Parameters: identifier ( PGPMessage
,PGPSignature
,str
) – The identifier to use to select a loaded key.Raises: KeyError
if 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
set
of 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
OrderedDict
of headers that appear, in order, in the ASCII-armored form of this object.
-
classmethod
from_file
(filename)¶ Create a new
PGPMessage
object, with contents loaded from a file. May be binary or ASCII armored.Parameters: filename ( str
) – The path to the file to load.Raises: ValueError
if a properly formed PGP block was not found in the file atfilename
Raises: PGPError
if de-armoring or parsing failedReturns: PGPMessage
-
classmethod
from_blob
(blob)¶ Create a new
PGPMessage
object, with contents loaded from a blob. May be binary or ASCII armored.Parameters: blob ( str
,bytes
,unicode
,bytearray
) – The data to load.Raises: TypeError
if blob is not in the expected types aboveRaises: ValueError
if a properly formed PGP block was not found inblob
Raises: PGPError
if de-armoring or parsing failedReturns: PGPMessage
-
encrypters
¶ A
set
containing 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
¶ True
if this message will be compressed when exported
-
is_encrypted
¶ True
if this message is encrypted; otherwise,False
-
is_sensitive
¶ True
if this message is marked sensitive; otherwiseFalse
-
is_signed
¶ True
if this message is signed; otherwise,False
. Should always beFalse
if the message is encrypted.
-
issuers
¶ A
set
containing all key ids (if any) which have signed or encrypted this message.
-
message
¶ The message contents
-
signatures
¶ A
set
containing all key ids (if any) which have signed this message.
-
signers
¶ A
set
containing 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: PGPMessage
The following optional keyword arguments can be used with
PGPMessage.new()
:Parameters: - file (
bool
) – if True,message
should 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 (
str
representing 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
,bytes
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 desiredSymmetricKeyAlgorithm
to generate the session key!Raises: Returns: A new
PGPMessage
containing 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: PGPDecryptionError
if decryption failed for any reason.Returns: A new PGPMessage
containing 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
OrderedDict
of headers that appear, in order, in the ASCII-armored form of this object.
-
classmethod
from_file
(filename)¶ Create a new
PGPSignature
object, with contents loaded from a file. May be binary or ASCII armored.Parameters: filename ( str
) – The path to the file to load.Raises: ValueError
if a properly formed PGP block was not found in the file atfilename
Raises: PGPError
if de-armoring or parsing failedReturns: PGPSignature
-
classmethod
from_blob
(blob)¶ Create a new
PGPSignature
object, with contents loaded from a blob. May be binary or ASCII armored.Parameters: blob ( str
,bytes
,unicode
,bytearray
) – The data to load.Raises: TypeError
if blob is not in the expected types aboveRaises: ValueError
if a properly formed PGP block was not found inblob
Raises: PGPError
if de-armoring or parsing failedReturns: PGPSignature
-
cipherprefs
¶ A
list
of preferred symmetric algorithms specified in this signature, if any. Otherwise, an emptylist
.
-
compprefs
¶ A
list
of preferred compression algorithms specified in this signature, if any. Otherwise, an emptylist
.
-
created
¶ A
datetime
of when this signature was created.
-
expires_at
¶ A
datetime
of when this signature expires, if a signature expiration date is specified. Otherwise,None
-
exportable
¶ False
if this signature is marked as being not exportable. Otherwise,True
.
-
features
¶ A
set
of implementation features specified in this signature, if any. Otherwise, an emptyset
.
-
hashprefs
¶ A
list
of preferred hash algorithms specified in this signature, if any. Otherwise, an emptylist
.
-
hash_algorithm
¶ The
HashAlgorithm
used when computing this signature.
-
is_expired
¶ True
if the signature has an expiration date, and is expired. Otherwise,False
-
key_algorithm
¶ The
PubKeyAlgorithm
of the key that generated this signature.
-
keyserver
¶ The preferred key server specified in this signature, if any. Otherwise, an empty
str
.
-
keyserverprefs
¶ A
list
ofKeyServerPreferences
in this signature, if any. Otherwise, an emptylist
.
-
notation
¶ A
dict
of 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
¶ False
if 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
SignatureType
of 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
¶ True
if this is a User ID, otherwise False.
-
is_ua
¶ True
if 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
-bool
of whether the signature verified successfully or not.sigsubj.by
- thePGPKey
that was used in this verify operation.sigsubj.signature
- thePGPSignature
that 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
-bool
of whether the signature verified successfully or not.sigsubj.by
- thePGPKey
that was used in this verify operation.sigsubj.signature
- thePGPSignature
that 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 otherFingerprint
instances.Primarily used as a key for internal dictionaries, so it ignores spaces when comparing and hashing