本文整理汇总了Python中pgpy.PGPMessage.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python PGPMessage.from_file方法的具体用法?Python PGPMessage.from_file怎么用?Python PGPMessage.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgpy.PGPMessage
的用法示例。
在下文中一共展示了PGPMessage.from_file方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_load_from_file
# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import from_file [as 别名]
def test_load_from_file(self, msgfile):
# TODO: figure out a good way to verify that all went well here, because
# PGPy reorders signatures sometimes, and also unwraps compressed messages
# so comparing str(msg) to the contents of msgfile doesn't actually work
msg = PGPMessage.from_file(msgfile)
with open(msgfile, 'r') as mf:
mt = mf.read()
assert len(str(msg)) == len(mt)
示例2: sorted
# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import from_file [as 别名]
from pgpy.constants import CompressionAlgorithm
from pgpy.constants import EllipticCurveOID
from pgpy.constants import Features
from pgpy.constants import HashAlgorithm
from pgpy.constants import KeyFlags
from pgpy.constants import KeyServerPreferences
from pgpy.constants import PubKeyAlgorithm
from pgpy.constants import RevocationReason
from pgpy.constants import SignatureType
from pgpy.constants import SymmetricKeyAlgorithm
from pgpy.packet import Packet
from pgpy.packet.packets import PrivKeyV4
from pgpy.packet.packets import PrivSubKeyV4
enc_msgs = [ PGPMessage.from_file(f) for f in sorted(glob.glob('tests/testdata/messages/message*.pass*.asc')) ]
class TestPGPMessage(object):
@staticmethod
def gpg_message(msg):
with gpg.Context(offline=True) as c:
c.set_engine_info(gpg.constants.PROTOCOL_OpenPGP, home_dir=gnupghome)
msg, _ = c.verify(gpg.Data(string=str(msg)))
return msg
@staticmethod
def gpg_decrypt(msg, passphrase):
try:
with gpg.Context(armor=True, offline=True, pinentry_mode=gpg.constants.PINENTRY_MODE_LOOPBACK) as c:
c.set_engine_info(gpg.constants.PROTOCOL_OpenPGP, file_name='/usr/bin/gpg', home_dir=gnupghome)
示例3: test_decrypt_unencrypted
# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import from_file [as 别名]
def test_decrypt_unencrypted(self):
msg = PGPMessage.from_file('tests/testdata/messages/message.signed.asc')
with pytest.raises(PGPError):
msg.decrypt("Password")
示例4: test_decrypt_wrongpass
# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import from_file [as 别名]
def test_decrypt_wrongpass(self):
msg = PGPMessage.from_file(next(f for f in glob.glob('tests/testdata/messages/message*.pass*.asc')))
with pytest.raises(PGPDecryptionError):
msg.decrypt("TheWrongPassword")
示例5: test_decrypt_unsupported_algorithm
# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import from_file [as 别名]
def test_decrypt_unsupported_algorithm(self):
msg = PGPMessage.from_file('tests/testdata/message.enc.twofish.asc')
with pytest.raises(PGPDecryptionError):
msg.decrypt("QwertyUiop")
示例6: test_decrypt_wrongkey
# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import from_file [as 别名]
def test_decrypt_wrongkey(self, targette_sec):
msg = PGPMessage.from_file('tests/testdata/messages/message.rsa.cast5.asc')
with pytest.raises(PGPError):
targette_sec.decrypt(msg)
示例7: isinstance
# 需要导入模块: from pgpy import PGPMessage [as 别名]
# 或者: from pgpy.PGPMessage import from_file [as 别名]
# integers are kind of a special case.
# ints that do not exceed sys.maxsize are singletons, and in either case are immutable
# this shouldn't apply to MPIs, though, which are subclasses of int
if isinstance(obj, int) and not isinstance(obj, pgpy.packet.types.MPI):
return False
return True
def ksort(key):
# return a tuple of key, key.count('.') so we get a descending alphabetical, ascending depth ordering
return key, key.count('.')
objs = [sig(), uid(),] + [PGPMessage.from_file(m) for m in _msgs] + [key(f) for f in _keys]
cids = ['sig', 'uid',] + [os.path.basename(m) for m in _msgs] + [os.path.basename(f) for f in _keys]
@pytest.mark.parametrize('obj', objs, ids=cids)
def test_copy_obj(request, obj):
obj2 = copy.copy(obj)
objflat = {name: val for name, val in walk_obj(obj, '{}.'.format(request.node.callspec.id))}
obj2flat = {name: val for name, val in walk_obj(obj2, '{}.'.format(request.node.callspec.id))}
for k in sorted(objflat, key=ksort):
print("checking attribute: {} ".format(k), end="")
if isinstance(objflat[k], pgpy.types.SorteDeque):
print("[SorteDeque] ", end="")
assert len(objflat[k]) == len(obj2flat[k])