Esempio n. 1
0
from mom.security import random

from mom import codec
from mom.tests import test_mom_codec_base85


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


b = builtins.b

BASE85_RAW = test_mom_codec_base85.RAW
BASE85_ENCODED = test_mom_codec_base85.ENCODED

# Generates a 1024-bit strength random byte string.
RANDOM_BYTES_1024 = random.generate_random_bytes(1024 >> 3)
# Generates a 2048-bit strength random byte string.
RANDOM_BYTES_2048 = random.generate_random_bytes(2048 >> 3)
# Generates a 4093 byte length random byte string.
RANDOM_BYTES_4093 = random.generate_random_bytes(4093)

ZERO_BYTES = b("\x00\x00\x00\x00")
ONE_ZERO_BYTE = b("\x00")

RANDOM_LONG_VALUE = random.generate_random_uint_between(0, 99999999999999999)
ZERO_LONG = 0
NEGATIVE_LONG_VALUE = -1

LONG_VALUE = 71671831749689734735896910666236152091910950933161125188784836897624039426313152092699961904060141667369
EXPECTED_BLOCKSIZE_BYTES = b("""\
\x00\x01\xff\xff\xff\xff\xff\xff\xff\xff\x000 0\x0c\x06\x08*\x86H\x86\
Esempio n. 2
0
from mom import _alt_builtins
from mom import _compat
from mom import builtins
from mom.security import random
from mom.tests import constants


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


b = builtins.b
byte = builtins.byte
hex = builtins.hex
bin = builtins.bin

RANDOM_BYTES = random.generate_random_bytes(100)


class Test_byte(unittest2.TestCase):
  def test_byte(self):
    for i in range(256):
      byt = byte(i)
      self.assertTrue(builtins.is_bytes(byt))
      self.assertEqual(ord(byt), i)

  def test_raises_Error_on_overflow(self):
    self.assertRaises(struct.error, byte, 256)
    self.assertRaises(struct.error, byte, -1)


class Test_bytes_leading_and_trailing(unittest2.TestCase):
Esempio n. 3
0
  is_bytes_or_unicode,\
  bin,\
  hex,\
  integer_byte_length,\
  integer_bit_length,\
  is_sequence,\
  is_odd,\
  is_even,\
  is_negative,\
  is_positive, byte, bytes_leading, bytes_trailing, b,\
  integer_byte_size, integer_bit_count, integer_bit_size

from mom.tests.constants import unicode_string, unicode_string2,\
  utf8_bytes, utf8_bytes2, latin1_bytes

random_bytes = generate_random_bytes(100)

class Test_byte(unittest2.TestCase):
  def test_byte(self):
    for i in range(256):
      byt = byte(i)
      self.assertTrue(is_bytes(byt))
      self.assertEqual(ord(byt), i)

  def test_raises_Error_on_overflow(self):
    self.assertRaises(struct.error, byte, 256)
    self.assertRaises(struct.error, byte, -1)


class Test_bytes_leading_and_trailing(unittest2.TestCase):
  def test_leading(self):
Esempio n. 4
0
from mom import _compat
from mom import builtins
from mom import codec
from mom.codec import base36
from mom.codec import integer
from mom.security import random


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


b = builtins.b
ZERO_BYTE = _compat.ZERO_BYTE


RANDOM_BYTES = random.generate_random_bytes(384)
ZERO_BYTES_4 = ZERO_BYTE * 4
RAW_DATA = b("""\
\x00\x00\xa4\x97\xf2\x10\xfc\x9c]\x02\xfc}\xc7\xbd!\x1c\xb0\xc7M\xa0\xae\x16\
""")


class Test_base36_codec(unittest2.TestCase):
  def test_ensure_charset_length(self):
    self.assertEqual(len(base36.ASCII36_BYTES), 36)

  def test_codec_identity(self):
    self.assertEqual(base36.b36decode(base36.b36encode(RANDOM_BYTES)), RANDOM_BYTES)
    self.assertEqual(codec.base36_decode(codec.base36_encode(RANDOM_BYTES)),
                     RANDOM_BYTES)
Esempio n. 5
0
from mom.codec import\
  base64_encode,\
  base64_decode,\
  hex_decode,\
  hex_encode,\
  decimal_decode,\
  decimal_encode,\
  bin_encode,\
  bin_decode,\
  base85_encode, base85_decode, base58_encode, base58_decode,\
  base64_urlsafe_encode, base64_urlsafe_decode
from mom.tests.test_mom_codec_base85 import raw as base85_raw,\
  encoded as base85_encoded

# Generates a 1024-bit strength random byte string.
random_bytes_1024 = generate_random_bytes(1024 >> 3)
# Generates a 2048-bit strength random byte string.
random_bytes_2048 = generate_random_bytes(2048 >> 3)
# Generates a 4093 byte length random byte string.
random_bytes_len_4093 = generate_random_bytes(4093)

zero_bytes = b('\x00\x00\x00\x00')
one_zero_byte = b('\x00')

random_long_value = generate_random_uint_between(0, 99999999999999999)
zero_long = 0
negative_long_value = -1

long_value = 71671831749689734735896910666236152091910950933161125188784836897624039426313152092699961904060141667369
expected_blocksize_bytes = b('''\
\x00\x01\xff\xff\xff\xff\xff\xff\xff\xff\x000 0\x0c\x06\x08*\x86H\x86\
Esempio n. 6
0
import unittest2

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):
Esempio n. 7
0
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

import unittest2
from mom._compat import ZERO_BYTE
from mom.builtins import b
from mom.codec import base58_decode, base58_encode
from mom.codec._alt_base import b58decode_naive, b58encode_naive
from mom.codec.base58 import b58encode, b58decode, ALT58_BYTES, ASCII58_BYTES
from mom.codec.integer import uint_to_bytes, bytes_to_uint
from mom.security.random import generate_random_bytes
from mom.tests.constants import unicode_string

random_bytes = generate_random_bytes(384)

zero_bytes_4 = ZERO_BYTE * 4
#raw_data = hex_decode(b('005cc87f4a3fdfe3a2346b6953267ca867282630d3f9b78e64'))
raw_data = b('\x00\\\xc8\x7fJ?\xdf\xe3\xa24kiS&|\xa8g(&0\xd3\xf9\xb7\x8ed')
encoded = b('19TbMSWwHvnxAKy12iNm3KdbGfzfaMFViT')
encoded_with_whitespace = b('''
19TbMSWwHvnxAKy12iN
m3KdbGfzfaMFViT
''')

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

class Test_base58_codec(unittest2.TestCase):
Esempio n. 8
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

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):
Esempio n. 9
0
from __future__ import absolute_import

import unittest2

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\
""")