Add NONCE_RANDOM_PREFIX_SIZE to constants

Add test for NONCE_RANDOM_PREFIX_SIZE constant
pull/52/head
tuxxy 2017-09-14 14:29:05 -07:00
parent d9f1bcb82b
commit 0004532871
3 changed files with 7 additions and 1 deletions

View File

@ -1 +1,5 @@
# Number of random bytes to prefix before the counter
NONCE_RANDOM_PREFIX_SIZE = 20
# Size of the counter in bytes (4 = int)
NONCE_COUNTER_BYTE_SIZE = 4

View File

@ -1,6 +1,7 @@
import msgpack
import pathlib
from nacl.utils import random
from nkms.storage.constants import NONCE_RANDOM_PREFIX_SIZE
class Header(object):
@ -53,7 +54,7 @@ class Header(object):
:rtype: Dict
"""
if not nonce:
nonce = random(20)
nonce = random(NONCE_RANDOM_PREFIX_SIZE)
return {
'version': version,

View File

@ -5,3 +5,4 @@ from nkms.storage import constants
class TestConstants(unittest.TestCase):
def test_constants(self):
self.assertEqual(4, constants.NONCE_COUNTER_BYTE_SIZE)
self.assertEqual(20, constants.NONCE_RANDOM_PREFIX_SIZE)