@staticmethod
def compute_ldap_message_size(data):
    """
        Compute LDAP Message size according to BER definite length rules
        Returns -1 if too few data to compute message length
        """
    if isinstance(data, str):
        data = bytearray(data)
    ret_value = -1
    if len(data) > 2:
        if data[1] <= 127:
            ret_value = data[1] + 2
        else:
            bytes_length = data[1] - 128
            if len(data) >= bytes_length + 2:
                value_length = 0
                cont = bytes_length
                for byte in data[2:2 + bytes_length]:
                    cont -= 1
                    value_length += byte * 256 ** cont
                ret_value = value_length + 2 + bytes_length
    return ret_value
