class SortRequestControl extends AbstractControl implements RequestControl {

  @Override
  public byte[] encode()
  {
    final DEREncoder[] keyEncoders = new DEREncoder[sortKeys.length];
    for (int i = 0; i < sortKeys.length; i++) {
      final List<DEREncoder> l = new ArrayList<>();
      l.add(new OctetStringType(sortKeys[i].getAttributeDescription()));
      if (sortKeys[i].getMatchingRuleId() != null) {
        l.add(new ContextType(0, sortKeys[i].getMatchingRuleId()));
      }
      if (sortKeys[i].getReverseOrder()) {
        l.add(new ContextType(1, sortKeys[i].getReverseOrder()));
      }
      keyEncoders[i] = new ConstructedDEREncoder(UniversalDERTag.SEQ, l.toArray(new DEREncoder[0]));
    }

    final ConstructedDEREncoder se = new ConstructedDEREncoder(UniversalDERTag.SEQ, keyEncoders);
    return se.encode();
  }

  public  SortRequestControl();
  public  SortRequestControl(final SortKey[] keys);
  public  SortRequestControl(final SortKey[] keys, final boolean critical);

}