def do_test(as_int, prefix, as_rep, base):
     self.assertEqual((as_int, prefix), encoding.to_long(base, encoding.byte_to_int, as_rep))
     self.assertEqual(as_rep, encoding.from_long(as_int, prefix, base, lambda v:v))
示例#2
0
def num_to_bytes(bytes_len, v):  # copied from pycoin.encoding.to_bytes_32
    v = from_long(v, 0, 256, lambda x: x)
    if len(v) > bytes_len:
        raise ValueError("input to num_to_bytes is too large")
    return ((b'\0' * bytes_len) + v)[-bytes_len:]
示例#3
0
 def do_test(as_int, prefix, as_rep, base):
     self.assertEqual((as_int, prefix),
                      encoding.to_long(base, encoding.byte_to_int,
                                       as_rep))
     self.assertEqual(
         as_rep, encoding.from_long(as_int, prefix, base, lambda v: v))
示例#4
0
文件: common.py 项目: F483/btctxstore
def num_to_bytes(bytes_len, v):  # copied from pycoin.encoding.to_bytes_32
    v = from_long(v, 0, 256, lambda x: x)
    if len(v) > bytes_len:
        raise ValueError("input to num_to_bytes is too large")
    return ((b'\0' * bytes_len) + v)[-bytes_len:]