Esempio n. 1
0
 def test_codec_identity(self):
   # Not zero-destructive
   self.assertEqual(codec.hex_decode(codec.hex_encode(ZERO_BYTES)), ZERO_BYTES)
   self.assertEqual(codec.hex_decode(codec.hex_encode(RANDOM_BYTES_1024)),
                    RANDOM_BYTES_1024)
   self.assertEqual(codec.hex_decode(codec.hex_encode(RANDOM_BYTES_2048)),
                    RANDOM_BYTES_2048)
   self.assertEqual(
     codec.hex_decode(codec.hex_encode(RANDOM_BYTES_4093)),
     RANDOM_BYTES_4093)
Esempio n. 2
0
 def test_codec_identity(self):
   # Not zero-destructive
   self.assertEqual(hex_decode(hex_encode(zero_bytes)), zero_bytes)
   self.assertEqual(hex_decode(hex_encode(random_bytes_1024)),
                    random_bytes_1024)
   self.assertEqual(hex_decode(hex_encode(random_bytes_2048)),
                    random_bytes_2048)
   self.assertEqual(
     hex_decode(hex_encode(random_bytes_len_4093)),
     random_bytes_len_4093)
Esempio n. 3
0
from __future__ import absolute_import

import unittest2
from mom.builtins import b
from mom.codec import hex_decode, base62_decode, base62_encode
from mom.codec._alt_base import b62decode_naive, b62encode_naive
from mom.codec.base62 import b62encode, b62decode, ASCII62_BYTES, ALT62_BYTES
from mom.security.random import generate_random_bytes
from mom.tests.constants import unicode_string

random_bytes_len_512 = generate_random_bytes(512)

zero_bytes = b('\x00\x00\x00\x00')
one_zero_byte = b('\x00')
raw_data = hex_decode(b('005cc87f4a3fdfe3a2346b6953267ca867282630d3f9b78e64'))
encoded = b('01041W9weGIezvwKmSO0laL8BGx4qp64Q8')
encoded_with_whitespace = b('''
01041W9weGIezvwKmS
O0laL8BGx4qp64Q8
''')

padding_raw = b('''\
\x00\x00\xa4\x97\xf2\x10\xfc\x9c]\x02\xfc}\xc7\xbd!\x1c\xb0\xc7M\xa0\xae\x16\
''')

class Test_base62_codec(unittest2.TestCase):
  def test_ensure_charset_length(self):
    self.assertEqual(len(ASCII62_BYTES), 62)
    self.assertEqual(len(ALT62_BYTES), 62)
Esempio n. 4
0
from mom.codec import _alt_base
from mom.codec import base62
from mom.security import random
from mom.tests import constants


__author__ = "[email protected] (Yesudeep Mangalapilly)"


b = builtins.b

RANDOM_BYTES_LEN_512 = random.generate_random_bytes(512)

ZERO_BYTES = b("\x00\x00\x00\x00")
ONE_ZERO_BYTE = b("\x00")
RAW_DATA = codec.hex_decode(b("005cc87f4a3fdfe3a2346b6953267ca867282630d3f9b78e64"))
ENCODED = b("01041W9weGIezvwKmSO0laL8BGx4qp64Q8")
ENCODED_WITH_WHITESPACE = b("""
01041W9weGIezvwKmS
O0laL8BGx4qp64Q8
""")

PADDING_RAW = b("""\
\x00\x00\xa4\x97\xf2\x10\xfc\x9c]\x02\xfc}\xc7\xbd!\x1c\xb0\xc7M\xa0\xae\x16\
""")

class Test_base62_codec(unittest2.TestCase):
  def test_ensure_charset_length(self):
    self.assertEqual(len(base62.ASCII62_BYTES), 62)
    self.assertEqual(len(base62.ALT62_BYTES), 62)
Esempio n. 5
0
from mom import builtins
from mom import codec
from mom.codec import _alt_base
from mom.codec import base62
from mom.security import random
from mom.tests import constants

__author__ = "[email protected] (Yesudeep Mangalapilly)"

b = builtins.b

RANDOM_BYTES_LEN_512 = random.generate_random_bytes(512)

ZERO_BYTES = b("\x00\x00\x00\x00")
ONE_ZERO_BYTE = b("\x00")
RAW_DATA = codec.hex_decode(
    b("005cc87f4a3fdfe3a2346b6953267ca867282630d3f9b78e64"))
ENCODED = b("01041W9weGIezvwKmSO0laL8BGx4qp64Q8")
ENCODED_WITH_WHITESPACE = b("""
01041W9weGIezvwKmS
O0laL8BGx4qp64Q8
""")

PADDING_RAW = b("""\
\x00\x00\xa4\x97\xf2\x10\xfc\x9c]\x02\xfc}\xc7\xbd!\x1c\xb0\xc7M\xa0\xae\x16\
""")


class Test_base62_codec(unittest2.TestCase):
    def test_ensure_charset_length(self):
        self.assertEqual(len(base62.ASCII62_BYTES), 62)
        self.assertEqual(len(base62.ALT62_BYTES), 62)