def faux_payload ():
return "abcd" * 42
+
class CryptoLayerTest (unittest.TestCase):
+ pass
+
+
+class AESGCMTest (CryptoLayerTest):
def test_crypto_aes_gcm_enc_simple (self):
NaCl = os.urandom (CRYPTO_NACL_SIZE)
ok, _, _ = dec.done ()
+class HeaderTest (CryptoLayerTest):
+
def test_crypto_fmt_hdr_make (self):
meta = faux_hdr()
ok, hdr = crypto.hdr_make (meta)
assert len (hdr) == crypto.I2N_HDR_SIZE
+ def test_crypto_fmt_hdr_make_useless (self):
+ ok, ret = crypto.hdr_make ({ 42: "x" })
+ assert ok is False
+ assert ret.startswith ("error writing header:")
+
+
def test_crypto_fmt_hdr_read (self):
meta = faux_hdr()
ok, hdr = crypto.hdr_make (meta)
% (meta [k], mmeta [k])
+ def test_crypto_fmt_hdr_read_trailing_garbage (self):
+ meta = faux_hdr()
+ ok, hdr = crypto.hdr_make (meta)
+ hdr += b"-junk"
+ ok, msg = crypto.hdr_read (hdr)
+ assert ok is False
+ assert msg.startswith ("error reading header from")
+
+
+ def test_crypto_fmt_hdr_read_leading_garbage (self):
+ meta = faux_hdr()
+ ok, hdr = crypto.hdr_make (meta)
+ hdr = b"junk-" + hdr
+ ok, msg = crypto.hdr_read (hdr)
+ assert ok is False
+ assert msg.startswith ("error reading header from")
+
+
+ def test_crypto_fmt_hdr_inner_garbage (self):
+ meta = faux_hdr()
+ ok, hdr = crypto.hdr_make (meta)
+ hdr = hdr[:len(hdr)//2] + b"junk-" + hdr[len(hdr)//2:]
+ ok, msg = crypto.hdr_read (hdr)
+ assert ok is False
+ assert msg.startswith ("error reading header from")
+