def mpi2str(l, limit): """Convert a list of MPIs to a byte-string. :Parameters: - `l`: list of MPI integers - `limit`: dummy parameter to follow svt_*() suit :Returns: MPI byte-string :note: This should probably return some sort of an index like `str2mpi()` since a limit < len(l) might be useful. But it's not useful now. """ d = [] for i in l: i_d = int2str(i) i_length = len(i_d) bit_count = sigbits(i_d[0]) + (8 * (i_length - 1)) i_length_str = int2str(bit_count) if 2 < len(i_length_str): raise ValueError, "MPI integer > two octs: %s octets used>" % str( i_length) elif 1 == len(i_length_str): i_length_str = ''.join(['\x00', i_length_str]) d.append(''.join([i_length_str, i_d])) # since limit checks complete mpi if limit == len(d): break return ''.join(d)
def create_MPI(i): """Create an MPI out of an integer. :Parameters: - `i`: integer :Returns: `MPI` instance """ d = [] i_d = STN.int2str(i) i_length = len(i_d) bit_count = STN.sigbits(i_d[0]) + (8 * (i_length - 1)) i_length_str = STN.int2str(bit_count) if 2 < len(i_length_str): raise ValueError, "int is larger than two octets can specify - int occupies %s octets" % str( i_length) elif 1 == len(i_length_str): i_length_str = ''.join(['\x00', i_length_str]) d.append(i_length_str) d.append(i_d) return MPI(''.join(d))
def create_MPI(i): """Create an MPI out of an integer. :Parameters: - `i`: integer :Returns: `MPI` instance """ d = [] i_d = STN.int2str(i) i_length = len(i_d) bit_count = STN.sigbits(i_d[0]) + (8 * (i_length - 1)) i_length_str = STN.int2str(bit_count) if 2 < len(i_length_str): raise ValueError, "int is larger than two octets can specify - int occupies %s octets" % str(i_length) elif 1 == len(i_length_str): i_length_str = ''.join(['\x00', i_length_str]) d.append(i_length_str) d.append(i_d) return MPI(''.join(d))