use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.
the class OverrideSearchLimitsRequestControl method encodeValue.
/**
* Encodes the provided set of properties into an ASN.1 element suitable for
* use as the value of this control.
*
* @param properties The map of properties to set in this control. It must
* not be {@code null} or empty, and none of the keys or
* values inside it may be {@code null} or empty.
*
* @return The ASN.1 octet string containing the encoded value.
*/
@NotNull()
static ASN1OctetString encodeValue(@NotNull final Map<String, String> properties) {
Validator.ensureTrue(((properties != null) && (!properties.isEmpty())), "OverrideSearchLimitsRequestControl.<init>properties must not be " + "null or empty");
final ArrayList<ASN1Element> propertyElements = new ArrayList<>(properties.size());
for (final Map.Entry<String, String> e : properties.entrySet()) {
final String propertyName = e.getKey();
final String propertyValue = e.getValue();
Validator.ensureTrue(((propertyName != null) && (!propertyName.isEmpty())), "OverrideSearchLimitsRequestControl.<init>properties keys must " + "not be null or empty");
Validator.ensureTrue(((propertyValue != null) && (!propertyValue.isEmpty())), "OverrideSearchLimitsRequestControl.<init>properties values must " + "not be null or empty");
propertyElements.add(new ASN1Sequence(new ASN1OctetString(propertyName), new ASN1OctetString(propertyValue)));
}
return new ASN1OctetString(new ASN1Sequence(propertyElements).encode());
}
use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.
the class InteractiveTransactionSpecificationRequestControl method encodeValue.
/**
* Encodes the provided information into an ASN.1 octet string suitable for
* use as the value of this control.
*
* @param transactionID The transaction ID for the associated transaction,
* as obtained from the start interactive transaction
* extended operation. It must not be {@code null}.
* @param abortOnFailure Indicates whether the transaction should be aborted
* if the associated operation does not complete
* successfully.
* @param writeLock Indicates whether the server should attempt to
* obtain a write lock on the target entry. This
* should only be {@code false} if the associated
* operation is a search or compare and it is known
* that the target entry will not be updated later in
* the transaction.
*
* @return The ASN.1 octet string containing the encoded value for this
* control.
*/
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ASN1OctetString transactionID, final boolean abortOnFailure, final boolean writeLock) {
Validator.ensureNotNull(transactionID);
final ArrayList<ASN1Element> elements = new ArrayList<>(3);
elements.add(new ASN1OctetString(TYPE_TXN_ID, transactionID.getValue()));
if (abortOnFailure) {
elements.add(new ASN1Boolean(TYPE_ABORT_ON_FAILURE, abortOnFailure));
}
if (!writeLock) {
elements.add(new ASN1Boolean(TYPE_WRITE_LOCK, writeLock));
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.
the class GeneratePasswordResponseControl method encodeValue.
/**
* Encodes the provided information appropriately for use as the value of this
* control.
*
* @param generatedPassword The password generated by the server. It
* must not be {@code null}.
* @param mustChangePassword Indicates whether the user will be required
* to choose a new password the first time
* they authenticate.
* @param secondsUntilExpiration The number of seconds until the new
* password will expire. It may be
* {@code null} if the new password will not
* expire.
*
* @return The ASN.1 octet string suitable for use as the control value.
*/
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ASN1OctetString generatedPassword, final boolean mustChangePassword, @Nullable final Long secondsUntilExpiration) {
final ArrayList<ASN1Element> elements = new ArrayList<>(3);
elements.add(generatedPassword);
elements.add(mustChangePassword ? ASN1Boolean.UNIVERSAL_BOOLEAN_TRUE_ELEMENT : ASN1Boolean.UNIVERSAL_BOOLEAN_FALSE_ELEMENT);
if (secondsUntilExpiration != null) {
elements.add(new ASN1Long(TYPE_SECONDS_UNTIL_EXPIRATION, secondsUntilExpiration));
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.
the class ChangelogEntryIntermediateResponseTestCase method testDecodeValueSequenceWithMalformedElements.
/**
* Tests the behavior when attempting to decode an intermediate response
* with a value sequence with a value sequence containing malformed elements.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceWithMalformedElements() throws Exception {
final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString("foo"), new ASN1OctetString("foo"), new ASN1OctetString("foo"), new ASN1OctetString("foo"));
new ChangelogEntryIntermediateResponse(new IntermediateResponse(ChangelogEntryIntermediateResponse.CHANGELOG_ENTRY_INTERMEDIATE_RESPONSE_OID, new ASN1OctetString(valueSequence.encode())));
}
use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.
the class ChangelogEntryIntermediateResponseTestCase method testDecodeValueSequenceInvalidElementCount.
/**
* Tests the behavior when attempting to decode an intermediate response
* with a value sequence with an unexpected number of elements.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceInvalidElementCount() throws Exception {
final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString("foo"));
new ChangelogEntryIntermediateResponse(new IntermediateResponse(ChangelogEntryIntermediateResponse.CHANGELOG_ENTRY_INTERMEDIATE_RESPONSE_OID, new ASN1OctetString(valueSequence.encode())));
}
Aggregations