File: test_raw_secret_easy.py

package info (click to toggle)
python-libnacl 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 488 kB
  • sloc: python: 2,634; makefile: 149; sh: 3
file content (33 lines) | stat: -rw-r--r-- 959 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Import libnacl libs
import libnacl
import libnacl.utils

# Import python libs
import unittest


class TestSecret(unittest.TestCase):
    """
    Test secret functions
    """
    def test_secretbox_easy(self):
        msg = b'Are you suggesting coconuts migrate?'

        nonce = libnacl.utils.rand_nonce()
        key = libnacl.utils.salsa_key()

        c = libnacl.crypto_secretbox_easy(msg, nonce, key)
        m = libnacl.crypto_secretbox_open_easy(c, nonce, key)
        self.assertEqual(msg, m)

        with self.assertRaises(ValueError):
            libnacl.crypto_secretbox_easy(msg, b'too_short', key)

        with self.assertRaises(ValueError):
            libnacl.crypto_secretbox_easy(msg, nonce, b'too_short')

        with self.assertRaises(ValueError):
            libnacl.crypto_secretbox_open_easy(c, b'too_short', key)

        with self.assertRaises(ValueError):
            libnacl.crypto_secretbox_open_easy(c, nonce, b'too_short')