Esempio n. 1
0
 def test_malformed_base64(self):
     # 'asdf' base64-encoded becomes 'YXNkZg=='
     # remove one of the pad characters and we should get a PGPError
     data = '-----BEGIN PGP SOMETHING-----\n' \
            '\n' \
            'YXNkZg=\n' \
            '=ZEO6\n' \
            '-----END PGP SOMETHING-----\n'
     with pytest.raises(PGPError):
         Armorable.ascii_unarmor(data)
Esempio n. 2
0
 def test_malformed_base64(self):
     # 'asdf' base64-encoded becomes 'YXNkZg=='
     # remove one of the pad characters and we should get a PGPError
     data = '-----BEGIN PGP SOMETHING-----\n' \
            '\n' \
            'YXNkZg=\n' \
            '=ZEO6\n' \
            '-----END PGP SOMETHING-----\n'
     with pytest.raises(PGPError):
         Armorable.ascii_unarmor(data)
Esempio n. 3
0
def list_packets_pgpy(keydata):
    if isinstance(keydata, bytes):
        data = bytearray(keydata)
    elif isinstance(keydata, str):
        data = Armorable.ascii_unarmor(keydata)['body']
    packets = []
    while data:
        packets.append(Packet(data))
    return packets
Esempio n. 4
0
def test_oneline_cleartext(sf, cleartext):
    with open(sf) as of:
        oc = of.read()

    dearmor = Armorable.ascii_unarmor(oc)
    # It is a signature
    assert dearmor['magic'] == 'SIGNATURE'
    # No newline at the end
    assert dearmor['cleartext'] == cleartext
Esempio n. 5
0
def test_oneline_cleartext(sf, cleartext):
    with open(sf) as of:
        oc = of.read()

    dearmor = Armorable.ascii_unarmor(oc)
    # It is a signature
    assert dearmor['magic'] == 'SIGNATURE'
    # No newline at the end
    assert dearmor['cleartext'] == cleartext
Esempio n. 6
0
    def test_not_armor(self, text):
        mode = 'r' if text in txt else 'rb'
        with open(text, mode) as tf:
            tc = tf.read()

        assert not Armorable.is_armor(tc)
Esempio n. 7
0
    def test_is_armor(self, armored):
        with open(armored) as af:
            ac = af.read()

        assert Armorable.is_armor(ac)
Esempio n. 8
0
    def test_not_armor(self, text):
        mode = 'r' if text in txt else 'rb'
        with open(text, mode) as tf:
            tc = tf.read()

        assert not Armorable.is_armor(tc)
Esempio n. 9
0
    def test_is_armor(self, armored):
        with open(armored) as af:
            ac = af.read()

        assert Armorable.is_armor(ac)
Esempio n. 10
0
def test_armorable_empty_str():
    with pytest.raises(ValueError, message='Expected: ASCII-armored PGP data'):
        Armorable.ascii_unarmor('')
Esempio n. 11
0
def test_armorable_empty_str():
    with pytest.raises(ValueError, message='Expected: ASCII-armored PGP data'):
        Armorable.ascii_unarmor('')