How to use the pgpy.PGPKey.from_file function in PGPy

To help you get started, we’ve selected a few PGPy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SecurityInnovation / PGPy / tests / test_10_exceptions.py View on Github external
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)
github SecurityInnovation / PGPy / tests / test_10_exceptions.py View on Github external
def rsa_enc():
    return PGPKey.from_file('tests/testdata/keys/rsa.1.enc.asc')[0]
github SecurityInnovation / PGPy / tests / test_99_regressions.py View on Github external
# with GnuPG
        with gpg.Context(armor=True, offline=True) as c:
            c.set_engine_info(gpg.constants.PROTOCOL_OpenPGP, home_dir=gnupghome)

            # import the key
            key_data = gpg.Data(string=pub)
            gpg.core.gpgme.gpgme_op_import(c.wrapped, key_data)

            _, vres = c.verify(gpg.Data(string=sigsubject.decode('latin-1')), gpg.Data(string=str(sig)))
            assert vres



# load mixed keys separately so they do not overwrite "single algo" keys in the _seckeys mapping
_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')) if 'keys/mixed' not in f)}
_mixed1 = PGPKey.from_file('tests/testdata/keys/mixed.1.sec.asc')[0]
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
    _seckeys['EdDSA']._key,                              # EdDSA private key packet
    _seckeys['EdDSA'].subkeys['AFC377493D8E897D']._key,  # Curve25519 private key packet
    _mixed1._key,                                        # RSA private key packet
    _mixed1.subkeys['B345506C90A428C5']._key,            # ECDH Curve25519 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):
github SecurityInnovation / PGPy / tests / test_04_PGP_objects.py View on Github external
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__()
github SecurityInnovation / PGPy / tests / test_05_actions.py View on Github external
def targette_pub():
    return PGPKey.from_file('tests/testdata/keys/targette.pub.rsa.asc')[0]
github SecurityInnovation / PGPy / tests / test_99_regressions.py View on Github external
if gpg:
        # with GnuPG
        with gpg.Context(armor=True, offline=True) as c:
            c.set_engine_info(gpg.constants.PROTOCOL_OpenPGP, home_dir=gnupghome)

            # import the key
            key_data = gpg.Data(string=pub)
            gpg.core.gpgme.gpgme_op_import(c.wrapped, key_data)

            _, vres = c.verify(gpg.Data(string=sigsubject.decode('latin-1')), gpg.Data(string=str(sig)))
            assert vres



# load mixed keys separately so they do not overwrite "single algo" keys in the _seckeys mapping
_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')) if 'keys/mixed' not in f)}
_mixed1 = PGPKey.from_file('tests/testdata/keys/mixed.1.sec.asc')[0]
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
    _seckeys['EdDSA']._key,                              # EdDSA private key packet
    _seckeys['EdDSA'].subkeys['AFC377493D8E897D']._key,  # Curve25519 private key packet
    _mixed1._key,                                        # RSA private key packet
    _mixed1.subkeys['B345506C90A428C5']._key,            # ECDH Curve25519 private key packet
]


@pytest.mark.regression(issue=172)
@pytest.mark.parametrize('keypkt', seckm, ids=[sk.pkalg.name for sk in seckm])
github SecurityInnovation / PGPy / tests / test_10_exceptions.py View on Github external
def targette_pub():
    return PGPKey.from_file('tests/testdata/keys/targette.pub.rsa.asc')[0]
github SecurityInnovation / PGPy / tests / test_05_actions.py View on Github external
def test_gpg_ed25519_verify(self, abe):
        # test verification of Ed25519 signature generated by GnuPG
        pubkey, _ = PGPKey.from_file('tests/testdata/keys/ecc.2.pub.asc')
        sig = PGPSignature.from_file('tests/testdata/signatures/ecc.2.sig.asc')
        assert pubkey.verify("This is a test signature message", sig)
github SecurityInnovation / PGPy / tests / test_04_PGP_objects.py View on Github external
def test_load_from_file(self, kf):
        key, _ = PGPKey.from_file(kf)

        assert key.fingerprint == _fingerprints[os.path.basename(kf)]