some minor inspection fixes; documentation

This commit is contained in:
Michael Greene
2014-10-14 13:12:04 -07:00
parent 5c291e4a8c
commit 6fbe57bb96
10 changed files with 168 additions and 14 deletions

View File

@@ -18,7 +18,6 @@ class ProgressTable(Directive):
final_argument_whitespace = True
option_spec = {'text': str}
def create_headrow(self, label="Progress", classes=('prog-top-label',)):
hrow = nodes.row()
hrow += nodes.entry('', nodes.paragraph(text=label), classes=['head'] + list(classes))
@@ -86,7 +85,7 @@ class ProgressTable(Directive):
if nl is not None:
if cur != "":
# finish up shrow
self.add_progbar(shrow, len([c for c in comps[cur] if c == True]), len(comps[cur]))
self.add_progbar(shrow, len([c for c in comps[cur] if c is True]), len(comps[cur]))
cur = nl.groupdict()['component']

View File

@@ -13,9 +13,31 @@ Classes
.. py:classmethod:: from_file(filename)
:noindex:
Create a new :py:obj:`PGPKey` object, with contents loaded from a file. May be binary or ASCII armored.
:param filename: The path to the file to load.
:type filename: ``str``
:returns: A two element ``tuple`` of :py:obj:`PGPKey`, :py:obj:`~collections.OrderedDict`.
The :py:obj:`~collections.OrderedDict` has the following format::
key, others = PGPKey.from_file('path/to/keyfile')
# others: { (Fingerprint, bool(key.is_public): PGPKey }
.. py:classmethod:: from_blob(blob)
:noindex:
Create a new :py:obj:`PGPKey` object, with contents loaded from a blob. May be binary or ASCII armored.
:param blob: The data to load.
:type blob: ``str``, ``bytes``, ``unicode``, ``bytearray``
:returns: A two element ``tuple`` of :py:obj:`PGPKey`, :py:obj:`~collections.OrderedDict`.
The :py:obj:`~collections.OrderedDict` has the following format::
key, others = PGPKey.from_file('path/to/keyfile')
# others: { (Fingerprint, bool(key.is_public): PGPKey }
:py:class:`PGPKeyring`
----------------------
@@ -23,6 +45,7 @@ Classes
:members:
:noindex:
:py:class:`PGPMessage`
----------------------
@@ -33,9 +56,22 @@ Classes
.. py:classmethod:: from_file(filename)
:noindex:
Create a new :py:obj:`PGPMessage` object, with contents loaded from a file. May be binary or ASCII armored.
:param filename: The path to the file to load.
:type filename: ``str``
:returns: :py:obj:`PGPMessage`
.. py:classmethod:: from_blob(blob)
:noindex:
Create a new :py:obj:`PGPMessage` object, with contents loaded from a blob. May be binary or ASCII armored.
:param blob: The data to load.
:type blob: ``str``, ``bytes``, ``unicode``, ``bytearray``
:returns: :py:obj:`PGPMessage`
:py:class:`PGPSignature`
------------------------
@@ -46,9 +82,22 @@ Classes
.. py:classmethod:: from_file(filename)
:noindex:
Create a new :py:obj:`PGPSignature` object, with contents loaded from a file. May be binary or ASCII armored.
:param filename: The path to the file to load.
:type filename: ``str``
:returns: :py:obj:`PGPSignature`
.. py:classmethod:: from_blob(blob)
:noindex:
Create a new :py:obj:`PGPSignature` object, with contents loaded from a blob. May be binary or ASCII armored.
:param blob: The data to load.
:type blob: ``str``, ``bytes``, ``unicode``, ``bytearray``
:returns: :py:obj:`PGPSignature`
:py:class:`PGPUID`
------------------
@@ -56,6 +105,7 @@ Classes
:members:
:noindex:
Other Objects
=============
@@ -63,6 +113,7 @@ Other Objects
These are objects that are returned during certain operations, but are probably not useful to instantiate directly.
:py:class:`~types.SignatureVerification`
----------------------------------------
@@ -70,9 +121,11 @@ These are objects that are returned during certain operations, but are probably
:members:
:noindex:
:py:class:`~types.Fingerprint`
------------------------------
.. autoclass:: Fingerprint
:members:
:noindex:

View File

