示例#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)
示例#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)
示例#3
0
文件: crypto.py 项目: oliverFU/pyac
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
示例#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
示例#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
示例#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)
示例#7
0
    def test_is_armor(self, armored):
        with open(armored) as af:
            ac = af.read()

        assert Armorable.is_armor(ac)
示例#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)
示例#9
0
    def test_is_armor(self, armored):
        with open(armored) as af:
            ac = af.read()

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