@Override
  public Object getObjectToEncode(Object object) {
    if (object instanceof ChosenValue) {
      ChosenValue chosen = (ChosenValue) object;
      return chosen.getValue();
    }

    if (object instanceof ASN1Encodable) {
      Object[] value = new Object[1];
      ((ASN1Encodable) object).encodeValues(value);
      return getObjectToEncode(value[0]);
    }

    return ((Object[]) object)[1];
  }
  @Override
  public int getIndex(Object object) {
    if (object instanceof ChosenValue) {
      ChosenValue chosen = (ChosenValue) object;
      return chosen.getIndex();
    }

    if (object instanceof ASN1Encodable) {
      Object[] value = new Object[1];
      ((ASN1Encodable) object).encodeValues(value);
      return getIndex(value[0]);
    }

    Object[] values = (Object[]) object;
    return ((Integer) values[0]).intValue();
  }