def _help_init_string(N): global inputs if N not in inputs: inputs[N] = [ randutil.insecurerandstr(N), randutil.insecurerandstr(N), ]
def test_could_be(self): # base-32 encoded strings could be for j in range(2**9): rands = randutil.insecurerandstr(random.randrange(1, 2**7)) randsenc = b2a(rands) assert could_be_base32_encoded(randsenc), "rands: %s, randsenc: %s, a2b(randsenc): %s" % (`rands`, `randsenc`, `a2b(randsenc)`,) # base-32 encoded strings with unusual bit lengths could be, too for j in range(2**9): bitl = random.randrange(1, 2**7) bs = randutil.insecurerandstr((bitl+7)/8) # zero-out unused least-sig bits if bitl%8: b=ord(bs[-1]) b = b >> (8 - (bitl%8)) b = b << (8 - (bitl%8)) bs = bs[:-1] + chr(b) assert could_be_base32_encoded_l(b2a_l(bs, bitl), bitl) # anything with a bogus character couldn't be s = b2a(randutil.insecurerandstr(random.randrange(3, 2**7))) assert not could_be_base32_encoded('\x00' + s) assert not could_be_base32_encoded(s + '\x00') assert not could_be_base32_encoded(s[:1] + '\x00' + s[1:]) assert not could_be_base32_encoded(s[:1] + '\x00' + s[2:]) # a base-32 encoded string with an alleged lengthinbits of 16 but with 1-bits in the 18th, 19th, # and 20th location couldn't be. assert not could_be_base32_encoded_l('yyz', 16)
def _help_init_string(N): global inputs if not inputs.has_key(N): inputs[N] = [ randutil.insecurerandstr(N), randutil.insecurerandstr(N), ]
def data_strings(N): assert isinstance(N, int), (N, type(N)) del l[:] for i in range(N): l.append(repr(randutil.insecurerandstr(4))) global s s = json.dumps(l)
def test_big(self): bs = randutil.insecurerandstr(2**9) as=b2a(bs) asl=b2a_long(bs) assert as == asl, "as: %s, asl: %s" % (`as`, `asl`,) as=b2a(bs) bs2=a2b(as) bs2l=a2b_long(as) assert bs2 == bs2l assert bs2 == bs
def DISABLED_test_odd_sizes_violates_preconditions(self): """ The Python implementation of b2a_l() actually works if you pass any lengthinbits, and if you don't zero out the unused least significant bits. The precondition assertions are (a) because the high speed C implementation does not work in those cases and (b) because it might help people discover errors in their own code. Anyway, if you have assertion-checking turned off, then this test should pass, too. """ for j in range(2**6): lib = random.randrange(1, 2**8) bs = randutil.insecurerandstr(random.randrange(1, 2**5)) as = b2a_l(bs, lib) assert len(as) == (lib+4)/5 # the size of the base-32 encoding must be just right asl = b2a_l_long(bs, lib) assert len(asl) == (lib+4)/5 # the size of the base-32 encoding must be just right assert as == asl bs2 = a2b_l(as, lib) assert len(bs2) == (lib+7)/8 # the size of the result must be just right bs2l = a2b_l_long(as, lib) assert len(bs2l) == (lib+7)/8 # the size of the result must be just right assert bs2 == bs2l assert trimnpad(bs, lib) == bs2, "trimnpad(%s, %s): %s, bs2: %s" % (`bs`, lib, `trimnpad(bs, lib)`, `bs2`,)
def test_odd_sizes(self): for j in range(2**6): lib = random.randrange(1, 2**8) bs = randutil.insecurerandstr((lib+7)/8) # zero-out unused least-sig bits if lib%8: b=ord(bs[-1]) b = b >> (8 - (lib%8)) b = b << (8 - (lib%8)) bs = bs[:-1] + chr(b) as = b2a_l(bs, lib) assert len(as) == (lib+4)/5 # the size of the base-32 encoding must be just right asl = b2a_l_long(bs, lib) assert len(asl) == (lib+4)/5 # the size of the base-32 encoding must be just right assert as == asl bs2 = a2b_l(as, lib) assert len(bs2) == (lib+7)/8 # the size of the result must be just right bs2l = a2b_l_long(as, lib) assert len(bs2l) == (lib+7)/8 # the size of the result must be just right assert bs2 == bs2l assert trimnpad(bs, lib) == bs2, "trimnpad(%s, %s): %s, bs2: %s" % (`bs`, lib, `trimnpad(bs, lib)`, `bs2`,)
def random_fsnode(self): coin = random.randrange(0, 3) if coin == 0: cap = uri.CHKFileURI(randutil.insecurerandstr(16), randutil.insecurerandstr(32), random.randrange(1, 5), random.randrange(6, 15), random.randrange(99, 1000000000000)) return ImmutableFileNode(cap, None, None, None, None, None) elif coin == 1: cap = uri.WriteableSSKFileURI(randutil.insecurerandstr(16), randutil.insecurerandstr(32)) n = MutableFileNode(None, None, encoding_parameters, None) return n.init_from_cap(cap) else: assert coin == 2 cap = uri.WriteableSSKFileURI(randutil.insecurerandstr(16), randutil.insecurerandstr(32)) n = MutableFileNode(None, None, encoding_parameters, None) n.init_from_cap(cap) return dirnode.DirectoryNode(n, self.nodemaker, uploader=None)
def genrandstr(strlen): return randutil.insecurerandstr(strlen)
def __init__(self): self._writekey = randutil.insecurerandstr(16) self._fingerprint = randutil.insecurerandstr(32) self._cap = uri.WriteableSSKFileURI(self._writekey, self._fingerprint)
def _help_init_string(N): global inputs if not inputs.has_key(N): inputs[N] = [randutil.insecurerandstr(N), randutil.insecurerandstr(N),]
def _help_bench_e(N): return b2a(randutil.insecurerandstr(N))
def test_ende_long(self): bs = randutil.insecurerandstr(2**3) as=b2a_long(bs) bs2=a2b_long(as) assert bs2 == bs, "bs2: %s, bs: %s" % (`bs2`, `bs`,)
def _help_bench_ed_l(N): return a2b_long(b2a_long(randutil.insecurerandstr(N)))
def _help_bench_e_l(N): return b2a_long(randutil.insecurerandstr(N))
def _help_bench_ed(N): return a2b(b2a(randutil.insecurerandstr(N)))