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)
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
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
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)
def test_is_armor(self, armored): with open(armored) as af: ac = af.read() assert Armorable.is_armor(ac)
def test_armorable_empty_str(): with pytest.raises(ValueError, message='Expected: ASCII-armored PGP data'): Armorable.ascii_unarmor('')