def test_open_with_invalid_nonce(self):
        key = bytearray(b'\x01' * 16)
        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02' * 11)

        ciphertext = bytearray(b'\'\x81h\x17\xe6Z)\\\xf2\x8emF\xcb\x91\x0eu'
                               b'z1:\xf6}\xa7\\@\xba\x11\xd8r\xdf#K\xd4')

        with self.assertRaises(ValueError):
            aesGCM.open(nonce, ciphertext, bytearray(0))
    def test_open_with_invalid_nonce(self):
        key = bytearray(b'\x01'*16)
        aesGCM = AESGCM(key, "python", rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02'*11)

        ciphertext = bytearray(
            b'\'\x81h\x17\xe6Z)\\\xf2\x8emF\xcb\x91\x0eu'
            b'z1:\xf6}\xa7\\@\xba\x11\xd8r\xdf#K\xd4')

        with self.assertRaises(ValueError):
            aesGCM.open(nonce, ciphertext, bytearray(0))
    def test_open_with_invalid_ciphertext(self):
        key = bytearray(b'\x01' * 16)
        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02' * 12)

        ciphertext = bytearray(b'\xff' * 15)

        self.assertIsNone(aesGCM.open(nonce, ciphertext, bytearray(0)))
    def test_open_with_invalid_ciphertext(self):
        key = bytearray(b'\x01'*16)
        aesGCM = AESGCM(key, "python", rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02'*12)

        ciphertext = bytearray(
            b'\xff'*15)

        self.assertIsNone(aesGCM.open(nonce, ciphertext, bytearray(0)))
    def test_open_with_incorrect_nonce(self):
        key = bytearray(b'\x01' * 16)
        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02' * 11 + b'\x01')

        ciphertext = bytearray(b'\'\x81h\x17\xe6Z)\\\xf2\x8emF\xcb\x91\x0eu'
                               b'z1:\xf6}\xa7\\@\xba\x11\xd8r\xdf#K\xd4')

        plaintext = aesGCM.open(nonce, ciphertext, bytearray(0))

        self.assertIsNone(plaintext)
    def test_open(self):
        key = bytearray(b'\x01' * 16)
        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02' * 12)

        ciphertext = bytearray(b'\'\x81h\x17\xe6Z)\\\xf2\x8emF\xcb\x91\x0eu'
                               b'z1:\xf6}\xa7\\@\xba\x11\xd8r\xdf#K\xd4')

        plaintext = aesGCM.open(nonce, ciphertext, bytearray(0))

        self.assertEqual(plaintext, bytearray(b'text to encrypt.'))
    def test_open_with_incorrect_nonce(self):
        key = bytearray(b'\x01'*16)
        aesGCM = AESGCM(key, "python", rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02'*11 + b'\x01')

        ciphertext = bytearray(
            b'\'\x81h\x17\xe6Z)\\\xf2\x8emF\xcb\x91\x0eu'
            b'z1:\xf6}\xa7\\@\xba\x11\xd8r\xdf#K\xd4')

        plaintext = aesGCM.open(nonce, ciphertext, bytearray(0))

        self.assertIsNone(plaintext)
    def test_open(self):
        key = bytearray(b'\x01'*16)
        aesGCM = AESGCM(key, "python", rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02'*12)

        ciphertext = bytearray(
            b'\'\x81h\x17\xe6Z)\\\xf2\x8emF\xcb\x91\x0eu'
            b'z1:\xf6}\xa7\\@\xba\x11\xd8r\xdf#K\xd4')

        plaintext = aesGCM.open(nonce, ciphertext, bytearray(0))

        self.assertEqual(plaintext, bytearray(b'text to encrypt.'))