use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.
the class RouteToServerRequestControlTestCase method testDecodeValueSequenceUnexpectedElementType.
/**
* Tests the ability to decode a control with a value sequence containing an
* unexpected element type.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceUnexpectedElementType() throws Exception {
final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString((byte) 0x80, "foo"), new ASN1Boolean((byte) 0x82, true), new ASN1Boolean((byte) 0x00, true));
new RouteToServerRequestControl(new Control(RouteToServerRequestControl.ROUTE_TO_SERVER_REQUEST_OID, true, new ASN1OctetString(valueSequence.encode())));
}
use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.
the class SoftDeletedEntryAccessRequestControlTestCase method testDecodeValueSequenceBadElement.
/**
* Tests the behavior when attempting to decode a control whose value has an
* invalid sequence element.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceBadElement() throws Exception {
final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Boolean((byte) 0x80, false), new ASN1OctetString((byte) 0x83, "unexpected type"));
new SoftDeletedEntryAccessRequestControl(new Control(SoftDeletedEntryAccessRequestControl.SOFT_DELETED_ENTRY_ACCESS_REQUEST_OID, false, new ASN1OctetString(valueSequence.encode())));
}
use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.
the class Control method encode.
/**
* Encodes this control to an ASN.1 sequence suitable for use in an LDAP
* message.
*
* @return The encoded representation of this control.
*/
@NotNull()
public final ASN1Sequence encode() {
final ArrayList<ASN1Element> elementList = new ArrayList<>(3);
elementList.add(new ASN1OctetString(oid));
if (isCritical) {
elementList.add(new ASN1Boolean(isCritical));
}
if (value != null) {
elementList.add(new ASN1OctetString(value.getValue()));
}
return new ASN1Sequence(elementList);
}
use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.
the class SearchRequest method encodeProtocolOp.
/**
* Encodes the search request protocol op to an ASN.1 element.
*
* @return The ASN.1 element with the encoded search request protocol op.
*/
@Override()
@NotNull()
public ASN1Element encodeProtocolOp() {
// Create the search request protocol op.
final ASN1Element[] attrElements = new ASN1Element[attributes.length];
for (int i = 0; i < attrElements.length; i++) {
attrElements[i] = new ASN1OctetString(attributes[i]);
}
final ASN1Element[] protocolOpElements = { new ASN1OctetString(baseDN), new ASN1Enumerated(scope.intValue()), new ASN1Enumerated(derefPolicy.intValue()), new ASN1Integer(sizeLimit), new ASN1Integer(timeLimit), new ASN1Boolean(typesOnly), filter.encode(), new ASN1Sequence(attrElements) };
return new ASN1Sequence(LDAPMessage.PROTOCOL_OP_TYPE_SEARCH_REQUEST, protocolOpElements);
}
use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.
the class ContentSyncInfoIntermediateResponse method encodeValue.
/**
* Encodes the provided information into a form suitable for use as the value
* of this intermediate response.
*
* @param type The type for this sync info message.
* @param cookie The updated sync state cookie.
* @param refreshDone Indicates whether the refresh phase of the
* synchronization operation is complete.
* @param entryUUIDs The set of entryUUIDs for the entries referenced
* in this message.
* @param refreshDeletes Indicates whether the associated entryUUIDs are for
* entries that have been removed.
*
* @return The encoded value.
*/
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ContentSyncInfoType type, @Nullable final ASN1OctetString cookie, final boolean refreshDone, @Nullable final List<UUID> entryUUIDs, final boolean refreshDeletes) {
final ASN1Element e;
switch(type) {
case NEW_COOKIE:
e = new ASN1OctetString(type.getType(), cookie.getValue());
break;
case REFRESH_DELETE:
case REFRESH_PRESENT:
ArrayList<ASN1Element> l = new ArrayList<>(2);
if (cookie != null) {
l.add(cookie);
}
if (!refreshDone) {
l.add(new ASN1Boolean(refreshDone));
}
e = new ASN1Sequence(type.getType(), l);
break;
case SYNC_ID_SET:
l = new ArrayList<>(3);
if (cookie != null) {
l.add(cookie);
}
if (refreshDeletes) {
l.add(new ASN1Boolean(refreshDeletes));
}
final ArrayList<ASN1Element> uuidElements = new ArrayList<>(entryUUIDs.size());
for (final UUID uuid : entryUUIDs) {
uuidElements.add(new ASN1OctetString(StaticUtils.encodeUUID(uuid)));
}
l.add(new ASN1Set(uuidElements));
e = new ASN1Sequence(type.getType(), l);
break;
default:
// This should never happen.
throw new AssertionError("Unexpected sync info type: " + type.name());
}
return new ASN1OctetString(e.encode());
}
Aggregations