/* Checks to make sure that a complete, valid BER-encoded length is in the buffer. */
static gboolean ber_len_ok(tvbuff_t *tvb, int offset)
/* Checks to make sure that a complete, valid BER-encoded length is in the buffer. */
static gboolean ber_len_ok(tvbuff_t *tvb, int offset)
{
  guint8 ch;
  if (tvb_offset_exists(tvb, offset)) {
    ch = tvb_get_guint8(tvb, offset);
    offset++;
    if (!(ch & 0x80)) {
      return TRUE;
    } else if (tvb_offset_exists(tvb, offset)) {
      ch = tvb_get_guint8(tvb, offset);
      offset++;
      if (!(ch & 0x80)) {
        return TRUE;
      } else if (tvb_offset_exists(tvb, offset)) {
        ch = tvb_get_guint8(tvb, offset);
        offset++;
        if (!(ch & 0x80)) {
          return TRUE;
        } else if (tvb_offset_exists(tvb, offset)) {
          ch = tvb_get_guint8(tvb, offset);
          if (!(ch & 0x80)) {
            return TRUE;
          }
        }
      }
    }
  }
  return FALSE;
}