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(); } SortRequestControl();  SortRequestControl(final SortKey[] keys);  SortRequestControl(final SortKey[] keys, final boolean critical); @Override boolean hasValue(); SortKey[] getSortKeys(); void setSortKeys(final SortKey[] keys); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); @Override byte[] encode(); static final String OID; }
@Test(groups = "control", dataProvider = "request") public void encode(final byte[] berValue, final SortRequestControl expected) throws Exception { Assert.assertEquals(expected.encode(), berValue); }