def test_encode_decode_large():
    bytestring = ('123456789012345678901234567890123456789012345678901234567890'
                  '123456789012345678901234567890123456789012345678901234567890'
                  '123456789012345678901234567890123456789012345678901234567890'
                  '123456789012345678901234567890123456789012345678901234567890'
                  '123456789012345678901234567890123456789012345678901234567890'
                  '123456789012345678901234567890123456789012345678901234567890'
                  '123456789012345678901234567890123456789012345678901234567890')
    int_result = serialization.convert_bytestring_to_int(bytestring)
    assert serialization.convert_int_to_bytestring(int_result) == bytestring
def _get_bytestring_secret(shares, num_players, max_secret_length):
    '''
    Args:
        shares, a list of paired integer shares (see schemes/pairing.py)
        num_players, the number of total players
        max_secret_length, the max length of the share if it were represented as a bytestring
    Returns:
        the original secret as passed to share_authenticated_secret if all shares are valid
        otherwise, no guarantees are made about the value of the bytestring returned
    '''
    tuple_shares = [pairing.elegant_unpair(share) for share in shares]
    return serialization.convert_int_to_bytestring(sss._reconstruct_secret_int(num_players, max_secret_length + 1, tuple_shares))
def reconstruct_secret(num_players, max_secret_length, shares):
    '''
    Args:
        num_players, the total number of players (can be greater than or equal to the number of shares)
        max_secret_length, the maximum length of the secret represented as a bytestring (ie, len(secret))
        shares, a list of strings - each representing an integer value
    Returns:
        the original secret as passed to share_authenticated_secret if all shares are valid
        otherwise, no guarantees are made about the value of the bytestring returned
    '''
    points = [pairing.elegant_unpair(int(share)) for share in shares]
    secret_int = _reconstruct_secret_int(num_players, max_secret_length + 1, points)
    return serialization.convert_int_to_bytestring(secret_int)
def test_large_mutation():
    bytestring = '\x00\x9c\x9e\x16\xe9'
    int_result = serialization.convert_bytestring_to_int(bytestring) + 1000000000000000000  # large relative to bytestring length
    serialization.convert_int_to_bytestring(int_result)
def test_encode_decode_trailing_zeros():
    bytestring = 'e\x9c\x9e\x16\xe9\xea\x15+\xbf]\xebx;o\xef\xc9X1c\xaepj\xebj\x12\xe3r\xcd\xeaM\x00\x00'
    int_result = serialization.convert_bytestring_to_int(bytestring)
    assert serialization.convert_int_to_bytestring(int_result) == bytestring
def test_encode_decode_leading_star():
    bytestring = '**e\x9c\x9e\x16\xe9\xea\x15+\xbf]\xebx;o\xef\xc9X1c\xaepj\xebj\x12\xe3r\xcd\xeaM'
    int_result = serialization.convert_bytestring_to_int(bytestring)
    assert serialization.convert_int_to_bytestring(int_result) == bytestring
def test_encode_decode_small():
    bytestring = '123'
    int_result = serialization.convert_bytestring_to_int(bytestring)
    assert serialization.convert_int_to_bytestring(int_result) == bytestring