def decode_ber(ber):
    """
    Decodes an array of bytes to an integer value

    If the first byte in the BER length field does not have the high bit set (0x80),
    then that single byte represents an integer between 0 and 127 and indicates
    the number of Value bytes that immediately follows. If the high bit is set,
    then the lower seven bits indicate how many bytes follow that make up a length field
    """
    length = ber[0]
    bytes_read = 1
    if length > 127:
        bytes_read += length & 127 # Strip off the high bit
        length = 0
        for i in range(1, bytes_read):
            length += ber[i] << (8 * (bytes_read - i - 1))
    return length, bytes_read