本文整理汇总了Python中pgpy.PGPKey.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python PGPKey.from_file方法的具体用法?Python PGPKey.from_file怎么用?Python PGPKey.from_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgpy.PGPKey
的用法示例。
在下文中一共展示了PGPKey.from_file方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_save
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def test_save(self, kf):
# load the key and export it back to binary
key, _ = PGPKey.from_file(kf)
pgpyblob = key.__bytes__()
# try loading the exported key
reloaded, _ = PGPKey.from_file(kf)
assert pgpyblob == reloaded.__bytes__()
示例2: test_sign_encrypted_message
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def test_sign_encrypted_message(self, sf, cipher):
# test decrypting a message
sec, _ = PGPKey.from_file(sf)
if (sec.fingerprint, cipher) not in self.msgs:
pytest.skip('Message not present; see test_encrypt_message skip or xfail reason')
emsg = self.msgs[(sec.fingerprint, cipher)]
emsg |= sec.sign(emsg)
assert emsg.is_signed
assert emsg.is_encrypted
assert isinstance(next(iter(emsg)), PGPSignature)
示例3: test_decrypt_message
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def test_decrypt_message(self, sf, cipher):
# test decrypting a message
sec, _ = PGPKey.from_file(sf)
if (sec.fingerprint, cipher) not in self.msgs:
pytest.skip('Message not present; see test_encrypt_message skip or xfail reason')
emsg = self.msgs[(sec.fingerprint, cipher)]
dmsg = sec.decrypt(emsg)
assert dmsg.message == "This message will have been encrypted"
# now check with GnuPG, if possible
if gpg_ver < '2.1' and sec.key_algorithm in {PubKeyAlgorithm.ECDSA, PubKeyAlgorithm.ECDH}:
# GnuPG prior to 2.1.x does not support EC* keys, so skip this step
return
assert self.gpg_decrypt(emsg, sec).decode('utf-8') == dmsg.message
示例4: targette_sec
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def targette_sec():
return PGPKey.from_file('tests/testdata/keys/targette.sec.rsa.asc')[0]
示例5: targette_pub
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def targette_pub():
return PGPKey.from_file('tests/testdata/keys/targette.pub.rsa.asc')[0]
示例6: rsa_pub
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def rsa_pub():
return PGPKey.from_file('tests/testdata/keys/rsa.1.pub.asc')[0]
示例7: test_load_from_file
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def test_load_from_file(self, kf):
key, _ = PGPKey.from_file(kf)
assert key.fingerprint == _fingerprints[os.path.basename(kf)]
示例8: rsa_enc
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def rsa_enc():
return PGPKey.from_file('tests/testdata/keys/rsa.1.enc.asc')[0]
示例9: test_verify_wrongkey
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def test_verify_wrongkey(self, rsa_pub):
wrongkey, _ = PGPKey.from_file('tests/testdata/signatures/aptapproval-test.key.asc')
sig = PGPSignature.from_file('tests/testdata/signatures/debian-sid.sig.asc')
with pytest.raises(PGPError):
wrongkey.verify(_read('tests/testdata/signatures/debian-sid.subj'), sig)
示例10: key
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def key(fn):
key, _ = PGPKey.from_file(fn)
return key
示例11: rtime
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
s2k.count = pgpy.constants.HashAlgorithm.SHA256.tuned_count
start = rtime()
sk = s2k.derive_key('sooper_sekret_passphrase')
elapsed = rtime() - start
# check that we're actually close to our target
assert len(sk) == 32
try:
assert 0.1 <= round(elapsed, 1) <= 0.2
except AssertionError:
warnings.warn("tuned_count: {}; elapsed time: {:.5f}".format(pgpy.constants.HashAlgorithm.SHA256.tuned_count, elapsed))
_seckeys = {sk.key_algorithm.name: sk for sk in (PGPKey.from_file(f)[0] for f in sorted(glob.glob('tests/testdata/keys/*.sec.asc')))}
seckm = [
_seckeys['DSA']._key, # DSA private key packet
_seckeys['DSA'].subkeys['1FD6D5D4DA0170C4']._key, # ElGamal private key packet
_seckeys['RSAEncryptOrSign']._key, # RSA private key packet
_seckeys['ECDSA']._key, # ECDSA private key packet
_seckeys['ECDSA'].subkeys['A81B93FD16BD9806']._key, # ECDH private key packet
]
@pytest.mark.regression(issue=172)
@pytest.mark.parametrize('keypkt', seckm, ids=[sk.pkalg.name for sk in seckm])
def test_check_checksum(keypkt):
# this test is dirty and simple
# take the key packet provided, and store the key material checksum
# recompute the checksum, and ensure they match
示例12: test_load_from_file
# 需要导入模块: from pgpy import PGPKey [as 别名]
# 或者: from pgpy.PGPKey import from_file [as 别名]
def test_load_from_file(self, gpg_keyid_file):
key, _ = PGPKey.from_file(self.kf)
assert key.fingerprint.keyid in gpg_keyid_file(self.kf.replace('tests/testdata/', ''))