@@ -3,6 +3,26 @@ Constants
.. py:currentmodule:: pgpy.constants
:py:class:`PubKeyAlgorithm`
---------------------------
.. autoclass:: PubKeyAlgorithm
:no-members:
:noindex:
.. autoattribute:: RSAEncryptOrSign
:noindex:
:annotation:
.. autoattribute:: DSA
:noindex:
:annotation:
.. autoattribute:: ElGamal
:noindex:
:annotation:
:py:class:`SymmetricKeyAlgorithm`
---------------------------------
@@ -42,6 +62,7 @@ Constants
:noindex:
:annotation:
:py:class:`CompressionAlgorithm`
--------------------------------
@@ -100,6 +121,7 @@ Constants
:noindex:
:annotation:
:py:class:`SignatureType`
-------------------------
@@ -163,6 +185,7 @@ Constants
:noindex:
:annotation:
:py:class:`KeyFlags`
--------------------
@@ -170,3 +193,59 @@ Constants
:no-members:
:noindex:
.. autoattribute:: Certify
:noindex:
:annotation:
.. autoattribute:: Sign
:noindex:
:annotation:
.. autoattribute:: EncryptCommunications
:noindex:
:annotation:
.. autoattribute:: EncryptStorage
:noindex:
:annotation:
.. autoattribute:: Split
:noindex:
:annotation:
.. autoattribute:: Authentication
:noindex:
:annotation:
.. autoattribute:: MultiPerson
:noindex:
:annotation:
:py:class:`RevocationReason`
----------------------------
.. autoclass:: RevocationReason
:no-members:
:noindex:
.. autoattribute:: NotSpecified
:noindex:
:annotation:
.. autoattribute:: Superseded
:noindex:
:annotation:
.. autoattribute:: Compromised
:noindex:
:annotation:
.. autoattribute:: Retired
:noindex:
:annotation:
.. autoattribute:: UserID
:noindex:
:annotation:

View File

@@ -15,7 +15,7 @@ Text and messages can be signed using the .sign method::
# sign some text
sig = sec.sign("I have just signed this text!")
# sign a message
# sign a message - the bitwise OR operator '|' is used to add a signature to a PGPMessage.
message |= sec.sign(message)
# timestamp signatures can also be generated, like so. Note that GnuPG seems to have no idea what to do with this
@@ -35,10 +35,12 @@ Keys and User IDs can be signed using the .certify method::
# Sign the primary User ID - this creates the usual certification signature that is best supported by other popular OpenPGP
# implementations.
# As above, the bitwise OR operator '|' is used to add a signature to a PGPUID.
someones_pubkey.userids[0] |= mykey.certify(someones_pubkey.userids[0], level=SignatureType.Persona_Cert)
# If you want to sign all of their User IDs, that can be done easily in a loop. This is equivalent to GnuPG's
# default behavior when signing someone else's public key.
# As above, the bitwise OR operator '|' is used to add a signature to a PGPKey.
for uid in someones_pubkey.userids:
uid |= mykey.certify(uid)

View File

@@ -22,7 +22,6 @@ Keys can be loaded individually into PGPKey objects::
# or from a text or binary string/bytes/bytearray that has already been read in:
key, _ = pgpy.PGPKey.from_blob(keyblob)
Loading Keys Into a Keyring
^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@@ -24,6 +24,7 @@ Mac OS X
If you are on Mac OS, you may experience more limited functionality without installing a more capable version of OpenSSL.
You may refer to Cryptography's documentation on `Using your own OpenSSL on OS X <https://cryptography.io/en/latest/installation/#using-your-own-openssl-on-os-x>`_ for information on how to do so.
Installation

View File

@@ -131,10 +131,13 @@ class SymmetricKeyAlgorithm(IntEnum):
class PubKeyAlgorithm(IntEnum):
Invalid = 0x00
#: Signifies that a key is an RSA key.
RSAEncryptOrSign = 0x01
RSAEncrypt = 0x02 # deprecated
RSASign = 0x03 # deprecated
#: Signifies that a key is an ElGamal key.
ElGamal = 0x10
#: Signifies that a key is a DSA key.
DSA = 0x11
ECDH = 0x12
ECDSA = 0x13
@@ -245,10 +248,15 @@ class HashAlgorithm(IntEnum):
class RevocationReason(IntEnum):
#: No reason was specified. This is the default reason.
NotSpecified = 0x00
#: The key was superseded by a new key. Only meaningful when revoking a key.
Superseded = 0x01
#: Key material has been compromised. Only meaningful when revoking a key.
Compromised = 0x02
#: Key is retired and no longer used. Only meaningful when revoking a key.
Retired = 0x03
#: User ID information is no longer valid. Only meaningful when revoking a certification of a user id.
UserID = 0x20
@@ -305,12 +313,20 @@ class TrustLevel(IntEnum):
class KeyFlags(FlagEnum):
#: Signifies that a key may be used to certify keys and user ids. Primary keys always have this, even if it is not specified.
Certify = 0x01
#: Signifies that a key may be used to sign messages and documents.
Sign = 0x02
#: Signifies that a key may be used to encrypt messages.
EncryptCommunications = 0x04
#: Signifies that a key may be used to encrypt storage. Currently equivalent to :py:obj:~pgpy.constants.EncryptCommunications`.
EncryptStorage = 0x08
#: 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.
Split = 0x10
#: Signifies that a key may be used for authentication.
Authentication = 0x20
#: Signifies that the private component of a key may be in the possession of more than one person.
MultiPerson = 0x80

