use of com.github.zhenwei.core.asn1.ASN1Enumerated in project ldapsdk by pingidentity.
the class GetConfigurationExtendedResult method encodeValue.
/**
* Creates an ASN.1 octet string containing an encoded representation of the
* value for a get configuration extended result with the provided
* information.
*
* @param configurationType The type of configuration that has been
* returned.
* @param fileName The name of the configuration file that has been
* returned.
* @param fileData The raw data for the configuration file that has
* been returned.
*
* @return An ASN.1 octet string containing an encoded representation of the
* value for a get configuration extended result, or {@code null} if
* a result with the provided information should not have a value.
*/
@Nullable()
public static ASN1OctetString encodeValue(@Nullable final GetConfigurationType configurationType, @Nullable final String fileName, @Nullable final byte[] fileData) {
if (configurationType == null) {
Validator.ensureTrue((fileName == null), "The configuration file name must be null if the configuration " + "type is null.");
Validator.ensureTrue((fileData == null), "The configuration file data must be null if the configuration " + "type is null.");
return null;
}
Validator.ensureTrue((fileName != null), "The configuration file name must not be null if the configuration " + "type is not null.");
Validator.ensureTrue((fileData != null), "The configuration file data must not be null if the configuration " + "type is not null.");
final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Enumerated(TYPE_CONFIG_TYPE, configurationType.getIntValue()), new ASN1OctetString(TYPE_FILE_NAME, fileName), new ASN1OctetString(TYPE_FILE_DATA, fileData));
return new ASN1OctetString(valueSequence.encode());
}
use of com.github.zhenwei.core.asn1.ASN1Enumerated in project ldapsdk by pingidentity.
the class GetSubtreeAccessibilityExtendedResult method encodeValue.
/**
* Encodes the value for this extended result using the provided information.
*
* @param restrictions The set of subtree accessibility restrictions to
* include in the response. It may be {@code null} if
* this represents an error response, or it may be empty
* if there are no subtree accessibility restrictions
* defined in the server.
*
* @return An ASN.1 octet string containing the properly-encoded value, or
* {@code null} if there should be no value.
*/
@Nullable()
private static ASN1OctetString encodeValue(@Nullable final Collection<SubtreeAccessibilityRestriction> restrictions) {
if (restrictions == null) {
return null;
}
final ArrayList<ASN1Element> elements = new ArrayList<>(restrictions.size());
for (final SubtreeAccessibilityRestriction r : restrictions) {
final ArrayList<ASN1Element> restrictionElements = new ArrayList<>(4);
restrictionElements.add(new ASN1OctetString(TYPE_BASE_DN, r.getSubtreeBaseDN()));
restrictionElements.add(new ASN1Enumerated(TYPE_STATE, r.getAccessibilityState().intValue()));
if (r.getBypassUserDN() != null) {
restrictionElements.add(new ASN1OctetString(TYPE_BYPASS_USER, r.getBypassUserDN()));
}
restrictionElements.add(new ASN1OctetString(TYPE_EFFECTIVE_TIME, StaticUtils.encodeGeneralizedTime(r.getEffectiveTime())));
elements.add(new ASN1Sequence(restrictionElements));
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
use of com.github.zhenwei.core.asn1.ASN1Enumerated in project ldapsdk by pingidentity.
the class SetNotificationDestinationExtendedRequest 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 destinationID The notification destination ID. It must not
* be {@code null}.
* @param destinationDetails The implementation-specific details for the
* notification destination. At least one detail
* value must be provided.
* @param changeType The change type for the destination details.
*
* @return The ASN.1 octet string containing the encoded value.
*/
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final String managerID, @NotNull final String destinationID, @NotNull final Collection<ASN1OctetString> destinationDetails, @Nullable final SetNotificationDestinationChangeType changeType) {
Validator.ensureNotNull(managerID);
Validator.ensureNotNull(destinationID);
Validator.ensureNotNull(destinationDetails);
Validator.ensureFalse(destinationDetails.isEmpty());
final ArrayList<ASN1Element> elements = new ArrayList<>(4);
elements.add(new ASN1OctetString(managerID));
elements.add(new ASN1OctetString(destinationID));
elements.add(new ASN1Sequence(new ArrayList<ASN1Element>(destinationDetails)));
if ((changeType != null) && (changeType != SetNotificationDestinationChangeType.REPLACE)) {
elements.add(new ASN1Enumerated(BER_TYPE_CHANGE_TYPE, changeType.intValue()));
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
use of com.github.zhenwei.core.asn1.ASN1Enumerated in project ldapsdk by pingidentity.
the class SetSubtreeAccessibilityExtendedRequest method encodeValue.
/**
* Encodes the provided information for use as the extended request value.
*
* @param subtreeBaseDNs The set of base DNs for the target subtrees.
* It must not be {@code null} or empty.
* @param accessibilityState The accessibility state to use for the target
* subtrees.
* @param bypassUserDN The DN of a user that will be allowed to bypass
* restrictions on the target subtrees.
*
* @return An ASN.1 octet string containing the encoded value.
*/
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final Collection<String> subtreeBaseDNs, @NotNull final SubtreeAccessibilityState accessibilityState, @Nullable final String bypassUserDN) {
final Iterator<String> dnIterator = subtreeBaseDNs.iterator();
final String subtreeBaseDN = dnIterator.next();
Validator.ensureNotNull(subtreeBaseDN);
final ArrayList<ASN1Element> elements = new ArrayList<>(4);
elements.add(new ASN1OctetString(subtreeBaseDN));
elements.add(new ASN1Enumerated(accessibilityState.intValue()));
if (bypassUserDN != null) {
elements.add(new ASN1OctetString(TYPE_BYPASS_USER_DN, bypassUserDN));
}
if (dnIterator.hasNext()) {
final ArrayList<ASN1Element> additionalDNElements = new ArrayList<>(subtreeBaseDNs.size() - 1);
while (dnIterator.hasNext()) {
final String additionalDN = dnIterator.next();
Validator.ensureNotNull(additionalDN);
additionalDNElements.add(new ASN1OctetString(additionalDN));
}
elements.add(new ASN1Sequence(TYPE_ADDITIONAL_SUBTREE_BASE_DNS, additionalDNElements));
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
use of com.github.zhenwei.core.asn1.ASN1Enumerated in project ldapsdk by pingidentity.
the class MultiUpdateExtendedRequest method encodeValue.
/**
* Generates an ASN.1 octet string suitable for use as the value of a
* multi-update extended request.
*
* @param errorBehavior The behavior to exhibit if errors are encountered.
* It must not be {@code null}.
* @param requests The set of requests to be processed. It must not
* be {@code null} or empty. Only add, delete, modify,
* modify DN, and certain extended requests (as
* determined by the server) should be included. Each
* request may include zero or more controls that
* should apply only to that request.
*
* @return An ASN.1 octet string suitable for use as the value of a
* multi-update extended request.
*/
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final MultiUpdateErrorBehavior errorBehavior, @NotNull final List<LDAPRequest> requests) {
final ArrayList<ASN1Element> requestElements = new ArrayList<>(requests.size());
for (final LDAPRequest r : requests) {
final ArrayList<ASN1Element> rsElements = new ArrayList<>(2);
switch(r.getOperationType()) {
case ADD:
rsElements.add(((AddRequest) r).encodeProtocolOp());
break;
case DELETE:
rsElements.add(((DeleteRequest) r).encodeProtocolOp());
break;
case MODIFY:
rsElements.add(((ModifyRequest) r).encodeProtocolOp());
break;
case MODIFY_DN:
rsElements.add(((ModifyDNRequest) r).encodeProtocolOp());
break;
case EXTENDED:
rsElements.add(((ExtendedRequest) r).encodeProtocolOp());
break;
}
if (r.hasControl()) {
rsElements.add(Control.encodeControls(r.getControls()));
}
requestElements.add(new ASN1Sequence(rsElements));
}
final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Enumerated(errorBehavior.intValue()), new ASN1Sequence(requestElements));
return new ASN1OctetString(valueSequence.encode());
}
Aggregations