# Path: mom/builtins.py
# def byte(number):
# def bytes_leading(raw_bytes, needle=_compat.ZERO_BYTE):
# def bytes_trailing(raw_bytes, needle=_compat.ZERO_BYTE):
# def bin(number, prefix="0b"):
# def hex(number, prefix="0x"):
# def is_sequence(obj):
# def is_unicode(obj):
# def is_bytes(obj):
# def is_bytes_or_unicode(obj):
# def is_integer(obj):
# def integer_byte_length(number):
# def integer_byte_size(number):
# def integer_bit_length(number):
# def integer_bit_size(number):
# def integer_bit_count(number):
# def is_even(num):
# def is_odd(num):
# def is_positive(num):
# def is_negative(num):
# 
# Path: mom/codec/integer.py
# ZERO_BYTE = _compat.ZERO_BYTE
# EMPTY_BYTE = _compat.EMPTY_BYTE
# def bytes_to_uint(raw_bytes):
# def uint_to_bytes(number, fill_size=0, chunk_size=0, overflow=False):
# 
# Path: mom/security/random.py
# HEXADECIMAL_DIGITS = string.DIGITS + "abcdef"
# DIGITS = string.DIGITS
# LOWERCASE_ALPHA = string.ASCII_LOWERCASE
# UPPERCASE_ALPHA = string.ASCII_UPPERCASE
# LOWERCASE_ALPHANUMERIC = LOWERCASE_ALPHA + string.DIGITS
# UPPERCASE_ALPHANUMERIC = UPPERCASE_ALPHA + string.DIGITS
# ALPHA = string.ASCII_LETTERS
# ALPHANUMERIC = ALPHA + string.DIGITS
# ASCII_PRINTABLE = ALPHA + string.DIGITS + string.PUNCTUATION
# ALL_PRINTABLE = string.PRINTABLE
# PUNCTUATION = string.PUNCTUATION
# def generate_random_bits(n_bits, rand_func=generate_random_bytes):
# def generate_random_uint_atmost(n_bits, rand_func=generate_random_bytes):
# def generate_random_uint_exactly(n_bits, rand_func=generate_random_bytes):
# def generate_random_uint_between(low, high, rand_func=generate_random_bytes):
# def generate_random_hex_string(length=8, rand_func=generate_random_bytes):
# def random_choice(sequence, rand_func=generate_random_bytes):
# def random_shuffle(sequence, rand_func=generate_random_bytes):
# def generate_random_sequence(length, pool, rand_func=generate_random_bytes):
# def generate_random_string(length, pool=ALPHANUMERIC,
#                            rand_func=generate_random_bytes):
# def calculate_entropy(length, pool=ALPHANUMERIC):
# def generate_random_sequence_strong(entropy, pool,
#                                     rand_func=generate_random_bytes):
# def generate_random_password(entropy, pool=ASCII_PRINTABLE,
#                              rand_func=generate_random_bytes):


import unittest2
from mom import builtins
from mom.codec import integer
from mom.security import random
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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




__author__ = "yesudeep@google.com (Yesudeep Mangalapilly)"


class Test_generate_random_bits(unittest2.TestCase):
  def test_range(self):
    for _ in range(999):
      n_bits = 4
      value = integer.bytes_to_uint(random.generate_random_bits(n_bits))
      self.assertTrue(value >= 0 and value < (1 << n_bits))

  def test_uniqueness(self):
    # The likely-hood of recurrence should be tiny if a large enough
    # bit size is chosen.

# Path: mom/builtins.py
# def byte(number):
# def bytes_leading(raw_bytes, needle=_compat.ZERO_BYTE):
# def bytes_trailing(raw_bytes, needle=_compat.ZERO_BYTE):
# def bin(number, prefix="0b"):
# def hex(number, prefix="0x"):
# def is_sequence(obj):
# def is_unicode(obj):
# def is_bytes(obj):
# def is_bytes_or_unicode(obj):
# def is_integer(obj):
# def integer_byte_length(number):
# def integer_byte_size(number):
# def integer_bit_length(number):
# def integer_bit_size(number):
# def integer_bit_count(number):
# def is_even(num):
# def is_odd(num):
# def is_positive(num):
# def is_negative(num):
# 
# Path: mom/codec/integer.py
# ZERO_BYTE = _compat.ZERO_BYTE
# EMPTY_BYTE = _compat.EMPTY_BYTE
# def bytes_to_uint(raw_bytes):
# def uint_to_bytes(number, fill_size=0, chunk_size=0, overflow=False):
# 
# Path: mom/security/random.py
# HEXADECIMAL_DIGITS = string.DIGITS + "abcdef"
# DIGITS = string.DIGITS
# LOWERCASE_ALPHA = string.ASCII_LOWERCASE
# UPPERCASE_ALPHA = string.ASCII_UPPERCASE
# LOWERCASE_ALPHANUMERIC = LOWERCASE_ALPHA + string.DIGITS
# UPPERCASE_ALPHANUMERIC = UPPERCASE_ALPHA + string.DIGITS
# ALPHA = string.ASCII_LETTERS
# ALPHANUMERIC = ALPHA + string.DIGITS
# ASCII_PRINTABLE = ALPHA + string.DIGITS + string.PUNCTUATION
# ALL_PRINTABLE = string.PRINTABLE
# PUNCTUATION = string.PUNCTUATION
# def generate_random_bits(n_bits, rand_func=generate_random_bytes):
# def generate_random_uint_atmost(n_bits, rand_func=generate_random_bytes):
# def generate_random_uint_exactly(n_bits, rand_func=generate_random_bytes):
# def generate_random_uint_between(low, high, rand_func=generate_random_bytes):
# def generate_random_hex_string(length=8, rand_func=generate_random_bytes):
# def random_choice(sequence, rand_func=generate_random_bytes):
# def random_shuffle(sequence, rand_func=generate_random_bytes):
# def generate_random_sequence(length, pool, rand_func=generate_random_bytes):
# def generate_random_string(length, pool=ALPHANUMERIC,
#                            rand_func=generate_random_bytes):
# def calculate_entropy(length, pool=ALPHANUMERIC):
# def generate_random_sequence_strong(entropy, pool,
#                                     rand_func=generate_random_bytes):
# def generate_random_password(entropy, pool=ASCII_PRINTABLE,
#                              rand_func=generate_random_bytes):


# Path: mom/tests/test_mom_security_random.py
import unittest2
from mom import builtins
from mom.codec import integer
from mom.security import random

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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




__author__ = "yesudeep@google.com (Yesudeep Mangalapilly)"


class Test_generate_random_bits(unittest2.TestCase):
  def test_range(self):
    for _ in range(999):
      n_bits = 4
      value = integer.bytes_to_uint(random.generate_random_bits(n_bits))
      self.assertTrue(value >= 0 and value < (1 << n_bits))

  def test_uniqueness(self):
    # The likely-hood of recurrence should be tiny if a large enough
    # bit size is chosen.

    self.assertNotEqual(random.generate_random_bits(64), random.generate_random_bits(64))