use of com.unboundid.asn1.ASN1Set in project ldapsdk by pingidentity.
the class Filter method encode.
/**
* Encodes this search filter to an ASN.1 element suitable for inclusion in an
* LDAP search request protocol op.
*
* @return An ASN.1 element containing the encoded search filter.
*/
@NotNull()
public ASN1Element encode() {
switch(filterType) {
case FILTER_TYPE_AND:
case FILTER_TYPE_OR:
final ASN1Element[] filterElements = new ASN1Element[filterComps.length];
for (int i = 0; i < filterComps.length; i++) {
filterElements[i] = filterComps[i].encode();
}
return new ASN1Set(filterType, filterElements);
case FILTER_TYPE_NOT:
return new ASN1Element(filterType, notComp.encode().encode());
case FILTER_TYPE_EQUALITY:
case FILTER_TYPE_GREATER_OR_EQUAL:
case FILTER_TYPE_LESS_OR_EQUAL:
case FILTER_TYPE_APPROXIMATE_MATCH:
final ASN1OctetString[] attrValueAssertionElements = { new ASN1OctetString(attrName), assertionValue };
return new ASN1Sequence(filterType, attrValueAssertionElements);
case FILTER_TYPE_SUBSTRING:
final ArrayList<ASN1OctetString> subList = new ArrayList<>(2 + subAny.length);
if (subInitial != null) {
subList.add(new ASN1OctetString(SUBSTRING_TYPE_SUBINITIAL, subInitial.getValue()));
}
for (final ASN1Element subAnyElement : subAny) {
subList.add(new ASN1OctetString(SUBSTRING_TYPE_SUBANY, subAnyElement.getValue()));
}
if (subFinal != null) {
subList.add(new ASN1OctetString(SUBSTRING_TYPE_SUBFINAL, subFinal.getValue()));
}
final ASN1Element[] subFilterElements = { new ASN1OctetString(attrName), new ASN1Sequence(subList) };
return new ASN1Sequence(filterType, subFilterElements);
case FILTER_TYPE_PRESENCE:
return new ASN1OctetString(filterType, attrName);
case FILTER_TYPE_EXTENSIBLE_MATCH:
final ArrayList<ASN1Element> emElementList = new ArrayList<>(4);
if (matchingRuleID != null) {
emElementList.add(new ASN1OctetString(EXTENSIBLE_TYPE_MATCHING_RULE_ID, matchingRuleID));
}
if (attrName != null) {
emElementList.add(new ASN1OctetString(EXTENSIBLE_TYPE_ATTRIBUTE_NAME, attrName));
}
emElementList.add(new ASN1OctetString(EXTENSIBLE_TYPE_MATCH_VALUE, assertionValue.getValue()));
if (dnAttributes) {
emElementList.add(new ASN1Boolean(EXTENSIBLE_TYPE_DN_ATTRIBUTES, true));
}
return new ASN1Sequence(filterType, emElementList);
default:
throw new AssertionError(ERR_FILTER_INVALID_TYPE.get(StaticUtils.toHex(filterType)));
}
}
use of com.unboundid.asn1.ASN1Set in project ldapsdk by pingidentity.
the class ListNotificationSubscriptionsExtendedRequest method encodeValue.
/**
* Encodes the provided information into an ASN.1 octet string suitable for
* use as the value of this extended request.
*
* @param managerID The notification manager ID. It must not be
* {@code null}.
* @param destinationIDs The set of notification destination IDs for
* which to retrieve the subscription information.
* It may be {@code null} or empty if subscription
* information for all destinations should be
* returned.
*
* @return The ASN.1 octet string containing the encoded value.
*/
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final String managerID, @Nullable final Collection<String> destinationIDs) {
Validator.ensureNotNull(managerID);
final ArrayList<ASN1Element> elements = new ArrayList<>(2);
elements.add(new ASN1OctetString(managerID));
if ((destinationIDs != null) && (!destinationIDs.isEmpty())) {
final LinkedHashSet<ASN1Element> destIDElements = new LinkedHashSet<>(StaticUtils.computeMapCapacity(destinationIDs.size()));
for (final String destinationID : destinationIDs) {
destIDElements.add(new ASN1OctetString(destinationID));
}
elements.add(new ASN1Set(destIDElements));
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
use of com.unboundid.asn1.ASN1Set in project ldapsdk by pingidentity.
the class GetChangelogBatchExtendedRequestTestCase method testDecodeValueSequenceInvalidChangeType.
/**
* Provides test coverage for an attempt to decode an extended request with a
* value sequence with an invalid change type.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceInvalidChangeType() throws Exception {
final ASN1Set changeTypeSet = new ASN1Set((byte) 0xA4, new ASN1Enumerated(0), new ASN1Enumerated(5));
final ASN1Sequence valueSequence = new ASN1Sequence(new EndOfChangelogStartingPoint().encode(), new ASN1Integer(0), changeTypeSet);
new GetChangelogBatchExtendedRequest(new ExtendedRequest(GetChangelogBatchExtendedRequest.GET_CHANGELOG_BATCH_REQUEST_OID, new ASN1OctetString(valueSequence.encode())));
}
use of com.unboundid.asn1.ASN1Set in project ldapsdk by pingidentity.
the class UniquenessRequestControlTestCase method testDecodeControlValueSequenceInvalidPostCommitValidationLevel.
/**
* Tests the behavior when trying to decode a control whose value sequence has
* an invalid multiple post-commit validation level value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeControlValueSequenceInvalidPostCommitValidationLevel() throws Exception {
final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString((byte) 0x80, "uniqueness-id"), new ASN1Set((byte) 0xA1, new ASN1OctetString("uid")), new ASN1Enumerated((byte) 0x87, 12345));
new UniquenessRequestControl(new Control("1.3.6.1.4.1.30221.2.5.52", true, new ASN1OctetString(valueSequence.encode())));
}
use of com.unboundid.asn1.ASN1Set in project ldapsdk by pingidentity.
the class UniquenessRequestControlTestCase method testDecodeControlValueSequenceUnrecognizedElementType.
/**
* Tests the behavior when trying to decode a control whose value sequence has
* an element with an unrecognized BER type.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeControlValueSequenceUnrecognizedElementType() throws Exception {
final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString((byte) 0x80, "uniqueness-id"), new ASN1Set((byte) 0xA1, new ASN1OctetString("uid")), new ASN1Enumerated((byte) 0x8F, 12345));
new UniquenessRequestControl(new Control("1.3.6.1.4.1.30221.2.5.52", true, new ASN1OctetString(valueSequence.encode())));
}
Aggregations