View File

@@ -28,6 +28,9 @@ def classproperty(fget):
def sdmethod(meth):
"""
This is a hack to monkey patch sdproperty to work as expected with instance methods.
"""
sd = singledispatch(meth)
def wrapper(obj, *args, **kwargs):

View File

@@ -333,7 +333,7 @@ class PGPSignature(PGPObject, Armorable):
document is canonicalized by converting line endings to <CR><LF>,
and the resulting data is hashed.
"""
_data += re.subn(br'\r{0,1}\n', b'\r\n', subject)[0]
_data += re.subn(br'\r?\n', b'\r\n', subject)[0]
if self.type in [SignatureType.Generic_Cert, SignatureType.Persona_Cert, SignatureType.Casual_Cert,
SignatureType.Positive_Cert, SignatureType.CertRevocation, SignatureType.Subkey_Binding,
@@ -1904,7 +1904,7 @@ class PGPKey(PGPObject, Armorable):
# keys will hold other keys parsed here
keys = collections.OrderedDict()
# orphaned will hold all non-opaque orphaned packets
orphaned = collections.OrderedDict()
orphaned = []
# last holds the last non-signature thing processed
getpkt = lambda d: Packet(d) if len(d) > 0 else None
@@ -1958,13 +1958,14 @@ class PGPKey(PGPObject, Armorable):
# this will only be reached called if the inner loop hit a break
warnings.warn("Warning: Orphaned packet detected! {:s}".format(repr(pkt)), stacklevel=2) # pragma: no cover
orphaned[(pkt.header.tag, len([k for k, v in orphaned.keys() if k == pkt.header.tag]))] = pkt # pragma: no cover
orphaned.append(pkt) # pragma: no cover
for pkt in group: # pragma: no cover
orphaned[(pkt.header.tag, len([k for k, v in orphaned.keys() if k == pkt.header.tag]))] = pkt
orphaned.append(pkt)
# remove the reference to self from keys
[ keys.pop((getattr(self, 'fingerprint.keyid', '~'), None), t) for t in (True, False) ]
return {'keys': keys, 'orphaned': orphaned}
# return {'keys': keys, 'orphaned': orphaned}
return keys
class PGPKeyring(collections.Container, collections.Iterable, collections.Sized):
@@ -2096,7 +2097,7 @@ class PGPKeyring(collections.Container, collections.Iterable, collections.Sized)
else:
_key, keys = PGPKey.from_blob(key)
for ik in _preiter(_key, keys['keys'].values()):
for ik in _preiter(_key, keys.values()):
self._add_key(ik)
loaded |= {ik.fingerprint} | {isk.fingerprint for isk in ik.subkeys.values()}

View File

@@ -19,16 +19,17 @@ gpg_ver = LooseVersion()
os.chdir(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir))
if os.getcwd() not in sys.path:
sys.path.insert(0, os.getcwd())
sys.path.insert(0, os.getcwd())
else:
sys.path.insert(0, sys.path.pop(sys.path.index(os.getcwd())))
sys.path.insert(0, sys.path.pop(sys.path.index(os.getcwd())))
if os.path.join(os.getcwd(), 'tests') not in sys.path:
sys.path.insert(1, os.path.join(os.getcwd(), 'tests'))
sys.path.insert(1, os.path.join(os.getcwd(), 'tests'))
# now import stuff from fixtures so it can be imported by test modules
# from fixtures import TestFiles, gpg_getfingerprint, pgpdump, gpg_verify, gpg_fingerprint
class CWD_As(object):
def __init__(self, newwd):
if not os.path.exists(newwd):
@@ -90,7 +91,7 @@ def write_clean():
def gpg_import():
@contextlib.contextmanager
def _gpg_import(*keypaths):
gpg_args = _gpg_args + ['--import',] + list(keypaths)
gpg_args = _gpg_args + ['--import', ] + list(keypaths)
gpg_kwargs = _gpg_kwargs.copy()
gpgdec = subprocess.Popen(gpg_args, **gpg_kwargs)