mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
07.10.2014 df59285898b635c3c9f3011609eb7a73e779ecb9
opendj3-server-dev/src/dsml/org/opends/dsml/protocol/DSMLAddOperation.java
@@ -33,7 +33,7 @@
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.ldap.AddRequestProtocolOp;
import org.opends.server.protocols.ldap.AddResponseProtocolOp;
import org.opends.server.protocols.ldap.LDAPAttribute;
@@ -79,13 +79,13 @@
   * @throws  LDAPException  If an error occurs while interacting with an LDAP
   *                         element.
   *
   * @throws  ASN1Exception  If an error occurs while interacting with an ASN.1
   * @throws  DecodeException  If an error occurs while interacting with an ASN.1
   *                         element.
   */
  public LDAPResult doOperation(ObjectFactory objFactory,
        AddRequest addRequest,
        List<org.opends.server.types.Control> controls)
    throws IOException, LDAPException, ASN1Exception
    throws IOException, LDAPException, DecodeException
  {
    LDAPResult addResponse = objFactory.createLDAPResult();
    addResponse.setRequestID(addRequest.getRequestID());
opendj3-server-dev/src/dsml/org/opends/dsml/protocol/DSMLCompareOperation.java
@@ -32,7 +32,7 @@
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.ldap.CompareRequestProtocolOp;
import org.opends.server.protocols.ldap.CompareResponseProtocolOp;
import org.opends.server.protocols.ldap.LDAPMessage;
@@ -76,13 +76,13 @@
   * @throws  LDAPException  If an error occurs while interacting with an LDAP
   *                         element.
   *
   * @throws  ASN1Exception  If an error occurs while interacting with an ASN.1
   * @throws  DecodeException  If an error occurs while interacting with an ASN.1
   *                         element.
   */
  public LDAPResult doOperation(ObjectFactory objFactory,
        CompareRequest compareRequest,
        List<org.opends.server.types.Control> controls)
    throws IOException, LDAPException, ASN1Exception
    throws IOException, LDAPException, DecodeException
  {
    LDAPResult compareResponse = objFactory.createLDAPResult();
    compareResponse.setRequestID(compareRequest.getRequestID());
opendj3-server-dev/src/dsml/org/opends/dsml/protocol/DSMLDeleteOperation.java
@@ -32,7 +32,7 @@
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.ldap.DeleteRequestProtocolOp;
import org.opends.server.protocols.ldap.DeleteResponseProtocolOp;
import org.opends.server.protocols.ldap.LDAPMessage;
@@ -81,13 +81,13 @@
   * @throws  LDAPException  If an error occurs while interacting with an LDAP
   *                         element.
   *
   * @throws  ASN1Exception  If an error occurs while interacting with an ASN.1
   * @throws  DecodeException  If an error occurs while interacting with an ASN.1
   *                         element.
   */
  public LDAPResult doOperation(ObjectFactory objFactory,
        DelRequest deleteRequest,
        List<org.opends.server.types.Control> controls)
    throws IOException, LDAPException, ASN1Exception
    throws IOException, LDAPException, DecodeException
  {
    LDAPResult delResponse = objFactory.createLDAPResult();
    delResponse.setRequestID(deleteRequest.getRequestID());
opendj3-server-dev/src/dsml/org/opends/dsml/protocol/DSMLExtendedOperation.java
@@ -33,7 +33,7 @@
import java.util.Set;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.ldap.ExtendedRequestProtocolOp;
import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp;
import org.opends.server.protocols.ldap.LDAPMessage;
@@ -98,13 +98,13 @@
   * @throws  LDAPException  If an error occurs while interacting with an LDAP
   *                         element.
   *
   * @throws  ASN1Exception  If an error occurs while interacting with an ASN.1
   * @throws  DecodeException  If an error occurs while interacting with an ASN.1
   *                         element.
   */
  public ExtendedResponse doOperation(ObjectFactory objFactory,
              ExtendedRequest extendedRequest,
              List<org.opends.server.types.Control> controls)
    throws IOException, LDAPException, ASN1Exception
    throws IOException, LDAPException, DecodeException
  {
    ExtendedResponse extendedResponse = objFactory.createExtendedResponse();
    extendedResponse.setRequestID(extendedRequest.getRequestID());
opendj3-server-dev/src/dsml/org/opends/dsml/protocol/DSMLModifyDNOperation.java
@@ -33,7 +33,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.tools.LDAPConnection;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.ldap.LDAPMessage;
import org.opends.server.protocols.ldap.ModifyDNRequestProtocolOp;
import org.opends.server.protocols.ldap.ModifyDNResponseProtocolOp;
@@ -77,13 +77,13 @@
   * @throws  LDAPException  If an error occurs while interacting with an LDAP
   *                         element.
   *
   * @throws  ASN1Exception  If an error occurs while interacting with an ASN.1
   * @throws  DecodeException  If an error occurs while interacting with an ASN.1
   *                         element.
   */
  public LDAPResult doOperation(ObjectFactory objFactory,
        ModifyDNRequest modifyDNRequest,
        List<org.opends.server.types.Control> controls)
    throws IOException, LDAPException, ASN1Exception
    throws IOException, LDAPException, DecodeException
  {
    LDAPResult modDNResponse = objFactory.createLDAPResult();
    modDNResponse.setRequestID(modifyDNRequest.getRequestID());
opendj3-server-dev/src/dsml/org/opends/dsml/protocol/DSMLModifyOperation.java
@@ -33,7 +33,7 @@
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.ldap.LDAPAttribute;
import org.opends.server.protocols.ldap.LDAPMessage;
import org.opends.server.protocols.ldap.LDAPModification;
@@ -81,13 +81,13 @@
   * @throws  LDAPException  If an error occurs while interacting with an LDAP
   *                         element.
   *
   * @throws  ASN1Exception  If an error occurs while interacting with an ASN.1
   * @throws  DecodeException  If an error occurs while interacting with an ASN.1
   *                         element.
   */
  public LDAPResult doOperation(ObjectFactory objFactory,
        ModifyRequest modifyRequest,
        List<org.opends.server.types.Control> controls)
        throws IOException, LDAPException, ASN1Exception
        throws IOException, LDAPException, DecodeException
  {
    LDAPResult modResponse = objFactory.createLDAPResult();
    modResponse.setRequestID(modifyRequest.getRequestID());
opendj3-server-dev/src/dsml/org/opends/dsml/protocol/DSMLSearchOperation.java
@@ -37,7 +37,7 @@
import javax.xml.bind.JAXBElement;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.ldap.LDAPAttribute;
import org.opends.server.protocols.ldap.LDAPConstants;
import org.opends.server.protocols.ldap.LDAPFilter;
@@ -623,7 +623,7 @@
      while (opType != LDAPConstants.OP_TYPE_SEARCH_RESULT_DONE);
    }
    catch (ASN1Exception ae)
    catch (DecodeException ae)
    {
      ae.printStackTrace();
      throw new IOException(ae.getMessage());
opendj3-server-dev/src/dsml/org/opends/dsml/protocol/DSMLServlet.java
@@ -69,7 +69,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.controls.ProxiedAuthV2Control;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.ldap.LDAPConstants;
import org.opends.server.protocols.ldap.LDAPFilter;
import org.opends.server.protocols.ldap.LDAPMessage;
@@ -300,11 +300,10 @@
      LocalizableMessage m = INFO_RESULT_CLIENT_SIDE_ENCODING_ERROR.get();
      throw new LDAPConnectionException(m, CLIENT_SIDE_CONNECT_ERROR, null, le);
    }
    catch (ASN1Exception ae)
    catch (DecodeException ae)
    {
      LocalizableMessage m = INFO_RESULT_CLIENT_SIDE_ENCODING_ERROR.get();
      throw new LDAPConnectionException(m, CLIENT_SIDE_CONNECT_ERROR, null,
          ae);
      throw new LDAPConnectionException(m, CLIENT_SIDE_CONNECT_ERROR, null, ae);
    }
    catch (IOException ie)
    {
@@ -621,7 +620,7 @@
   * @return a JAXBElement that contains an ErrorResponse
   */
  private JAXBElement<ErrorResponse> createErrorResponse(Throwable t) {
    // potential exceptions are IOException, LDAPException, ASN1Exception
    // potential exceptions are IOException, LDAPException, DecodeException
    ErrorResponse errorResponse = objFactory.createErrorResponse();
    errorResponse.setMessage(String.valueOf(t));
opendj3-server-dev/src/server/org/opends/server/backends/jeb/ID2Entry.java
@@ -26,25 +26,20 @@
 */
package org.opends.server.backends.jeb;
import org.forgerock.i18n.LocalizableMessage;
import static org.opends.server.core.DirectoryServer.getMaxInternalBufferSize;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import static org.opends.messages.JebMessages.*;
import static org.forgerock.util.Utils.closeSilently;
import com.sleepycat.je.*;
import org.opends.server.types.*;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.api.CompressedSchema;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.LDAPException;
import com.sleepycat.je.*;
import java.io.IOException;
import java.io.OutputStream;
@@ -52,6 +47,10 @@
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterOutputStream;
import static org.forgerock.util.Utils.*;
import static org.opends.messages.JebMessages.*;
import static org.opends.server.core.DirectoryServer.*;
/**
 * Represents the database containing the LDAP entries. The database key is
 * the entry ID and the value is the entry contents.
@@ -114,22 +113,21 @@
    private void release()
    {
      closeSilently(writer); // Clears encodedBuffer as well.
      closeSilently(writer);
      encodedBuffer.clearAndTruncate(maxBufferSize, BUFFER_INIT_SIZE);
      entryBuffer.clearAndTruncate(maxBufferSize, BUFFER_INIT_SIZE);
      compressedEntryBuffer.clearAndTruncate(maxBufferSize, BUFFER_INIT_SIZE);
    }
    private Entry decode(ByteString bytes, CompressedSchema compressedSchema)
        throws DirectoryException, ASN1Exception, LDAPException,
        throws DirectoryException, DecodeException, LDAPException,
        DataFormatException, IOException
    {
      // Get the format version.
      byte formatVersion = bytes.byteAt(0);
      if(formatVersion != JebFormat.FORMAT_VERSION)
      {
        LocalizableMessage message =
            ERR_JEB_INCOMPATIBLE_ENTRY_VERSION.get(formatVersion);
        throw new ASN1Exception(message);
        throw DecodeException.error(ERR_JEB_INCOMPATIBLE_ENTRY_VERSION.get(formatVersion));
      }
      // Read the ASN1 sequence.
@@ -296,7 +294,7 @@
   * @param bytes A byte array containing the encoded database value.
   * @param compressedSchema The compressed schema manager to use when decoding.
   * @return The decoded entry.
   * @throws ASN1Exception If the data is not in the expected ASN.1 encoding
   * @throws DecodeException If the data is not in the expected ASN.1 encoding
   * format.
   * @throws LDAPException If the data is not in the expected ASN.1 encoding
   * format.
@@ -307,7 +305,7 @@
   */
  public static Entry entryFromDatabase(ByteString bytes,
      CompressedSchema compressedSchema) throws DirectoryException,
      ASN1Exception, LDAPException, DataFormatException, IOException
      DecodeException, LDAPException, DataFormatException, IOException
  {
    EntryCodec codec = acquireEntryCodec();
    try
opendj3-server-dev/src/server/org/opends/server/backends/jeb/JECompressedSchema.java
@@ -38,13 +38,13 @@
import org.opends.server.api.CompressedSchema;
import org.opends.server.core.DirectoryServer;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
import org.opends.server.util.StaticUtils;
import com.sleepycat.je.Cursor;
import com.sleepycat.je.Database;
@@ -77,13 +77,13 @@
  private static final String DB_NAME_OC = "compressed_object_classes";
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
  // The compressed attribute description schema database.
  /** The compressed attribute description schema database. */
  private Database adDatabase;
  // The environment in which the databases are held.
  /** The environment in which the databases are held. */
  private Environment environment;
  // The compresesd object class set schema database.
  /** The compressed object class set schema database. */
  private Database ocDatabase;
  private final ByteStringBuilder storeAttributeWriterBuffer =
@@ -134,14 +134,7 @@
      // Ignore.
    }
    try
    {
      adDatabase.close();
    }
    catch (final Exception e)
    {
      // Ignore.
    }
    StaticUtils.close(adDatabase);
    try
    {
@@ -152,14 +145,7 @@
      // Ignore.
    }
    try
    {
      ocDatabase.close();
    }
    catch (final Exception e)
    {
      // Ignore.
    }
    StaticUtils.close(ocDatabase);
    adDatabase = null;
    ocDatabase = null;
@@ -282,13 +268,11 @@
            LockMode.READ_UNCOMMITTED);
      }
    }
    catch (final ASN1Exception ae)
    catch (final IOException e)
    {
      logger.traceException(ae);
      final LocalizableMessage m = ERR_JEB_COMPSCHEMA_CANNOT_DECODE_OC_TOKEN.get(ae
          .getMessage());
      throw new InitializationException(m, ae);
      logger.traceException(e);
      throw new InitializationException(
          ERR_JEB_COMPSCHEMA_CANNOT_DECODE_OC_TOKEN.get(e.getMessage()), e);
    }
    finally
    {
@@ -321,13 +305,11 @@
            LockMode.READ_UNCOMMITTED);
      }
    }
    catch (final ASN1Exception ae)
    catch (final IOException e)
    {
      logger.traceException(ae);
      final LocalizableMessage m = ERR_JEB_COMPSCHEMA_CANNOT_DECODE_AD_TOKEN.get(ae
          .getMessage());
      throw new InitializationException(m, ae);
      logger.traceException(e);
      throw new InitializationException(
          ERR_JEB_COMPSCHEMA_CANNOT_DECODE_AD_TOKEN.get(e.getMessage()), e);
    }
    finally
    {
opendj3-server-dev/src/server/org/opends/server/controls/AccountUsableRequestControl.java
@@ -29,7 +29,7 @@
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.Control;
import org.opends.server.types.DirectoryException;
opendj3-server-dev/src/server/org/opends/server/controls/AccountUsableResponseControl.java
@@ -30,9 +30,7 @@
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import org.forgerock.opendj.io.*;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.i18n.slf4j.LocalizedLogger;
@@ -391,7 +389,7 @@
   * @throws IOException If a problem occurs while writing to the stream.
   */
  public void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    if(isUsable)
    {
opendj3-server-dev/src/server/org/opends/server/controls/AuthorizationIdentityResponseControl.java
@@ -29,7 +29,7 @@
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import static org.opends.messages.ProtocolMessages.*;
opendj3-server-dev/src/server/org/opends/server/controls/EntryChangeNotificationControl.java
@@ -30,11 +30,7 @@
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_INTEGER_TYPE;
import org.forgerock.opendj.io.*;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.i18n.slf4j.LocalizedLogger;
@@ -83,7 +79,7 @@
        changeType = PersistentSearchChangeType.valueOf(changeTypeValue);
        if(reader.hasNextElement() &&
            reader.peekType() == UNIVERSAL_OCTET_STRING_TYPE)
            reader.peekType() == ASN1.UNIVERSAL_OCTET_STRING_TYPE)
        {
          if (changeType != PersistentSearchChangeType.MODIFY_DN)
          {
@@ -94,7 +90,7 @@
          previousDN = DN.valueOf(reader.readOctetStringAsString());
        }
        if(reader.hasNextElement() &&
            reader.peekType() == UNIVERSAL_INTEGER_TYPE)
            reader.peekType() == ASN1.UNIVERSAL_INTEGER_TYPE)
        {
          changeNumber = reader.readInteger();
        }
@@ -240,7 +236,7 @@
   * @throws IOException If a problem occurs while writing to the stream.
   */
  public void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence();
    writer.writeEnumerated(changeType.intValue());
opendj3-server-dev/src/server/org/opends/server/controls/EntryChangelogNotificationControl.java
@@ -27,7 +27,6 @@
package org.opends.server.controls;
import static org.opends.messages.ProtocolMessages.ERR_ECLN_CANNOT_DECODE_VALUE;
import static org.opends.messages.ProtocolMessages.ERR_ECLN_NO_CONTROL_VALUE;
import static org.opends.server.protocols.asn1.ASN1Constants.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.getExceptionMessage;
@@ -35,9 +34,9 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.Control;
import org.opends.server.types.DirectoryException;
@@ -133,7 +132,7 @@
   * @throws IOException If a problem occurs while writing to the stream.
   */
  public void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence();
    writer.writeOctetString(cookie.toString());
    writer.writeEndSequence();
opendj3-server-dev/src/server/org/opends/server/controls/ExternalChangelogRequestControl.java
@@ -26,16 +26,15 @@
 */
package org.opends.server.controls;
import static org.opends.messages.ProtocolMessages.*;
import static org.opends.server.protocols.asn1.ASN1Constants.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.getExceptionMessage;
import java.io.IOException;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.replication.common.MultiDomainServerState;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.Control;
@@ -155,7 +154,7 @@
  protected void writeValue(ASN1Writer writer)
      throws IOException
  {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeOctetString(this.cookie.toString());
    writer.writeEndSequence();
  }
opendj3-server-dev/src/server/org/opends/server/controls/GetEffectiveRightsRequestControl.java
@@ -26,21 +26,22 @@
 */
package org.opends.server.controls;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import static org.opends.server.util.ServerConstants.OID_GET_EFFECTIVE_RIGHTS;
import org.opends.server.core.DirectoryServer;
import static org.opends.messages.ProtocolMessages.*;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.*;
import java.util.List;
import java.util.LinkedList;
import static org.opends.messages.ProtocolMessages.*;
import static org.opends.server.util.ServerConstants.*;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
/**
 * This class partially implements the geteffectiverights control as defined
@@ -73,7 +74,7 @@
public class GetEffectiveRightsRequestControl extends Control
{
  /**
   * ControlDecoder implentation to decode this control from a ByteString.
   * ControlDecoder implementation to decode this control from a ByteString.
   */
  private static final class Decoder
      implements ControlDecoder<GetEffectiveRightsRequestControl>
@@ -126,7 +127,7 @@
            reader.readEndSequence();
          }
          reader.readEndSequence();
        } catch (ASN1Exception e) {
        } catch (IOException e) {
          logger.traceException(e);
          LocalizableMessage message =
@@ -223,7 +224,7 @@
   */
  @Override
  public void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence();
    if(authzDN != null)
opendj3-server-dev/src/server/org/opends/server/controls/LDAPAssertionRequestControl.java
@@ -28,9 +28,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import org.forgerock.opendj.io.*;
import org.opends.server.protocols.ldap.LDAPFilter;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
@@ -137,7 +135,7 @@
   */
  @Override
  public void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    rawFilter.write(writer);
    writer.writeEndSequence();
  }
opendj3-server-dev/src/server/org/opends/server/controls/LDAPPostReadRequestControl.java
@@ -35,10 +35,9 @@
import java.util.Set;
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import static org.opends.server.plugins.LDAPADListPlugin.*;
import static org.opends.server.protocols.asn1.ASN1Constants.*;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
@@ -193,7 +192,7 @@
  @Override
  public void writeValue(ASN1Writer writer) throws IOException
  {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    {
      writer.writeStartSequence();
      if (rawAttributes != null)
opendj3-server-dev/src/server/org/opends/server/controls/LDAPPostReadResponseControl.java
@@ -28,10 +28,9 @@
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import org.forgerock.opendj.io.*;
import org.opends.server.protocols.ldap.*;
import org.opends.server.protocols.ldap.LDAPReader;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.i18n.slf4j.LocalizedLogger;
@@ -153,7 +152,7 @@
   */
  @Override
  public void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    SearchResultEntryProtocolOp protocolOp =
        new SearchResultEntryProtocolOp(searchEntry);
opendj3-server-dev/src/server/org/opends/server/controls/LDAPPreReadRequestControl.java
@@ -35,10 +35,9 @@
import java.util.Set;
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import static org.opends.server.plugins.LDAPADListPlugin.*;
import static org.opends.server.protocols.asn1.ASN1Constants.*;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.i18n.slf4j.LocalizedLogger;
@@ -163,7 +162,7 @@
  @Override
  public void writeValue(ASN1Writer writer) throws IOException
  {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    {
      writer.writeStartSequence();
      if (rawAttributes != null)
opendj3-server-dev/src/server/org/opends/server/controls/LDAPPreReadResponseControl.java
@@ -28,9 +28,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import org.forgerock.opendj.io.*;
import org.opends.server.protocols.ldap.SearchResultEntryProtocolOp;
import org.opends.server.protocols.ldap.LDAPReader;
import org.opends.server.types.*;
@@ -156,7 +154,7 @@
   */
  @Override
  public void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    SearchResultEntryProtocolOp protocolOp =
        new SearchResultEntryProtocolOp(searchEntry);
opendj3-server-dev/src/server/org/opends/server/controls/MatchedValuesControl.java
@@ -32,9 +32,7 @@
import java.util.ArrayList;
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import org.forgerock.opendj.io.*;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.i18n.slf4j.LocalizedLogger;
@@ -157,7 +155,7 @@
   */
  @Override
  public void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence();
    for (MatchedValuesFilter f : filters)
opendj3-server-dev/src/server/org/opends/server/controls/MatchedValuesFilter.java
@@ -40,7 +40,7 @@
import org.opends.server.api.OrderingMatchingRule;
import org.opends.server.api.SubstringMatchingRule;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.forgerock.util.Reject;
opendj3-server-dev/src/server/org/opends/server/controls/PagedResultsControl.java
@@ -31,9 +31,7 @@
import static org.opends.messages.ProtocolMessages.*;
import static org.opends.server.util.ServerConstants.OID_PAGED_RESULTS_CONTROL;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import org.forgerock.opendj.io.*;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import java.io.IOException;
@@ -187,7 +185,7 @@
   */
  @Override
  public void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence();
    writer.writeInteger(size);
opendj3-server-dev/src/server/org/opends/server/controls/PasswordExpiredControl.java
@@ -29,7 +29,7 @@
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.Control;
import org.opends.server.types.DirectoryException;
opendj3-server-dev/src/server/org/opends/server/controls/PasswordExpiringControl.java
@@ -29,7 +29,7 @@
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.i18n.slf4j.LocalizedLogger;
opendj3-server-dev/src/server/org/opends/server/controls/PasswordPolicyRequestControl.java
@@ -29,7 +29,7 @@
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.Control;
import org.opends.server.types.DirectoryException;
opendj3-server-dev/src/server/org/opends/server/controls/PasswordPolicyResponseControl.java
@@ -31,9 +31,7 @@
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import org.forgerock.opendj.io.*;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
@@ -247,7 +245,7 @@
   */
  @Override
  protected void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence();
    if (warningType != null)
opendj3-server-dev/src/server/org/opends/server/controls/PersistentSearchControl.java
@@ -31,9 +31,7 @@
import java.util.Set;
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import org.forgerock.opendj.io.*;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
@@ -190,7 +188,7 @@
   */
  @Override
  protected void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence();
    writer.writeInteger(
opendj3-server-dev/src/server/org/opends/server/controls/ProxiedAuthV1Control.java
@@ -34,13 +34,12 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.PasswordPolicyState;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import static org.opends.messages.ProtocolMessages.*;
import static org.opends.server.protocols.asn1.ASN1Constants.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
@@ -208,7 +207,7 @@
   */
  @Override
  protected void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence();
    writer.writeOctetString(rawAuthorizationDN);
opendj3-server-dev/src/server/org/opends/server/controls/ProxiedAuthV2Control.java
@@ -35,9 +35,9 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.PasswordPolicyState;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import static org.opends.messages.ProtocolMessages.*;
opendj3-server-dev/src/server/org/opends/server/controls/ServerSideSortRequestControl.java
@@ -35,9 +35,7 @@
import org.opends.server.api.OrderingMatchingRule;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import org.forgerock.opendj.io.*;
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
@@ -496,7 +494,7 @@
  private void writeValueFromString(ASN1Writer writer) throws IOException
  {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence();
    for(String[] strs : decodedKeyList)
@@ -523,7 +521,7 @@
  private void writeValueFromSortOrder(ASN1Writer writer) throws IOException
  {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence();
    for (SortKey sortKey : sortOrder.getSortKeys())
opendj3-server-dev/src/server/org/opends/server/controls/ServerSideSortResponseControl.java
@@ -30,9 +30,7 @@
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import org.forgerock.opendj.io.*;
import org.opends.server.types.Control;
import org.opends.server.types.DirectoryException;
import org.forgerock.opendj.ldap.ByteString;
@@ -219,7 +217,7 @@
   */
  @Override
  protected void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence();
    writer.writeEnumerated(resultCode);
opendj3-server-dev/src/server/org/opends/server/controls/SubentriesControl.java
@@ -29,13 +29,11 @@
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import static org.opends.messages.ProtocolMessages.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
@@ -125,7 +123,7 @@
  @Override
  protected void writeValue(ASN1Writer writer) throws IOException
  {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeBoolean(visibility);
    writer.writeEndSequence();
  }
opendj3-server-dev/src/server/org/opends/server/controls/SubtreeDeleteControl.java
@@ -34,7 +34,7 @@
import java.io.IOException;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.Control;
import org.opends.server.types.DirectoryException;
opendj3-server-dev/src/server/org/opends/server/controls/VLVRequestControl.java
@@ -30,9 +30,7 @@
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import org.forgerock.opendj.io.*;
import org.opends.server.types.Control;
import org.opends.server.types.DirectoryException;
import org.forgerock.opendj.ldap.ByteString;
@@ -412,7 +410,7 @@
   */
  @Override
  protected void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence();
    writer.writeInteger(beforeCount);
opendj3-server-dev/src/server/org/opends/server/controls/VLVResponseControl.java
@@ -30,9 +30,7 @@
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.
    UNIVERSAL_OCTET_STRING_TYPE;
import org.forgerock.opendj.io.*;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import static org.opends.messages.ProtocolMessages.*;
@@ -243,7 +241,7 @@
   */
  @Override
  protected void writeValue(ASN1Writer writer) throws IOException {
    writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence();
    writer.writeInteger(targetPosition);
opendj3-server-dev/src/server/org/opends/server/core/DefaultCompressedSchema.java
@@ -30,7 +30,7 @@
import static org.opends.messages.CoreMessages.*;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
import static org.opends.server.util.StaticUtils.*;
import java.io.File;
import java.io.FileInputStream;
@@ -43,9 +43,9 @@
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.api.CompressedSchema;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.DirectoryException;
@@ -297,17 +297,7 @@
      }
      finally
      {
        try
        {
          if (outputStream != null)
          {
            outputStream.close();
          }
        }
        catch (final Exception e)
        {
          logger.traceException(e);
        }
        close(outputStream);
      }
    }
  }
opendj3-server-dev/src/server/org/opends/server/crypto/GetSymmetricKeyExtendedOperation.java
@@ -36,10 +36,10 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ExtendedOperation;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.ldap.DecodeException;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
@@ -129,13 +129,10 @@
      }
      reader.readEndSequence();
    }
    catch (ASN1Exception ae)
    catch (DecodeException e)
    {
      logger.traceException(ae);
      LocalizableMessage message = ERR_GET_SYMMETRIC_KEY_ASN1_DECODE_EXCEPTION.get(
           ae.getMessage());
      operation.appendErrorMessage(message);
      logger.traceException(e);
      operation.appendErrorMessage(ERR_GET_SYMMETRIC_KEY_ASN1_DECODE_EXCEPTION.get(e.getMessage()));
      return;
    }
    catch (Exception e)
opendj3-server-dev/src/server/org/opends/server/extensions/CancelExtendedOperation.java
@@ -33,8 +33,8 @@
import org.opends.server.config.ConfigException;
import org.opends.server.core.ExtendedOperation;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import static org.opends.messages.ExtensionMessages.*;
opendj3-server-dev/src/server/org/opends/server/extensions/GetConnectionIDExtendedOperation.java
@@ -32,10 +32,10 @@
import org.opends.server.config.ConfigException;
import org.opends.server.core.ExtendedOperation;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.ldap.DecodeException;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
@@ -118,11 +118,11 @@
   *
   * @return  The connection ID decoded from the provided response value.
   *
   * @throws ASN1Exception  If an error occurs while trying to decode the
   * @throws DecodeException  If an error occurs while trying to decode the
   *                         response value.
   */
  public static long decodeResponseValue(ByteString responseValue)
         throws ASN1Exception
         throws DecodeException
  {
    ASN1Reader reader = ASN1.getReader(responseValue);
    try
opendj3-server-dev/src/server/org/opends/server/extensions/LDAPPassThroughAuthenticationPolicyFactory.java
@@ -47,7 +47,7 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyOperation;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.ldap.*;
import org.opends.server.schema.GeneralizedTimeSyntax;
@@ -1158,7 +1158,7 @@
        {
          responseMessage = reader.readMessage();
        }
        catch (final ASN1Exception e)
        catch (final DecodeException e)
        {
          // ASN1 layer hides all underlying IO exceptions.
          if (e.getCause() instanceof SocketTimeoutException)
opendj3-server-dev/src/server/org/opends/server/extensions/PasswordModifyExtendedOperation.java
@@ -46,9 +46,9 @@
import org.opends.server.core.ModifyOperation;
import org.opends.server.core.PasswordPolicyState;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.schema.AuthPasswordSyntax;
import org.opends.server.schema.UserPasswordSyntax;
opendj3-server-dev/src/server/org/opends/server/extensions/PasswordPolicyStateExtendedOperation.java
@@ -40,9 +40,9 @@
import org.opends.server.config.ConfigException;
import org.opends.server.core.*;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.schema.GeneralizedTimeSyntax;
opendj3-server-dev/src/server/org/opends/server/plugins/ChangeNumberControlPlugin.java
@@ -42,7 +42,7 @@
import org.opends.server.api.plugin.PluginType;
import org.opends.server.api.plugin.PluginResult;
import org.opends.server.config.ConfigException;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.replication.common.CSN;
import org.opends.server.replication.protocol.OperationContext;
import org.opends.server.types.ConfigChangeResult;
opendj3-server-dev/src/server/org/opends/server/plugins/profiler/ProfileStack.java
@@ -26,14 +26,11 @@
 */
package org.opends.server.plugins.profiler;
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
/**
 * This class defines a data structure that may be used to hold information
@@ -324,10 +321,9 @@
   *                 information from.
   *
   * @return  The decoded profile stack.
   * @throws ASN1Exception If the element could not be decoded for some reason.
   *
   * @throws IOException If the element could not be decoded for some reason.
   */
  public static ProfileStack decode(ASN1Reader reader) throws ASN1Exception
  public static ProfileStack decode(ASN1Reader reader) throws IOException
  {
    reader.readStartSequence();
opendj3-server-dev/src/server/org/opends/server/plugins/profiler/ProfileViewer.java
@@ -25,9 +25,6 @@
 *      Portions Copyright 2012-2014 ForgeRock AS
 */
package org.opends.server.plugins.profiler;
import org.forgerock.i18n.LocalizableMessage;
import java.awt.BorderLayout;
import java.awt.Container;
@@ -49,7 +46,9 @@
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import org.opends.server.protocols.asn1.*;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import com.forgerock.opendj.cli.ArgumentException;
import com.forgerock.opendj.cli.ArgumentParser;
import com.forgerock.opendj.cli.BooleanArgument;
@@ -220,12 +219,8 @@
   *
   * @throws  IOException  If a problem occurs while trying to read from the
   *                       data file.
   *
   * @throws  ASN1Exception  If an error occurs while trying to decode the
   *                         contents of the file into profile stack objects.
   */
  public void processDataFile(String filename)
         throws IOException, ASN1Exception
  public void processDataFile(String filename) throws IOException
  {
    // Try to open the file for reading.
    ASN1Reader reader = ASN1.getReader(new FileInputStream(filename));
opendj3-server-dev/src/server/org/opends/server/plugins/profiler/ProfilerThread.java
@@ -26,19 +26,16 @@
 */
package org.opends.server.plugins.profiler;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.opends.server.api.DirectoryThread;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import static org.opends.server.util.StaticUtils.*;
/**
 * This class defines a thread that may be used to actually perform
@@ -218,7 +215,8 @@
  {
    // Open the capture file for writing.  We'll use an ASN.1 writer to write
    // the data.
    ASN1Writer writer = ASN1.getWriter(new FileOutputStream(filename));
    FileOutputStream fos = new FileOutputStream(filename);
    ASN1Writer writer = ASN1.getWriter(fos);
    try
@@ -254,7 +252,7 @@
    finally
    {
      // Make sure to close the file when we're done.
      writer.close();
      close(writer, fos);
    }
  }
}
opendj3-server-dev/src/server/org/opends/server/protocols/internal/InternalLDAPInputStream.java
@@ -32,8 +32,8 @@
import java.io.InputStream;
import java.util.concurrent.ArrayBlockingQueue;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.protocols.ldap.LDAPMessage;
import org.forgerock.opendj.ldap.ByteSequenceReader;
import org.forgerock.opendj.ldap.ByteStringBuilder;
opendj3-server-dev/src/server/org/opends/server/protocols/internal/InternalLDAPOutputStream.java
@@ -35,8 +35,8 @@
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.core.*;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.opends.server.protocols.ldap.*;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/ASN1ByteChannelReader.java
New file
@@ -0,0 +1,575 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2011-2014 ForgeRock AS.
 */
package org.opends.server.protocols.ldap;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.ldap.ByteSequenceReader;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import java.nio.ByteBuffer;
import java.nio.channels.IllegalBlockingModeException;
import java.nio.channels.ReadableByteChannel;
import java.io.IOException;
import java.io.InputStream;
/**
 * This class is for reading ASN.1 elements from a readable byte
 * channel. It will handle all partial element reads from the channel
 * and save any unread ASN.1 elements if required. All data read from
 * the channel will be ready to be read as ASN.1 elements no matter
 * how many times the channel is read. However, to minimize the the
 * amount of memory used by this reader, the client should read ASN.1
 * elements as soon as they are read off the channel.
 * <p>
 * {@code ASN1ByteChannelReader}s are created using the factory
 * methods in {@link ASN1}.
 * <p>
 * The client should use this class in the following manner:
 *<p>
 * When NIO signals new data is available in the channel, the client
 * should call {@link #processChannelData()}.
 *<p>
 * If bytes are read from the channel, the client should call
 * {@link #elementAvailable()} to see if a complete element is ready to
 * be read. However, if no data is actually read, the client should
 * wait for the next signal and try again.
 * <p>
 * As long as a complete element is ready, the client should read the
 * appropriate ASN.1 element(s). Once no more complete elements are
 * available, the client should call {@link #processChannelData()}
 * again to read more data (if available).
 * <p>
 * <b>NOTE:</b> Since this reader is non blocking, reading ASN.1
 * elements before making sure they are ready could result in
 * {@link IllegalBlockingModeException}s being thrown while reading
 * ASN.1 elements. Once an exception is thrown, the state of the reader
 * is no longer stable and can not be used again.
 */
final class ASN1ByteChannelReader implements ASN1Reader
{
  // The byte channel to read from.
  private final ReadableByteChannel byteChannel;
  // The wrapped ASN.1 reader.
  private final ASN1Reader reader;
  // The NIO ByteStringBuilder that stores any immediate data read off
  // the channel.
  private final ByteBuffer byteBuffer;
  // The save buffer used to store any unprocessed data waiting
  // to be read as ASN.1 elements. (Usually due to reading
  // incomplete elements from the channel).
  private final ByteStringBuilder saveBuffer;
  // The save buffer reader.
  private final ByteSequenceReader saveBufferReader;
  /**
   * An adaptor class for reading from a save buffer and the NIO byte buffer
   * sequentially using the InputStream interface.
   *
   * Since the NIO byte buffer is re-used when reading off the channel, any
   * unused data will be appended to the save buffer before reading off the
   * channel again. This reader will always read the save buffer first before
   * the actual NIO byte buffer to ensure bytes are read in the same order
   * as they are received.
   *
   * The read methods of this stream will throw an IllegalBlockingModeException
   * if invoked when there are no data to read from the save buffer or the
   * channel buffer.
   *
   * The stream will not support the mark or reset methods.
   */
  private final class CombinedBufferInputStream extends InputStream
  {
    /**
     * {@inheritDoc}
     */
    @Override
    public int available()
    {
      // The number of available bytes is the sum of the save buffer
      // and the last read data in the NIO ByteStringBuilder.
      return saveBufferReader.remaining() + byteBuffer.remaining();
    }
    /**
     * Reads the next byte of data from the save buffer or channel buffer.
     * The value byte is returned as an int in the range 0 to 255.
     * If no byte is available in the save buffer or channel buffer,
     * IllegalBlockingModeException will be thrown.
     *
     * @return the next byte of data.
     * @throws IllegalBlockingModeException if there are more bytes available.
     */
    @Override
    public int read()
    {
      if(saveBufferReader.remaining() > 0)
      {
        // Try saved buffer first
        return 0xFF & saveBufferReader.get();
      }
      if(byteBuffer.remaining() > 0)
      {
        // Must still be on the channel buffer
        return 0xFF & byteBuffer.get();
      }
      throw new IllegalBlockingModeException();
    }
    /**
     * Reads up to len bytes of data from the save buffer or channel buffer
     * into an array of bytes. An attempt is made to read as many as len bytes,
     * but a smaller number may be read. The number of bytes actually read is
     * returned as an integer.
     *
     * If b is null, a NullPointerException is thrown.
     *
     * If the length of b is zero, then no bytes are read and 0 is returned;
     * otherwise, there is an attempt to read at least one byte. If no byte is
     * available in the save buffer or channel buffer,
     * IllegalBlockingModeException will be thrown; otherwise, at least one
     * byte is read and stored into b.
     *
     * The first byte read is stored into element b[0], the next one into
     * b[o1], and so on. The number of bytes read is, at most, equal to the
     * length of b. Let k be the number of bytes actually read; these bytes
     * will be stored in elements b[0] through b[k-1], leaving elements b[k]
     * through b[b.length-1] unaffected.
     *
     * @return the total number of bytes read into the buffer.
     * @throws IllegalBlockingModeException if there are more bytes available.
     */
    @Override
    public int read(byte[] b)
    {
      return read(b, 0, b.length);
    }
    /**
     * Reads up to len bytes of data from the save buffer or channel buffer
     * into an array of bytes. An attempt is made to read as many as len bytes,
     * but a smaller number may be read. The number of bytes actually read is
     * returned as an integer.
     *
     * If b is null, a NullPointerException is thrown.
     *
     * If off is negative, or len is negative, or off+len is greater than the
     * length of the array b, then an IndexOutOfBoundsException is thrown.
     *
     * If len is zero, then no bytes are read and 0 is returned; otherwise,
     * there is an attempt to read at least one byte. If no byte is available
     * in the save buffer or channel buffer, IllegalBlockingModeException will
     * be thrown; otherwise, at least one byte is read and stored into b.
     *
     * The first byte read is stored into element b[off], the next one into
     * b[off+1], and so on. The number of bytes read is, at most, equal to len.
     * Let k be the number of bytes actually read; these bytes will be stored
     * in elements b[off] through b[off+k-1], leaving elements b[off+k]
     * through b[off+len-1] unaffected.
     *
     * In every case, elements b[0] through b[off] and elements b[off+len]
     * through b[b.length-1] are unaffected.
     *
     * @return the total number of bytes read into the buffer.
     * @throws IllegalBlockingModeException if there are more bytes available.
     */
    @Override
    public int read(byte[] b, int off, int len)
    {
      if ((off < 0) || (len < 0) || (off + len > b.length))
      {
        throw new IndexOutOfBoundsException();
      }
      if(len == 0)
      {
        return 0;
      }
      int bytesCopied=0;
      int getLen;
      if(saveBufferReader.remaining() > 0)
      {
        // Copy out of the last saved buffer first
        getLen = Math.min(saveBufferReader.remaining(), len);
        saveBufferReader.get(b, off, getLen);
        bytesCopied += getLen;
      }
      if(bytesCopied < len && byteBuffer.remaining() > 0)
      {
        // Copy out of the channel buffer if we haven't got
        // everything we needed.
        getLen = Math.min(byteBuffer.remaining(), len - bytesCopied);
        byteBuffer.get(b, off + bytesCopied, getLen);
        bytesCopied += getLen;
      }
      if(bytesCopied < len)
      {
        throw new IllegalBlockingModeException();
      }
      return bytesCopied;
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public long skip(long length)
    {
      int bytesSkipped=0;
      int len;
      if(saveBufferReader.remaining() > 0)
      {
        // Skip in the last saved buffer first
        len = Math.min(saveBufferReader.remaining(), (int)length);
        saveBufferReader.position(saveBufferReader.position() + len);
        bytesSkipped += len;
      }
      if(bytesSkipped < length && byteBuffer.remaining() > 0)
      {
        //Skip in the channel buffer if we haven't skipped enough.
        len = Math.min(byteBuffer.remaining(), (int)length - bytesSkipped);
        byteBuffer.position(byteBuffer.position() + len);
        bytesSkipped += len;
      }
      if(bytesSkipped < length)
      {
        throw new IllegalBlockingModeException();
      }
      return bytesSkipped;
    }
  }
  /**
   * Creates a new ASN.1 byte channel reader whose source is the
   * provided readable byte channel, having a user defined buffer
   * size, and user defined maximum BER element size.
   *
   * @param channel
   *          The readable byte channel to use.
   * @param bufferSize
   *          The buffer size to use when reading from the channel.
   * @param maxElementSize
   *          The max ASN.1 element size this reader will read.
   */
  ASN1ByteChannelReader(ReadableByteChannel channel, int bufferSize,
      int maxElementSize)
  {
    this.byteChannel = channel;
    this.byteBuffer = ByteBuffer.allocate(bufferSize);
    this.byteBuffer.flip();
    this.saveBuffer = new ByteStringBuilder();
    this.saveBufferReader = saveBuffer.asReader();
    CombinedBufferInputStream bufferStream = new CombinedBufferInputStream();
    this.reader = ASN1.getReader(bufferStream, maxElementSize);
  }
  /**
   * Process any new data on the channel so they can be read as ASN.1
   * elements. This method should only be called when there are no
   * more complete elements in the reader. Calling this method when
   * there are complete elements still in the reader will result in
   * unnecessary memory allocations to store any unread data. This
   * method will perform the following operations:
   * <ul>
   * <li>Clear the save buffer if everything was read.
   * <li>Append any unread data from the NIO byte buffer to the save
   * buffer.
   * <li>Clear the NIO byte buffer and read from the channel.
   * </ul>
   *
   * @return The number of bytes read from the channel or -1 if
   *         channel is closed.
   * @throws IOException
   *           If an exception occurs while reading from the channel.
   */
  public int processChannelData() throws IOException
  {
    // Clear the save buffer if we have read all of it
    if (saveBufferReader.remaining() == 0)
    {
      saveBuffer.clear();
      saveBufferReader.rewind();
    }
    // Append any unused data in the channel buffer to the save buffer
    if (byteBuffer.remaining() > 0)
    {
      saveBuffer.append(byteBuffer, byteBuffer.remaining());
    }
    byteBuffer.clear();
    try
    {
      int read = byteChannel.read(byteBuffer);
      return read;
    }
    finally
    {
      // Make sure that the buffer is flipped even if the read fails in order to
      // ensure that subsequent calls which query the remaining data return
      // valid results.
      byteBuffer.flip();
    }
  }
  /**
   * Determines if a complete ASN.1 element is ready to be read from
   * channel.
   *
   * @return <code>true</code> if another complete element is available or
   *         <code>false</code> otherwise.
   * @throws IOException If an error occurs while trying to decode
   *                       an ASN1 element.
   */
  @Override
  public boolean elementAvailable() throws IOException
  {
    return reader.elementAvailable();
  }
  /**
   * Determines if the channel contains at least one ASN.1 element to be read.
   *
   * @return <code>true</code> if another element is available or
   *         <code>false</code> otherwise.
   * @throws IOException If an error occurs while trying to decode
   *                       an ASN1 element.
   */
  @Override
  public boolean hasNextElement() throws IOException {
    return reader.hasNextElement();
  }
  /**
   * Returns {@code true} if this ASN.1 reader contains unread data.
   *
   * @return {@code true} if this ASN.1 reader contains unread data.
   */
  public boolean hasRemainingData()
  {
    return (saveBufferReader.remaining() != 0) || (byteBuffer.remaining() != 0);
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public int peekLength() throws IOException {
    return reader.peekLength();
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public byte peekType() throws IOException {
    return reader.peekType();
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public boolean readBoolean() throws IOException {
    return reader.readBoolean();
  }
  /** {@inheritDoc} */
  @Override
  public boolean readBoolean(byte type) throws IOException {
    return reader.readBoolean(type);
  }
  /**
   * {@inheritDoc}
   */
  public void readEndExplicitTag() throws IOException {
//    reader.readEndExplicitTag(); // TODO
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public void readEndSequence() throws IOException {
    reader.readEndSequence();
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public void readEndSet() throws IOException {
    reader.readEndSet();
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public int readEnumerated() throws IOException {
    return reader.readEnumerated();
  }
  /** {@inheritDoc} */
  @Override
  public int readEnumerated(byte type) throws IOException {
    return reader.readEnumerated(type);
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public long readInteger() throws IOException {
    return reader.readInteger();
  }
  /** {@inheritDoc} */
  @Override
  public long readInteger(byte type) throws IOException {
    return reader.readInteger(type);
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public void readNull() throws IOException {
    reader.readNull();
  }
  /** {@inheritDoc} */
  @Override
  public void readNull(byte type) throws IOException {
    reader.readNull(type);
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public ByteString readOctetString() throws IOException {
    return reader.readOctetString();
  }
  /** {@inheritDoc} */
  @Override
  public ByteString readOctetString(byte type) throws IOException {
    return readOctetString(type);
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public ByteStringBuilder readOctetString(ByteStringBuilder buffer) throws IOException {
    return reader.readOctetString(buffer);
  }
  /** {@inheritDoc} */
  @Override
  public ByteStringBuilder readOctetString(byte type, ByteStringBuilder builder) throws IOException {
    return readOctetString(type, builder);
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public String readOctetStringAsString() throws IOException {
    return reader.readOctetStringAsString();
  }
  /** {@inheritDoc} */
  @Override
  public String readOctetStringAsString(byte type) throws IOException {
    return readOctetStringAsString(type);
  }
  /**
   * {@inheritDoc}
   */
  public void readStartExplicitTag() throws IOException {
//    reader.readStartExplicitTag();// TODO
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public void readStartSequence() throws IOException {
    reader.readStartSequence();
  }
  /** {@inheritDoc} */
  @Override
  public void readStartSequence(byte type) throws IOException {
    reader.readStartSequence(type);
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public void readStartSet() throws IOException {
    reader.readStartSet();
  }
  /** {@inheritDoc} */
  @Override
  public void readStartSet(byte type) throws IOException {
    reader.readStartSet(type);
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public void close() throws IOException {
    reader.close();
    byteChannel.close();
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public ASN1Reader skipElement() throws IOException {
    reader.skipElement();
    return this;
  }
}
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/AbandonRequestProtocolOp.java
@@ -28,7 +28,7 @@
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/AddRequestProtocolOp.java
@@ -32,7 +32,7 @@
import java.util.List;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.RawAttribute;
import org.opends.server.util.Base64;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/AddResponseProtocolOp.java
@@ -32,7 +32,7 @@
import java.util.List;
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.DN;
import org.forgerock.i18n.slf4j.LocalizedLogger;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/BindRequestProtocolOp.java
@@ -29,7 +29,7 @@
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.AuthenticationType;
import org.forgerock.opendj.ldap.ByteString;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/BindResponseProtocolOp.java
@@ -32,7 +32,7 @@
import java.util.List;
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.DN;
import org.forgerock.opendj.ldap.ByteString;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/CompareRequestProtocolOp.java
@@ -29,7 +29,7 @@
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.i18n.slf4j.LocalizedLogger;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/CompareResponseProtocolOp.java
@@ -32,7 +32,7 @@
import java.util.List;
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.DN;
import org.forgerock.i18n.slf4j.LocalizedLogger;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/DeleteRequestProtocolOp.java
@@ -28,7 +28,7 @@
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.i18n.slf4j.LocalizedLogger;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/DeleteResponseProtocolOp.java
@@ -32,7 +32,7 @@
import java.util.List;
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.DN;
import org.forgerock.i18n.slf4j.LocalizedLogger;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/ExtendedRequestProtocolOp.java
@@ -29,7 +29,7 @@
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.i18n.slf4j.LocalizedLogger;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/ExtendedResponseProtocolOp.java
@@ -32,7 +32,7 @@
import java.util.List;
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.DN;
import org.forgerock.opendj.ldap.ByteString;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/IntermediateResponseProtocolOp.java
@@ -29,7 +29,7 @@
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.i18n.slf4j.LocalizedLogger;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/LDAPClientConnection.java
@@ -28,14 +28,7 @@
import static org.opends.messages.CoreMessages.*;
import static org.opends.messages.ProtocolMessages.*;
import static org.opends.server.core.DirectoryServer.*;
import static org.opends.server.loggers.AccessLogger.*;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetAddress;
import java.nio.ByteBuffer;
@@ -54,6 +47,11 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.api.ClientConnection;
import org.opends.server.api.ConnectionHandler;
import org.opends.server.core.*;
@@ -62,16 +60,18 @@
import org.opends.server.extensions.RedirectingByteChannel;
import org.opends.server.extensions.TLSByteChannel;
import org.opends.server.extensions.TLSCapableConnection;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1ByteChannelReader;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.util.StaticUtils;
import org.opends.server.util.TimeThread;
import static org.opends.messages.CoreMessages.*;
import static org.opends.messages.ProtocolMessages.*;
import static org.opends.server.core.DirectoryServer.*;
import static org.opends.server.loggers.AccessLogger.*;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
/**
 * This class defines an LDAP client connection, which is a type of
@@ -90,13 +90,13 @@
  private static final class ConnectionFinalizerJob implements Runnable
  {
    /** The client connection ASN1 reader. */
    private final ASN1Reader asn1Reader;
    private final ASN1ByteChannelReader asn1Reader;
    /** The client connection socket channel. */
    private final SocketChannel socketChannel;
    /** Creates a new connection finalizer job. */
    private ConnectionFinalizerJob(ASN1Reader asn1Reader,
    private ConnectionFinalizerJob(ASN1ByteChannelReader asn1Reader,
        SocketChannel socketChannel)
    {
      this.asn1Reader = asn1Reader;
@@ -308,7 +308,7 @@
  /**
   * Thread local ASN1Writer and buffer.
   */
  private static final class ASN1WriterHolder
  private static final class ASN1WriterHolder implements Closeable
  {
    private final ASN1Writer writer;
    private final ByteStringBuilder buffer;
@@ -320,6 +320,14 @@
      this.maxBufferSize = getMaxInternalBufferSize();
      this.writer = ASN1.getWriter(buffer, maxBufferSize);
    }
    /** {@inheritDoc} */
    @Override
    public void close() throws IOException
    {
      StaticUtils.close(writer);
      buffer.clearAndTruncate(maxBufferSize, maxBufferSize);
    }
  }
  /**
@@ -503,9 +511,7 @@
            timeoutClientChannel);
    saslChannel =
        RedirectingByteChannel.getRedirectingByteChannel(tlsChannel);
    this.asn1Reader =
        ASN1.getReader(saslChannel, bufferSize, connectionHandler
            .getMaxRequestSize());
    this.asn1Reader = new ASN1ByteChannelReader(saslChannel, bufferSize, connectionHandler.getMaxRequestSize());
    if (connectionHandler.useSSL())
    {
@@ -1004,7 +1010,7 @@
      // Clear and reset all of the internal buffers ready for the next usage.
      // The ASN1Writer is based on a ByteStringBuilder so closing will cause
      // the internal buffers to be resized if needed.
      close(holder.writer);
      close(holder);
    }
 }
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/LDAPControl.java
@@ -29,7 +29,7 @@
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.Control;
import org.forgerock.opendj.ldap.ByteString;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/LDAPMessage.java
@@ -33,7 +33,7 @@
import java.io.IOException;
import org.opends.server.api.ProtocolElement;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.Control;
import static org.opends.server.protocols.ldap.LDAPConstants.
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/LDAPReader.java
@@ -26,22 +26,20 @@
 */
package org.opends.server.protocols.ldap;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import static org.opends.messages.ProtocolMessages.*;
import static org.opends.server.protocols.asn1.ASN1Constants.*;
import static org.opends.server.protocols.ldap.LDAPResultCode.*;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.LinkedList;
/**
 * Utility class used to decode LDAP messages from an ASN1Reader.
 */
@@ -742,9 +740,9 @@
        }
      }
    }
    catch(ASN1Exception asn1e)
    catch(IOException e)
    {
      logger.traceException(asn1e);
      logger.traceException(e);
    }
    try
@@ -1348,9 +1346,9 @@
        }
      }
    }
    catch(ASN1Exception asn1e)
    catch(IOException e)
    {
      logger.traceException(asn1e);
      logger.traceException(e);
    }
    try
@@ -1440,9 +1438,9 @@
        }
      }
    }
    catch(ASN1Exception asn1e)
    catch(IOException e)
    {
      logger.traceException(asn1e);
      logger.traceException(e);
    }
    try
@@ -2452,7 +2450,7 @@
    try
    {
      if(reader.hasNextElement() &&
          reader.peekType() == UNIVERSAL_BOOLEAN_TYPE)
          reader.peekType() == ASN1.UNIVERSAL_BOOLEAN_TYPE)
      {
        try
        {
@@ -2467,7 +2465,7 @@
        }
      }
      if(reader.hasNextElement() &&
          reader.peekType() == UNIVERSAL_OCTET_STRING_TYPE)
          reader.peekType() == ASN1.UNIVERSAL_OCTET_STRING_TYPE)
      {
        try
        {
@@ -2482,9 +2480,9 @@
        }
      }
    }
    catch(ASN1Exception asn1e)
    catch(IOException e)
    {
      logger.traceException(asn1e);
      logger.traceException(e);
    }
    try
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/LDAPRequestHandler.java
@@ -48,8 +48,8 @@
import org.opends.server.api.ServerShutdownListener;
import org.opends.server.core.DirectoryServer;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1ByteChannelReader;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.types.DisconnectReason;
import org.opends.server.types.InitializationException;
import org.opends.server.types.LDAPException;
@@ -172,7 +172,7 @@
      {
        try
        {
          ASN1ByteChannelReader asn1Reader = readyConnection.getASN1Reader();
          ASN1Reader asn1Reader = readyConnection.getASN1Reader();
          boolean ldapMessageProcessed = false;
          while (true)
          {
@@ -205,7 +205,7 @@
            }
          }
        }
        catch (ASN1Exception e)
        catch (DecodeException e)
        {
          logger.traceException(e);
          readyConnection.disconnect(DisconnectReason.PROTOCOL_ERROR, true,
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/ModifyDNRequestProtocolOp.java
@@ -29,7 +29,7 @@
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.i18n.slf4j.LocalizedLogger;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/ModifyDNResponseProtocolOp.java
@@ -32,7 +32,7 @@
import java.util.List;
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.DN;
import org.forgerock.i18n.slf4j.LocalizedLogger;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/ModifyRequestProtocolOp.java
@@ -32,7 +32,7 @@
import java.util.List;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.RawModification;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/ModifyResponseProtocolOp.java
@@ -32,7 +32,7 @@
import java.util.List;
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.DN;
import org.forgerock.i18n.slf4j.LocalizedLogger;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/ProtocolOp.java
@@ -22,10 +22,11 @@
 *
 *
 *      Copyright 2006-2008 Sun Microsystems, Inc.
 *      Portions Copyright 2014 ForgeRock AS
 */
package org.opends.server.protocols.ldap;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import java.io.IOException;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/SearchRequestProtocolOp.java
@@ -32,7 +32,7 @@
import java.util.Set;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.DereferencePolicy;
import org.opends.server.types.RawFilter;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/SearchResultDoneProtocolOp.java
@@ -32,7 +32,7 @@
import java.util.List;
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.DN;
import org.forgerock.i18n.slf4j.LocalizedLogger;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/SearchResultEntryProtocolOp.java
@@ -41,7 +41,7 @@
import java.util.Map;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeBuilder;
import org.opends.server.types.AttributeType;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/SearchResultReferenceProtocolOp.java
@@ -32,7 +32,7 @@
import java.util.Iterator;
import java.io.IOException;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.SearchResultReference;
import org.forgerock.i18n.slf4j.LocalizedLogger;
opendj3-server-dev/src/server/org/opends/server/protocols/ldap/UnbindRequestProtocolOp.java
@@ -28,7 +28,7 @@
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
opendj3-server-dev/src/server/org/opends/server/replication/common/ServerState.java
@@ -34,7 +34,7 @@
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.zip.DataFormatException;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.replication.protocol.ProtocolVersion;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.util.Utils;
opendj3-server-dev/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
@@ -40,6 +40,7 @@
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.admin.server.ConfigurationChangeListener;
import org.opends.server.admin.std.meta.ReplicationDomainCfgDefn.IsolationPolicy;
import org.opends.server.admin.std.server.ExternalChangelogDomainCfg;
@@ -51,7 +52,6 @@
import org.opends.server.backends.task.Task;
import org.opends.server.config.ConfigException;
import org.opends.server.core.*;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchListener;
import org.opends.server.protocols.internal.InternalSearchOperation;
@@ -2435,7 +2435,7 @@
          replayErrorMsg = message.toString();
          updateError(csn);
        }
      } catch (ASN1Exception e)
      } catch (DecodeException e)
      {
        replayErrorMsg = logDecodingOperationError(msg, e);
      } catch (LDAPException e)
@@ -3133,10 +3133,10 @@
   *
   * @param msg            The conflicting Add Operation.
   *
   * @throws ASN1Exception When an encoding error happened manipulating the
   * @throws DecodeException When an encoding error happened manipulating the
   *                       msg.
   */
  private void addConflict(AddMsg msg) throws ASN1Exception
  private void addConflict(AddMsg msg) throws DecodeException
  {
    String normalizedDN = msg.getDN().toNormalizedString();
opendj3-server-dev/src/server/org/opends/server/replication/plugin/ReplicationRepairRequestControl.java
@@ -31,7 +31,7 @@
import org.opends.server.types.Control;
import org.opends.server.types.DirectoryException;
import org.opends.server.controls.ControlDecoder;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import java.io.IOException;
opendj3-server-dev/src/server/org/opends/server/replication/protocol/AddMsg.java
@@ -35,9 +35,9 @@
import org.opends.server.core.AddOperation;
import org.opends.server.core.AddOperationBasis;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.ldap.DecodeException;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.ldap.LDAPAttribute;
import org.opends.server.replication.common.CSN;
@@ -174,7 +174,7 @@
  @Override
  public AddOperation createOperation(
      InternalClientConnection connection, DN newDN)
  throws LDAPException, ASN1Exception
  throws LDAPException, DecodeException
  {
    List<RawAttribute> attr = decodeRawAttributes(encodedAttributes);
@@ -520,10 +520,9 @@
   *
   * @param name  The name of the attribute to add.
   * @param value The value of the attribute to add.
   * @throws ASN1Exception When this Msg is not valid.
   * @throws DecodeException When this Msg is not valid.
   */
  public void addAttribute(String name, String value)
         throws ASN1Exception
  public void addAttribute(String name, String value) throws DecodeException
  {
    ByteStringBuilder byteBuilder = new ByteStringBuilder();
    byteBuilder.append(encodedAttributes);
@@ -545,10 +544,10 @@
  /**
   * Get the attributes of this add msg.
   * @throws LDAPException In case of LDAP decoding exception
   * @throws ASN1Exception In case of ASN1 decoding exception
   * @throws DecodeException In case of ASN1 decoding exception
   * @return the list of attributes
   */
  public List<Attribute> getAttributes() throws LDAPException, ASN1Exception
  public List<Attribute> getAttributes() throws LDAPException, DecodeException
  {
    return decodeAttributes(encodedAttributes);
  }
opendj3-server-dev/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java
@@ -26,15 +26,16 @@
 */
package org.opends.server.replication.protocol;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.zip.DataFormatException;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.ldap.DecodeException;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.ldap.LDAPAttribute;
import org.opends.server.replication.common.AssuredMode;
@@ -178,11 +179,11 @@
   * @param   conn connection to use when creating the message
   * @return  the created Operation
   * @throws  LDAPException In case of LDAP decoding exception.
   * @throws  ASN1Exception In case of ASN1 decoding exception.
   * @throws  IOException In case of ASN1 decoding exception.
   * @throws DataFormatException In case of bad msg format.
   */
  public Operation createOperation(InternalClientConnection conn)
      throws LDAPException, ASN1Exception, DataFormatException
      throws LDAPException, IOException, DataFormatException
  {
    return createOperation(conn, dn);
  }
@@ -195,11 +196,11 @@
   * @param   newDN the DN to use when creating the operation.
   * @return  the created Operation.
   * @throws  LDAPException In case of LDAP decoding exception.
   * @throws  ASN1Exception In case of ASN1 decoding exception.
   * @throws  IOException In case of ASN1 decoding exception.
   * @throws DataFormatException In case of bad msg format.
   */
  public abstract Operation createOperation(InternalClientConnection conn,
      DN newDN) throws LDAPException, ASN1Exception, DataFormatException;
      DN newDN) throws LDAPException, IOException, DataFormatException;
  // ============
@@ -614,10 +615,10 @@
   * @param in The provided byte array.
   * @return The list of RawAttribute objects.
   * @throws LDAPException when it occurs.
   * @throws ASN1Exception when it occurs.
   * @throws DecodeException when it occurs.
   */
  public ArrayList<RawAttribute> decodeRawAttributes(byte[] in)
  throws LDAPException, ASN1Exception
  throws LDAPException, DecodeException
  {
    ArrayList<RawAttribute> rattr = new ArrayList<RawAttribute>();
    try
@@ -643,10 +644,10 @@
   * @param in The provided byte array.
   * @return The list of Attribute objects.
   * @throws LDAPException when it occurs.
   * @throws ASN1Exception when it occurs.
   * @throws DecodeException when it occurs.
   */
  public ArrayList<Attribute> decodeAttributes(byte[] in)
  throws LDAPException, ASN1Exception
  throws LDAPException, DecodeException
  {
    ArrayList<Attribute> lattr = new ArrayList<Attribute>();
    try
opendj3-server-dev/src/server/org/opends/server/replication/protocol/ModifyCommonMsg.java
@@ -26,19 +26,19 @@
 */
package org.opends.server.replication.protocol;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.protocols.ldap.LDAPAttribute;
import org.opends.server.protocols.ldap.LDAPModification;
import org.opends.server.replication.common.CSN;
import org.opends.server.replication.plugin.EntryHistorical;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteStringBuilder;
/**
 * This class holds every common code for the modify messages (mod, moddn).
@@ -99,10 +99,10 @@
  /**
   * Get the Modifications associated to the UpdateMsg to the provided value.
   * @throws LDAPException In case of LDAP decoding exception
   * @throws ASN1Exception In case of ASN1 decoding exception
   * @throws IOException In case of ASN1 decoding exception
   * @return the list of modifications
   */
  public List<Modification> getMods() throws ASN1Exception, LDAPException
  public List<Modification> getMods() throws IOException, LDAPException
  {
    return decodeMods(encodedMods);
  }
@@ -164,11 +164,11 @@
  /**
   * Decode mods from the provided byte array.
   * @param in The provided byte array.
   * @throws ASN1Exception when occurs.
   * @throws IOException when occurs.
   * @throws LDAPException when occurs.
   * @return The decoded mods.
   */
  protected List<Modification> decodeMods(byte[] in) throws ASN1Exception,
  protected List<Modification> decodeMods(byte[] in) throws IOException,
      LDAPException
  {
    List<Modification> mods = new ArrayList<Modification>();
@@ -184,11 +184,11 @@
   * Decode raw mods from the provided byte array.
   * @param in The provided byte array.
   * @return The decoded mods.
   * @throws ASN1Exception when occurs.
   * @throws IOException when occurs.
   * @throws LDAPException when occurs.
   */
  protected List<RawModification> decodeRawMods(byte[] in)
      throws LDAPException, ASN1Exception
      throws LDAPException, IOException
  {
    List<RawModification> ldapmods = new ArrayList<RawModification>();
    ASN1Reader asn1Reader = ASN1.getReader(in);
opendj3-server-dev/src/server/org/opends/server/replication/protocol/ModifyDNMsg.java
@@ -26,13 +26,13 @@
 */
package org.opends.server.replication.protocol;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.zip.DataFormatException;
import org.opends.server.core.ModifyDNOperation;
import org.opends.server.core.ModifyDNOperationBasis;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.replication.common.CSN;
import org.opends.server.types.*;
@@ -160,7 +160,7 @@
   */
  @Override
  public ModifyDNOperation createOperation(InternalClientConnection connection,
      DN newDN) throws LDAPException, ASN1Exception
      DN newDN) throws LDAPException, IOException
  {
    ModifyDNOperation moddn =  new ModifyDNOperationBasis(connection,
        InternalClientConnection.nextOperationID(),
opendj3-server-dev/src/server/org/opends/server/replication/protocol/ModifyMsg.java
@@ -26,13 +26,13 @@
 */
package org.opends.server.replication.protocol;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.zip.DataFormatException;
import org.opends.server.core.ModifyOperation;
import org.opends.server.core.ModifyOperationBasis;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.replication.common.CSN;
import org.opends.server.types.*;
@@ -127,7 +127,7 @@
   */
  @Override
  public ModifyOperation createOperation(InternalClientConnection connection,
      DN newDN) throws LDAPException, ASN1Exception, DataFormatException
      DN newDN) throws LDAPException, IOException, DataFormatException
  {
    if (newDN == null)
      newDN = getDN();
opendj3-server-dev/src/server/org/opends/server/replication/protocol/MonitorMsg.java
@@ -34,9 +34,9 @@
import java.util.Map.Entry;
import java.util.zip.DataFormatException;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.replication.common.CSN;
import org.opends.server.replication.common.ServerState;
import org.forgerock.opendj.ldap.ByteSequenceReader;
opendj3-server-dev/src/server/org/opends/server/replication/protocol/StartSessionMsg.java
@@ -32,9 +32,9 @@
import java.util.*;
import java.util.zip.DataFormatException;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.replication.common.AssuredMode;
import org.opends.server.replication.common.ServerStatus;
import org.forgerock.opendj.ldap.ByteSequenceReader;
opendj3-server-dev/src/server/org/opends/server/schema/CertificateSyntax.java
@@ -29,6 +29,7 @@
import java.io.IOException;
import java.util.List;
import org.forgerock.i18n.slf4j.LocalizedLogger;
@@ -45,16 +46,15 @@
import org.opends.server.types.ConfigChangeResult;
import org.opends.server.types.ResultCode;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.ldap.DecodeException;
import org.forgerock.opendj.io.ASN1Reader;
import static org.opends.messages.SchemaMessages.*;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import static org.opends.server.schema.SchemaConstants.*;
import static org.opends.server.protocols.asn1.ASN1Constants.*;
/**
@@ -282,7 +282,7 @@
    {
      // Certificate SIGNED SEQUENCE
      if (!reader.hasNextElement() ||
          reader.peekType() != UNIVERSAL_SEQUENCE_TYPE)
          reader.peekType() != ASN1.UNIVERSAL_SEQUENCE_TYPE)
      {
        invalidReason.append(ERR_SYNTAX_CERTIFICATE_NOTVALID.get());
        return false;
@@ -291,7 +291,7 @@
      // CertificateContent SEQUENCE
      if (!reader.hasNextElement() ||
          reader.peekType() != UNIVERSAL_SEQUENCE_TYPE)
          reader.peekType() != ASN1.UNIVERSAL_SEQUENCE_TYPE)
      {
        invalidReason.append(ERR_SYNTAX_CERTIFICATE_NOTVALID.get());
        return false;
@@ -300,11 +300,11 @@
      // Optional Version
      if (reader.hasNextElement() &&
          reader.peekType() == (TYPE_MASK_CONTEXT | TYPE_MASK_CONSTRUCTED))
          reader.peekType() == (ASN1.TYPE_MASK_CONTEXT | ASN1.TYPE_MASK_CONSTRUCTED))
      {
        reader.readStartExplicitTag();
        if (!reader.hasNextElement() ||
            reader.peekType() != UNIVERSAL_INTEGER_TYPE)
            reader.peekType() != ASN1.UNIVERSAL_INTEGER_TYPE)
        {
          invalidReason.append(ERR_SYNTAX_CERTIFICATE_NOTVALID.get());
          return false;
@@ -329,7 +329,7 @@
      // serialNumber
      if (!reader.hasNextElement() ||
          reader.peekType() != UNIVERSAL_INTEGER_TYPE)
          reader.peekType() != ASN1.UNIVERSAL_INTEGER_TYPE)
      {
        invalidReason.append(ERR_SYNTAX_CERTIFICATE_NOTVALID.get());
        return false;
@@ -338,7 +338,7 @@
      // signature AlgorithmIdentifier
      if (!reader.hasNextElement() ||
          reader.peekType() != UNIVERSAL_SEQUENCE_TYPE)
          reader.peekType() != ASN1.UNIVERSAL_SEQUENCE_TYPE)
      {
        invalidReason.append(ERR_SYNTAX_CERTIFICATE_NOTVALID.get());
        return false;
@@ -347,7 +347,7 @@
      // issuer name (SEQUENCE as of X.501, 9.2)
      if (!reader.hasNextElement() ||
          reader.peekType() != UNIVERSAL_SEQUENCE_TYPE)
          reader.peekType() != ASN1.UNIVERSAL_SEQUENCE_TYPE)
      {
        invalidReason.append(ERR_SYNTAX_CERTIFICATE_NOTVALID.get());
        return false;
@@ -356,7 +356,7 @@
      // validity (SEQUENCE)
      if (!reader.hasNextElement() ||
          reader.peekType() != UNIVERSAL_SEQUENCE_TYPE)
          reader.peekType() != ASN1.UNIVERSAL_SEQUENCE_TYPE)
      {
        invalidReason.append(ERR_SYNTAX_CERTIFICATE_NOTVALID.get());
        return false;
@@ -365,7 +365,7 @@
      // subject name (SEQUENCE as of X.501, 9.2)
      if (!reader.hasNextElement() ||
          reader.peekType() != UNIVERSAL_SEQUENCE_TYPE)
          reader.peekType() != ASN1.UNIVERSAL_SEQUENCE_TYPE)
      {
        invalidReason.append(ERR_SYNTAX_CERTIFICATE_NOTVALID.get());
        return false;
@@ -374,7 +374,7 @@
      // SubjectPublicKeyInfo (SEQUENCE)
      if (!reader.hasNextElement() ||
          reader.peekType() != UNIVERSAL_SEQUENCE_TYPE)
          reader.peekType() != ASN1.UNIVERSAL_SEQUENCE_TYPE)
      {
        invalidReason.append(ERR_SYNTAX_CERTIFICATE_NOTVALID.get());
        return false;
@@ -383,7 +383,7 @@
      // OPTIONAL issuerUniqueIdentifier
      if (reader.hasNextElement() &&
          reader.peekType() == (TYPE_MASK_CONTEXT + 1))
          reader.peekType() == (ASN1.TYPE_MASK_CONTEXT + 1))
      {
        if (x509Version < 1)
        {
@@ -396,7 +396,7 @@
      // OPTIONAL subjectUniqueIdentifier
      if (reader.hasNextElement() &&
          reader.peekType() == (TYPE_MASK_CONTEXT + 2))
          reader.peekType() == (ASN1.TYPE_MASK_CONTEXT + 2))
      {
        if (x509Version < 1)
        {
@@ -409,7 +409,7 @@
      // OPTIONAL extensions
      if (reader.hasNextElement() &&
          reader.peekType() == ((TYPE_MASK_CONTEXT|TYPE_MASK_CONSTRUCTED) + 3))
          reader.peekType() == ((ASN1.TYPE_MASK_CONTEXT|ASN1.TYPE_MASK_CONSTRUCTED) + 3))
      {
        if (x509Version < 2)
        {
@@ -419,7 +419,7 @@
        }
        reader.readStartExplicitTag(); // read Tag
        if (!reader.hasNextElement() ||
            reader.peekType() != UNIVERSAL_SEQUENCE_TYPE)
            reader.peekType() != ASN1.UNIVERSAL_SEQUENCE_TYPE)
        {
          // only valid in v3
          invalidReason.append(ERR_SYNTAX_CERTIFICATE_NOTVALID.get());
@@ -438,7 +438,7 @@
      // AlgorithmIdentifier SEQUENCE
      if (!reader.hasNextElement() ||
          reader.peekType() != UNIVERSAL_SEQUENCE_TYPE)
          reader.peekType() != ASN1.UNIVERSAL_SEQUENCE_TYPE)
      {
        invalidReason.append(ERR_SYNTAX_CERTIFICATE_NOTVALID.get());
        return false;
@@ -447,7 +447,7 @@
      // ENCRYPTED HASH BIT STRING
      if (!reader.hasNextElement() ||
          reader.peekType() != UNIVERSAL_BIT_STRING_TYPE)
          reader.peekType() != ASN1.UNIVERSAL_BIT_STRING_TYPE)
      {
        invalidReason.append(ERR_SYNTAX_CERTIFICATE_NOTVALID.get());
        return false;
@@ -470,12 +470,16 @@
      }
      // End of the certificate
    }
    catch (ASN1Exception e)
    catch (DecodeException e)
    {
      System.out.println(e.getMessageObject());
      invalidReason.append(e.getMessageObject());
      return false;
    }
    catch (IOException e)
    {
      invalidReason.append(e.getMessage());
      return false;
    }
    // The basic structure of the value is an X.509 certificate
    return true;
opendj3-server-dev/src/server/org/opends/server/tools/LDAPAuthenticationHandler.java
@@ -25,9 +25,6 @@
 *      Portions Copyright 2012-2014 ForgeRock AS
 */
package org.opends.server.tools;
import org.forgerock.i18n.LocalizableMessage;
import java.io.BufferedWriter;
import java.io.File;
@@ -56,7 +53,10 @@
import javax.security.sasl.Sasl;
import javax.security.sasl.SaslClient;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.ldap.BindRequestProtocolOp;
import org.opends.server.protocols.ldap.BindResponseProtocolOp;
import org.opends.server.protocols.ldap.ExtendedRequestProtocolOp;
@@ -65,13 +65,10 @@
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.opends.server.types.LDAPException;
import org.opends.server.types.Control;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteSequence;
import org.opends.server.util.Base64;
import org.opends.server.util.PasswordReader;
import static org.opends.messages.ToolMessages.*;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
import static org.opends.server.tools.ToolConstants.*;
import static org.opends.server.util.ServerConstants.*;
@@ -337,6 +334,13 @@
                                  message);
      }
    }
    catch (DecodeException ae)
    {
      LocalizableMessage message =
          ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE.get(getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
          message, ae);
    }
    catch (IOException ioe)
    {
      LocalizableMessage message =
@@ -344,13 +348,6 @@
      throw new ClientException(
              LDAPResultCode.CLIENT_SIDE_SERVER_DOWN, message, ioe);
    }
    catch (ASN1Exception ae)
    {
      LocalizableMessage message =
          ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE.get(getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
                                message, ae);
    }
    catch (LDAPException le)
    {
      LocalizableMessage message =
@@ -648,6 +645,13 @@
                                  message);
      }
    }
    catch (DecodeException ae)
    {
      LocalizableMessage message =
          ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE.get(getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
          message, ae);
    }
    catch (IOException ioe)
    {
      LocalizableMessage message =
@@ -655,13 +659,6 @@
      throw new ClientException(
              LDAPResultCode.CLIENT_SIDE_SERVER_DOWN, message, ioe);
    }
    catch (ASN1Exception ae)
    {
      LocalizableMessage message =
          ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE.get(getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
                                message, ae);
    }
    catch (LDAPException le)
    {
      LocalizableMessage message =
@@ -900,6 +897,14 @@
                                  message);
      }
    }
    catch (DecodeException ae)
    {
      LocalizableMessage message =
          ERR_LDAPAUTH_CANNOT_READ_INITIAL_BIND_RESPONSE.get(
              SASL_MECHANISM_CRAM_MD5, getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
          message, ae);
    }
    catch (IOException ioe)
    {
      LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_INITIAL_BIND_RESPONSE.get(
@@ -907,13 +912,6 @@
      throw new ClientException(
              LDAPResultCode.CLIENT_SIDE_SERVER_DOWN, message, ioe);
    }
    catch (ASN1Exception ae)
    {
      LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_INITIAL_BIND_RESPONSE.get(
          SASL_MECHANISM_CRAM_MD5, getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
                                message, ae);
    }
    catch (LDAPException le)
    {
      LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_INITIAL_BIND_RESPONSE.get(
@@ -1043,6 +1041,14 @@
                                  message);
      }
    }
    catch (DecodeException ae)
    {
      LocalizableMessage message =
          ERR_LDAPAUTH_CANNOT_READ_SECOND_BIND_RESPONSE.get(
              SASL_MECHANISM_CRAM_MD5, getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
          message, ae);
    }
    catch (IOException ioe)
    {
      LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_SECOND_BIND_RESPONSE.get(
@@ -1050,13 +1056,6 @@
      throw new ClientException(
              LDAPResultCode.CLIENT_SIDE_SERVER_DOWN, message, ioe);
    }
    catch (ASN1Exception ae)
    {
      LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_SECOND_BIND_RESPONSE.get(
          SASL_MECHANISM_CRAM_MD5, getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
                                message, ae);
    }
    catch (LDAPException le)
    {
      LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_SECOND_BIND_RESPONSE.get(
@@ -1479,6 +1478,14 @@
                                  message);
      }
    }
    catch (DecodeException ae)
    {
      LocalizableMessage message =
          ERR_LDAPAUTH_CANNOT_READ_INITIAL_BIND_RESPONSE.get(
              SASL_MECHANISM_DIGEST_MD5, getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
          message, ae);
    }
    catch (IOException ioe)
    {
      LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_INITIAL_BIND_RESPONSE.get(
@@ -1486,13 +1493,6 @@
      throw new ClientException(
              LDAPResultCode.CLIENT_SIDE_SERVER_DOWN, message, ioe);
    }
    catch (ASN1Exception ae)
    {
      LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_INITIAL_BIND_RESPONSE.get(
          SASL_MECHANISM_DIGEST_MD5, getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
                                message, ae);
    }
    catch (LDAPException le)
    {
      LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_INITIAL_BIND_RESPONSE.get(
@@ -1791,6 +1791,14 @@
                                  message);
      }
    }
    catch (DecodeException ae)
    {
      LocalizableMessage message =
          ERR_LDAPAUTH_CANNOT_READ_SECOND_BIND_RESPONSE.get(
              SASL_MECHANISM_DIGEST_MD5, getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
          message, ae);
    }
    catch (IOException ioe)
    {
      LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_SECOND_BIND_RESPONSE.get(
@@ -1798,13 +1806,6 @@
      throw new ClientException(
              LDAPResultCode.CLIENT_SIDE_SERVER_DOWN, message, ioe);
    }
    catch (ASN1Exception ae)
    {
      LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_SECOND_BIND_RESPONSE.get(
          SASL_MECHANISM_DIGEST_MD5, getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
                                message, ae);
    }
    catch (LDAPException le)
    {
      LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_SECOND_BIND_RESPONSE.get(
@@ -2455,6 +2456,13 @@
                                  message);
      }
    }
    catch (DecodeException e)
    {
      LocalizableMessage message =
          ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE.get(getExceptionMessage(e));
      throw new ClientException(
              LDAPResultCode.CLIENT_SIDE_DECODING_ERROR, message, e);
    }
    catch (IOException ioe)
    {
      LocalizableMessage message =
@@ -2462,13 +2470,6 @@
      throw new ClientException(
              LDAPResultCode.CLIENT_SIDE_SERVER_DOWN, message, ioe);
    }
    catch (ASN1Exception ae)
    {
      LocalizableMessage message =
          ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE.get(getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
                                message, ae);
    }
    catch (LDAPException le)
    {
      LocalizableMessage message =
@@ -3049,6 +3050,13 @@
                                  message);
      }
    }
    catch (DecodeException ae)
    {
      LocalizableMessage message =
          ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE.get(getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
          message, ae);
    }
    catch (IOException ioe)
    {
      LocalizableMessage message =
@@ -3056,13 +3064,6 @@
      throw new ClientException(
              LDAPResultCode.CLIENT_SIDE_SERVER_DOWN, message, ioe);
    }
    catch (ASN1Exception ae)
    {
      LocalizableMessage message =
          ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE.get(getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
                                message, ae);
    }
    catch (LDAPException le)
    {
      LocalizableMessage message =
@@ -3278,6 +3279,13 @@
                                    message);
        }
      }
      catch (DecodeException ae)
      {
        LocalizableMessage message =
            ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE.get(getExceptionMessage(ae));
        throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
            message, ae);
      }
      catch (IOException ioe)
      {
        LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE.get(
@@ -3285,13 +3293,6 @@
        throw new ClientException(
                LDAPResultCode.CLIENT_SIDE_SERVER_DOWN, message, ioe);
      }
      catch (ASN1Exception ae)
      {
        LocalizableMessage message =
            ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE.get(getExceptionMessage(ae));
        throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
                                  message, ae);
      }
      catch (LDAPException le)
      {
        LocalizableMessage message =
@@ -3451,6 +3452,14 @@
                                        message);
            }
          }
          catch (DecodeException ae)
          {
            LocalizableMessage message =
                ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE
                    .get(getExceptionMessage(ae));
            throw new ClientException(
                LDAPResultCode.CLIENT_SIDE_DECODING_ERROR, message, ae);
          }
          catch (IOException ioe)
          {
            LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE.get(
@@ -3458,13 +3467,6 @@
            throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
                                      message, ioe);
          }
          catch (ASN1Exception ae)
          {
            LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE.get(
                getExceptionMessage(ae));
            throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
                                      message, ae);
          }
          catch (LDAPException le)
          {
            LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_BIND_RESPONSE.get(
@@ -3655,6 +3657,13 @@
                                  message);
      }
    }
    catch (DecodeException ae)
    {
      LocalizableMessage message =
          ERR_LDAPAUTH_CANNOT_READ_WHOAMI_RESPONSE.get(getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
          message, ae);
    }
    catch (IOException ioe)
    {
      LocalizableMessage message = ERR_LDAPAUTH_CANNOT_READ_WHOAMI_RESPONSE.get(
@@ -3662,13 +3671,6 @@
      throw new ClientException(
              LDAPResultCode.CLIENT_SIDE_SERVER_DOWN, message, ioe);
    }
    catch (ASN1Exception ae)
    {
      LocalizableMessage message =
          ERR_LDAPAUTH_CANNOT_READ_WHOAMI_RESPONSE.get(getExceptionMessage(ae));
      throw new ClientException(LDAPResultCode.CLIENT_SIDE_DECODING_ERROR,
                                message, ae);
    }
    catch (LDAPException le)
    {
      LocalizableMessage message =
opendj3-server-dev/src/server/org/opends/server/tools/LDAPCompare.java
@@ -41,7 +41,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.controls.LDAPAssertionRequestControl;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.ldap.CompareRequestProtocolOp;
import org.opends.server.protocols.ldap.CompareResponseProtocolOp;
import org.opends.server.protocols.ldap.LDAPFilter;
@@ -248,7 +248,7 @@
                                              protocolOp, controls);
        connection.getLDAPWriter().writeMessage(message);
        responseMessage = connection.getLDAPReader().readMessage();
      } catch(ASN1Exception ae)
      } catch(DecodeException ae)
      {
        logger.traceException(ae);
        if (!compareOptions.continueOnError())
opendj3-server-dev/src/server/org/opends/server/tools/LDAPDelete.java
@@ -39,7 +39,7 @@
import java.util.LinkedList;
import java.util.concurrent.atomic.AtomicInteger;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.ldap.DeleteRequestProtocolOp;
import org.opends.server.protocols.ldap.DeleteResponseProtocolOp;
import org.opends.server.protocols.ldap.LDAPMessage;
@@ -188,7 +188,7 @@
      {
        connection.getLDAPWriter().writeMessage(message);
        responseMessage = connection.getLDAPReader().readMessage();
      } catch(ASN1Exception ae)
      } catch(DecodeException ae)
      {
        logger.traceException(ae);
        if (!deleteOptions.continueOnError())
opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java
@@ -42,7 +42,7 @@
import org.opends.server.controls.ProxiedAuthV2Control;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.plugins.ChangeNumberControlPlugin;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.ldap.AddRequestProtocolOp;
import org.opends.server.protocols.ldap.AddResponseProtocolOp;
import org.opends.server.protocols.ldap.DeleteRequestProtocolOp;
@@ -310,7 +310,7 @@
                               controls);
          connection.getLDAPWriter().writeMessage(message);
          responseMessage = connection.getLDAPReader().readMessage();
        } catch(ASN1Exception ae)
        } catch(DecodeException ae)
        {
          logger.traceException(ae);
          LocalizableMessage message = INFO_OPERATION_FAILED.get(operationType);
opendj3-server-dev/src/server/org/opends/server/tools/LDAPPasswordModify.java
@@ -37,7 +37,7 @@
import org.opends.server.controls.PasswordPolicyErrorType;
import org.opends.server.controls.PasswordPolicyResponseControl;
import org.opends.server.controls.PasswordPolicyWarningType;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.protocols.ldap.ExtendedRequestProtocolOp;
import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp;
import org.opends.server.protocols.ldap.LDAPControl;
@@ -771,20 +771,8 @@
      LocalizableMessage message = ERR_LDAPPWMOD_CANNOT_SEND_PWMOD_REQUEST.get(e);
      err.println(wrapText(message, MAX_LINE_WIDTH));
      try
      {
        requestMessage = new LDAPMessage(nextMessageID.getAndIncrement(),
                                         new UnbindRequestProtocolOp());
        writer.writeMessage(requestMessage);
      }
      catch (Exception e2) {}
      try
      {
        reader.close();
        writer.close();
      } catch (Exception e2) {}
      unbind(nextMessageID, writer);
      close(reader, writer);
      return 1;
    }
@@ -800,20 +788,8 @@
      LocalizableMessage message = ERR_LDAPPWMOD_CANNOT_READ_PWMOD_RESPONSE.get(e);
      err.println(wrapText(message, MAX_LINE_WIDTH));
      try
      {
        requestMessage = new LDAPMessage(nextMessageID.getAndIncrement(),
                                         new UnbindRequestProtocolOp());
        writer.writeMessage(requestMessage);
      }
      catch (Exception e2) {}
      try
      {
        reader.close();
        writer.close();
      } catch (Exception e2) {}
      unbind(nextMessageID, writer);
      close(reader, writer);
      return 1;
    }
@@ -841,20 +817,8 @@
        err.println(wrapText(message, MAX_LINE_WIDTH));
      }
      try
      {
        requestMessage = new LDAPMessage(nextMessageID.getAndIncrement(),
                                         new UnbindRequestProtocolOp());
        writer.writeMessage(requestMessage);
      }
      catch (Exception e) {}
      try
      {
        reader.close();
        writer.close();
      } catch (Exception e) {}
      unbind(nextMessageID, writer);
      close(reader, writer);
      return resultCode;
    }
    else
@@ -944,41 +908,29 @@
        LocalizableMessage message = ERR_LDAPPWMOD_COULD_NOT_DECODE_RESPONSE_VALUE.get(e);
        err.println(wrapText(message, MAX_LINE_WIDTH));
        try
        {
          requestMessage = new LDAPMessage(nextMessageID.getAndIncrement(),
                                           new UnbindRequestProtocolOp());
          writer.writeMessage(requestMessage);
        }
        catch (Exception e2) {}
        try
        {
          reader.close();
          writer.close();
        } catch (Exception e2) {}
        unbind(nextMessageID, writer);
        close(reader, writer);
        return 1;
      }
    }
    // Unbind from the server and close the connection.
    unbind(nextMessageID, writer);
    close(reader, writer);
    return 0;
  }
  private static void unbind(AtomicInteger nextMessageID, LDAPWriter writer)
  {
    try
    {
      requestMessage = new LDAPMessage(nextMessageID.getAndIncrement(),
                                       new UnbindRequestProtocolOp());
      LDAPMessage requestMessage = new LDAPMessage(
          nextMessageID.getAndIncrement(), new UnbindRequestProtocolOp());
      writer.writeMessage(requestMessage);
    }
    catch (Exception e) {}
    try
    {
      reader.close();
      writer.close();
    } catch (Exception e) {}
    return 0;
  }
}
opendj3-server-dev/src/server/org/opends/server/tools/LDAPReader.java
@@ -33,9 +33,9 @@
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.ldap.DecodeException;
import org.forgerock.opendj.io.ASN1Reader;
import org.opends.server.protocols.ldap.LDAPMessage;
import org.opends.server.types.LDAPException;
import org.opends.server.types.RecordingInputStream;
@@ -79,14 +79,14 @@
   * @throws  IOException  If a problem occurs while attempting to read from the
   *                       input stream.
   *
   * @throws  ASN1Exception  If a problem occurs while attempting to decode the
   * @throws  DecodeException  If a problem occurs while attempting to decode the
   *                         data read as an ASN.1 sequence.
   * @throws  LDAPException  If a problem occurs while attempting to decode the
   *                         LDAP message.
   */
  public LDAPMessage readMessage()
       throws IOException, ASN1Exception, LDAPException
       throws IOException, DecodeException, LDAPException
  {
    debugInputStream.setRecordingEnabled(logger.isTraceEnabled());
opendj3-server-dev/src/server/org/opends/server/tools/LDAPSearch.java
@@ -49,7 +49,7 @@
import com.forgerock.opendj.cli.IntegerArgument;
import com.forgerock.opendj.cli.MultiChoiceArgument;
import com.forgerock.opendj.cli.StringArgument;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import static org.opends.messages.ToolMessages.*;
@@ -386,7 +386,7 @@
          } while(opType != OP_TYPE_SEARCH_RESULT_DONE);
        } catch(ASN1Exception ae)
        } catch(DecodeException ae)
        {
          logger.traceException(ae);
          throw new IOException(ae.getMessage());
opendj3-server-dev/src/server/org/opends/server/tools/LDAPToolUtils.java
@@ -33,7 +33,7 @@
import java.io.PrintStream;
import java.net.SocketTimeoutException;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.opends.server.types.DN;
@@ -290,11 +290,11 @@
   * <br>
   * The code simply checks that the exception corresponds to a client side
   * time out.
   * @param ae the asn1exception that occurred connecting to the server or
   * @param ae the DecodeException that occurred connecting to the server or
   * handling the response from the server.
   * @return the message to be displayed to the user when an exception occurs.
   */
  public static String getMessageForConnectionException(ASN1Exception ae)
  public static String getMessageForConnectionException(DecodeException ae)
  {
    Throwable cause = ae.getCause();
    if (cause != null)
opendj3-server-dev/src/server/org/opends/server/tools/LDAPWriter.java
@@ -24,7 +24,6 @@
 *      Copyright 2009 Sun Microsystems, Inc.
 *      Portions Copyright 2014 ForgeRock AS
 */
package org.opends.server.tools;
import java.io.BufferedOutputStream;
@@ -33,12 +32,13 @@
import java.net.Socket;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.opends.server.protocols.ldap.LDAPMessage;
import org.opends.server.types.RecordingOutputStream;
import org.opends.server.util.ServerConstants;
import org.opends.server.util.StaticUtils;
/**
 * This class defines a utility that can be used to write LDAP messages over a
@@ -97,14 +97,8 @@
      ByteString bytesRead = debugOutputStream.getRecordedBytes();
      debugOutputStream.clearRecordedBytes();
      StringBuilder builder = new StringBuilder();
      builder.append("bytes written to wire(len=");
      builder.append(bytesRead.length());
      builder.append("):");
      builder.append(ServerConstants.EOL);
      builder.append(bytesRead.toHexPlusAsciiString(4));
      logger.trace(builder.toString());
      logger.trace("bytes written to wire(len=" + bytesRead.length() + "):"
          + ServerConstants.EOL + bytesRead.toHexPlusAsciiString(4));
    }
  }
@@ -114,26 +108,7 @@
  @Override
  public void close()
  {
    try
    {
      asn1Writer.close();
    }
    catch (Exception e)
    {
      logger.traceException(e);
    }
    if (socket != null)
    {
      try
      {
        socket.close();
      }
      catch (Exception e)
      {
        logger.traceException(e);
      }
    }
    StaticUtils.close(asn1Writer, debugOutputStream);
    StaticUtils.close(socket);
  }
}
opendj3-server-dev/src/server/org/opends/server/tools/ManageAccount.java
@@ -39,7 +39,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.admin.AdministrationConnector;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.protocols.ldap.ExtendedRequestProtocolOp;
import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp;
import org.opends.server.protocols.ldap.LDAPMessage;
opendj3-server-dev/src/server/org/opends/server/tools/ManageTasks.java
@@ -36,7 +36,7 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.loggers.ErrorLogger;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import static org.opends.server.tools.ToolConstants.*;
@@ -419,10 +419,10 @@
   * @throws IOException if there is a problem with screen I/O
   * @throws LDAPException if there is a problem getting information
   *         out to the directory
   * @throws ASN1Exception if there is a problem with the encoding
   * @throws DecodeException if there is a problem with the encoding
   */
  private void printSummaryTable()
          throws LDAPException, IOException, ASN1Exception {
          throws LDAPException, IOException, DecodeException {
    List<TaskEntry> entries = taskClient.getTaskEntries();
    if (entries.size() > 0) {
      TableBuilder table = new TableBuilder();
@@ -465,10 +465,10 @@
   * @throws IOException if there is a problem with screen I/O
   * @throws LDAPException if there is a problem getting information
   *         out to the directory
   * @throws ASN1Exception if there is a problem with the encoding
   * @throws DecodeException if there is a problem with the encoding
   */
  private Menu<Void> getSummaryMenu()
          throws LDAPException, IOException, ASN1Exception {
          throws LDAPException, IOException, DecodeException {
    List<String> taskIds = new ArrayList<String>();
    List<Integer> cancelableIndices = new ArrayList<Integer>();
    List<TaskEntry> entries = taskClient.getTaskEntries();
opendj3-server-dev/src/server/org/opends/server/tools/StopDS.java
@@ -40,11 +40,12 @@
import javax.net.ssl.SSLException;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.admin.AdministrationConnector;
import org.opends.server.controls.ProxiedAuthV2Control;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.LockFileManager;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.opends.server.protocols.ldap.AddRequestProtocolOp;
import org.opends.server.protocols.ldap.AddResponseProtocolOp;
import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp;
@@ -56,7 +57,6 @@
import org.opends.server.tools.tasks.TaskTool;
import org.opends.server.types.*;
import org.opends.server.util.args.LDAPConnectionArgumentParser;
import org.forgerock.opendj.ldap.ByteString;
import com.forgerock.opendj.cli.Argument;
import com.forgerock.opendj.cli.ArgumentException;
@@ -708,17 +708,17 @@
        return LDAPResultCode.CLIENT_SIDE_SERVER_DOWN;
      }
    }
    catch (IOException ioe)
    {
      err.println(wrapText(ERR_STOPDS_IO_ERROR.get(ioe), MAX_LINE_WIDTH));
      return LDAPResultCode.CLIENT_SIDE_SERVER_DOWN;
    }
    catch (ASN1Exception ae)
    catch (DecodeException ae)
    {
      LocalizableMessage message = ERR_STOPDS_DECODE_ERROR.get(ae.getMessage());
      err.println(wrapText(message, MAX_LINE_WIDTH));
      return LDAPResultCode.CLIENT_SIDE_DECODING_ERROR;
    }
    catch (IOException ioe)
    {
      err.println(wrapText(ERR_STOPDS_IO_ERROR.get(ioe), MAX_LINE_WIDTH));
      return LDAPResultCode.CLIENT_SIDE_SERVER_DOWN;
    }
    catch (LDAPException le)
    {
      LocalizableMessage message = ERR_STOPDS_DECODE_ERROR.get(le.getMessage());
opendj3-server-dev/src/server/org/opends/server/tools/tasks/TaskClient.java
@@ -45,7 +45,7 @@
import org.opends.server.backends.task.FailedDependencyAction;
import org.opends.server.backends.task.TaskState;
import org.opends.server.config.ConfigConstants;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.ldap.AddRequestProtocolOp;
import org.opends.server.protocols.ldap.AddResponseProtocolOp;
import org.opends.server.protocols.ldap.DeleteRequestProtocolOp;
@@ -300,11 +300,11 @@
   * @throws IOException if there is a stream communication problem
   * @throws LDAPException if there is a problem getting information
   *         out to the directory
   * @throws ASN1Exception if there is a problem with the encoding
   * @throws DecodeException if there is a problem with the encoding
   * @throws TaskClientException if there is a problem with the task entry
   */
  public synchronized TaskEntry schedule(TaskScheduleInformation information)
          throws LDAPException, IOException, ASN1Exception, TaskClientException
          throws LDAPException, IOException, DecodeException, TaskClientException
  {
    LDAPReader reader = connection.getLDAPReader();
    LDAPWriter writer = connection.getLDAPWriter();
@@ -356,10 +356,10 @@
   * @throws IOException if there is a stream communication problem
   * @throws LDAPException if there is a problem getting information
   *         out to the directory
   * @throws ASN1Exception if there is a problem with the encoding
   * @throws DecodeException if there is a problem with the encoding
   */
  public synchronized List<TaskEntry> getTaskEntries()
          throws LDAPException, IOException, ASN1Exception {
          throws LDAPException, IOException, DecodeException {
    List<Entry> entries = new ArrayList<Entry>();
    writeSearch(new SearchRequestProtocolOp(
@@ -406,11 +406,11 @@
   * @throws IOException if there is a stream communication problem
   * @throws LDAPException if there is a problem getting information
   *         out to the directory
   * @throws ASN1Exception if there is a problem with the encoding
   * @throws DecodeException if there is a problem with the encoding
   * @throws TaskClientException if there is no task with the requested id
   */
  public synchronized TaskEntry getTaskEntry(String id)
          throws LDAPException, IOException, ASN1Exception, TaskClientException
          throws LDAPException, IOException, DecodeException, TaskClientException
  {
    Entry entry = null;
@@ -455,11 +455,11 @@
   * @throws IOException if there is a stream communication problem
   * @throws LDAPException if there is a problem getting information
   *         out to the directory
   * @throws ASN1Exception if there is a problem with the encoding
   * @throws DecodeException if there is a problem with the encoding
   * @throws TaskClientException if there is no task with the requested id
   */
  public synchronized void cancelTask(String id)
          throws TaskClientException, IOException, ASN1Exception, LDAPException
          throws TaskClientException, IOException, DecodeException, LDAPException
  {
    LDAPReader reader = connection.getLDAPReader();
    LDAPWriter writer = connection.getLDAPWriter();
opendj3-server-dev/src/server/org/opends/server/tools/tasks/TaskTool.java
@@ -24,7 +24,6 @@
 *      Copyright 2007-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2012-2014 ForgeRock AS
 */
package org.opends.server.tools.tasks;
import com.forgerock.opendj.cli.Argument;
@@ -38,7 +37,7 @@
import static org.opends.server.util.StaticUtils.getExceptionMessage;
import static org.opends.server.util.ServerConstants.MAX_LINE_WIDTH;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.tools.LDAPConnection;
import org.opends.server.tools.LDAPConnectionException;
@@ -369,12 +368,12 @@
        }
        if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH));
        ret = 1;
      } catch (IOException ioe) {
        LocalizableMessage message = ERR_TASK_TOOL_IO_ERROR.get(ioe);
      } catch (DecodeException ae) {
        LocalizableMessage message = ERR_TASK_TOOL_DECODE_ERROR.get(ae.getMessage());
        if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH));
        ret = 1;
      } catch (ASN1Exception ae) {
        LocalizableMessage message = ERR_TASK_TOOL_DECODE_ERROR.get(ae.getMessage());
      } catch (IOException ioe) {
        LocalizableMessage message = ERR_TASK_TOOL_IO_ERROR.get(ioe);
        if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH));
        ret = 1;
      } catch (LDAPException le) {
opendj3-server-dev/src/server/org/opends/server/types/Control.java
@@ -22,10 +22,11 @@
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2014 ForgeRock AS
 */
package org.opends.server.types;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import java.io.IOException;
opendj3-server-dev/src/server/org/opends/server/types/RawAttribute.java
@@ -37,8 +37,8 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.protocols.ldap.LDAPAttribute;
/**
opendj3-server-dev/src/server/org/opends/server/types/RawFilter.java
@@ -35,7 +35,7 @@
import java.io.IOException;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.protocols.ldap.LDAPFilter;
import static org.opends.messages.ProtocolMessages.*;
opendj3-server-dev/src/server/org/opends/server/types/RawModification.java
@@ -36,8 +36,8 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.protocols.ldap.LDAPModification;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -56,9 +56,9 @@
import org.opends.server.extensions.ConfigFileHandler;
import org.opends.server.loggers.*;
import org.opends.server.plugins.InvocationCounterPlugin;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.protocols.ldap.BindRequestProtocolOp;
import org.opends.server.protocols.ldap.BindResponseProtocolOp;
import org.opends.server.protocols.ldap.LDAPMessage;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/ExternalChangelogControlTest.java
@@ -26,8 +26,8 @@
 */
package org.opends.server.controls;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.protocols.ldap.LDAPReader;
import org.opends.server.replication.common.MultiDomainServerState;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/MatchedValuesControlTest.java
@@ -40,8 +40,8 @@
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.opends.server.protocols.asn1.ASN1;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.opends.server.util.Base64;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/PasswordControlTest.java
@@ -36,8 +36,8 @@
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.protocols.ldap.LDAPReader;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Writer;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/PersistentSearchControlTest.java
@@ -31,8 +31,8 @@
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.ModifyOperation;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.ldap.LDAPAttribute;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/ProxiedAuthV1ControlTestCase.java
@@ -33,8 +33,8 @@
import org.opends.server.TestCaseUtils;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.opends.server.protocols.asn1.ASN1;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/ProxiedAuthV2ControlTestCase.java
@@ -33,8 +33,8 @@
import org.opends.server.TestCaseUtils;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/VLVControlTestCase.java
@@ -28,12 +28,8 @@
import static org.opends.server.util.ServerConstants.OID_SERVER_SIDE_SORT_RESPONSE_CONTROL;
import static org.opends.server.util.ServerConstants.OID_VLV_RESPONSE_CONTROL;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.fail;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
import java.util.ArrayList;
import java.util.List;
@@ -44,10 +40,9 @@
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Constants;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
@@ -406,22 +401,22 @@
    ASN1Reader reader = ASN1.getReader(builder.toByteString());
    // Should start as an octet string with a nested sequence
    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_OCTET_STRING_TYPE);
    assertEquals(reader.peekType(), ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    reader.readStartSequence();
    // Should be an sequence start
    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_SEQUENCE_TYPE);
    assertEquals(reader.peekType(), ASN1.UNIVERSAL_SEQUENCE_TYPE);
    reader.readStartSequence();
    // Should be an integer with targetPosition
    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_INTEGER_TYPE);
    assertEquals(reader.peekType(), ASN1.UNIVERSAL_INTEGER_TYPE);
    assertEquals(reader.readInteger(), 0);
    // Should be an integer with contentCount
    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_INTEGER_TYPE);
    assertEquals(reader.peekType(), ASN1.UNIVERSAL_INTEGER_TYPE);
    assertEquals(reader.readInteger(), 15);
    // Should be an enumerated with virtualListViewResult
    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_ENUMERATED_TYPE);
    assertEquals(reader.peekType(), ASN1.UNIVERSAL_ENUMERATED_TYPE);
    assertEquals(reader.readEnumerated(), 0);
    // Should be an octet string with contextID
    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_OCTET_STRING_TYPE);
    assertEquals(reader.peekType(), ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    assertEquals(reader.readOctetStringAsString(), "foo");
  }
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/core/SearchOperationTestCase.java
@@ -38,7 +38,7 @@
import org.opends.server.controls.MatchedValuesFilter;
import org.opends.server.controls.SubentriesControl;
import org.opends.server.plugins.InvocationCounterPlugin;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.ldap.*;
@@ -347,7 +347,7 @@
  }
  private void bindAsManager(LDAPWriter w, org.opends.server.tools.LDAPReader r)
       throws IOException, LDAPException, ASN1Exception, InterruptedException
       throws IOException, LDAPException, DecodeException, InterruptedException
  {
    // Since we are going to be watching the post-response count, we need to
    // wait for the server to become idle before kicking off the next request to
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/CancelExtendedOperationTestCase.java
@@ -40,8 +40,8 @@
import org.opends.server.TestCaseUtils;
import org.opends.server.core.AddOperation;
import org.opends.server.plugins.DelayPreOpPlugin;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.ldap.AddRequestProtocolOp;
import org.opends.server.protocols.ldap.AddResponseProtocolOp;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/LDAPPassThroughAuthenticationPolicyTestCase.java
@@ -49,8 +49,8 @@
import org.opends.server.extensions.LDAPPassThroughAuthenticationPolicyFactory.ConnectionFactory;
import org.opends.server.extensions.LDAPPassThroughAuthenticationPolicyFactory.ConnectionPool;
import org.opends.server.extensions.LDAPPassThroughAuthenticationPolicyFactory.LDAPConnectionFactory;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.protocols.ldap.*;
import org.opends.server.schema.DirectoryStringSyntax;
import org.opends.server.schema.GeneralizedTimeSyntax;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/PasswordModifyExtendedOperationTestCase.java
@@ -46,8 +46,8 @@
import org.opends.server.core.ExtendedOperation;
import org.opends.server.core.ModifyOperation;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.tools.LDAPPasswordModify;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/plugins/DelayPreOpPlugin.java
@@ -40,15 +40,13 @@
import org.opends.server.api.plugin.PluginType;
import org.opends.server.config.ConfigException;
import org.opends.server.controls.ControlDecoder;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.operation.*;
import static org.opends.server.protocols.asn1.ASN1Constants.*;
/**
 * This class defines a very simple pre-operation plugin that sleeps for up to
 * five seconds for add, compare, delete, extended, modify, modify DN, and
@@ -141,7 +139,7 @@
     */
    @Override
    protected void writeValue(ASN1Writer writer) throws IOException {
      writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
      writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
      writer.writeInteger(delayDuration);
      writer.writeEndSequence();
    }
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/plugins/DisconnectClientPlugin.java
@@ -42,7 +42,7 @@
import org.opends.server.api.plugin.PluginType;
import org.opends.server.config.ConfigException;
import org.opends.server.controls.ControlDecoder;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.types.CanceledOperationException;
import org.opends.server.types.Control;
import org.opends.server.types.DirectoryException;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/plugins/SambaPasswordPluginTestCase.java
@@ -46,8 +46,8 @@
import org.opends.server.core.ModifyOperation;
import org.opends.server.extensions.ExtensionsConstants;
import org.opends.server.plugins.SambaPasswordPlugin.TimeStampProvider;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteStringBuilder;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/plugins/ShortCircuitPlugin.java
@@ -42,16 +42,13 @@
import org.opends.server.api.plugin.PluginType;
import org.opends.server.config.ConfigException;
import org.opends.server.controls.ControlDecoder;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.operation.*;
import static org.opends.server.protocols.asn1.ASN1Constants.*;
/**
 * This class defines a very simple plugin that causes request processing to end
 * immediately and send a specific result code to the client.  It will be
@@ -153,7 +150,7 @@
     */
    @Override
    protected void writeValue(ASN1Writer writer) throws IOException {
      writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
      writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
      writer.writeStartSequence();
      writer.writeInteger(resultCode);
      writer.writeOctetString(section);
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/ASN1ByteChannelReaderTestCase.java
New file
@@ -0,0 +1,304 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2014 ForgeRock AS
 */
package org.opends.server.protocols.ldap;
import org.forgerock.opendj.io.ASN1Reader;
import org.opends.server.protocols.ldap.ASN1ByteChannelReader;
import org.testng.annotations.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.channels.Channels;
import java.nio.channels.IllegalBlockingModeException;
/**
 * Test class for ASN1ByteChannelReader
 */
public class ASN1ByteChannelReaderTestCase extends ASN1ReaderTestCase
{
  @Override
  ASN1Reader getReader(byte[] b, int maxElementSize) throws IOException
  {
    ByteArrayInputStream inStream = new ByteArrayInputStream(b);
    ASN1ByteChannelReader reader =
        new ASN1ByteChannelReader(Channels.newChannel(inStream),
            b.length, maxElementSize);
    reader.processChannelData();
    return reader;
  }
  /**
   * Tests the <CODE>decodeAsNull</CODE> method that takes a byte array argument
   * with a short array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testDecodeShortArrayAsNull()
      throws Exception
  {
    super.testDecodeShortArrayAsNull();
  }
  /**
   * Tests the <CODE>decodeAsInteger</CODE> method that takes a byte array with
   * a short array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testDecodeShortArrayAsInteger()
      throws Exception
  {
    super.testDecodeShortArrayAsInteger();
  }
  /**
   * Tests the <CODE>readEnumerated</CODE> method that takes a byte array with
   * a short array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testDecodeShortArrayAsEnumerated()
      throws Exception
  {
    super.testDecodeShortArrayAsEnumerated();
  }
  /**
   * Tests the <CODE>decodeAsBoolean</CODE> method that takes a byte array
   * argument with a short array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testDecodeShortArrayAsBoolean()
      throws Exception
  {
    super.testDecodeShortArrayAsBoolean();
  }
  /**
   * Tests the <CODE>decodeAsOctetString</CODE> method that takes a byte array
   * using a short array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions  = { IllegalBlockingModeException.class })
  public void testDecodeShortArrayAsOctetString()
      throws Exception
  {
    super.testDecodeShortArrayAsOctetString();
  }
  /**
   * Tests the <CODE>decodeAsSequence</CODE> method that takes a byte array
   * argument with a short array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testDecodeShortArrayAsSequence()
      throws Exception
  {
    super.testDecodeShortArrayAsSequence();
  }
  /**
   * Tests the <CODE>decodeAsBoolean</CODE> method that takes a byte array
   * argument with an array that has less bytes than indicated by the length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testDecodeLengthMismatchArrayAsBoolean()
      throws Exception
  {
    super.testDecodeLengthMismatchArrayAsBoolean();
  }
  /**
   * Tests the <CODE>decodeAsInteger</CODE> method that takes a byte array with
   * a length mismatch.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testDecodeLengthMismatchArrayAsInteger()
      throws Exception
  {
    super.testDecodeLengthMismatchArrayAsInteger();
  }
  /**
   * Tests the <CODE>readEnumerated</CODE> method that takes a byte array with
   * a length mismatch.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testDecodeLengthMismatchArrayAsEnumerated()
      throws Exception
  {
    super.testDecodeLengthMismatchArrayAsEnumerated();
  }
  /**
   * Tests the <CODE>decodeAsOctetString</CODE> method that takes a byte array
   * using an array whose actual length doesn't match with the decoded length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions  = { IllegalBlockingModeException.class })
  public void testDecodeLengthMismatchArrayAsOctetString()
      throws Exception
  {
    super.testDecodeLengthMismatchArrayAsOctetString();
  }
  /**
   * Tests the <CODE>decodeAsBoolean</CODE> method that takes a byte array
   * argument with an array that doesn't contain a full length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testDecodeTruncatedLengthArrayAsBoolean()
      throws Exception
  {
    super.testDecodeTruncatedLengthArrayAsBoolean();
  }
  /**
   * Tests the <CODE>decodeAsInteger</CODE> method that takes a byte array with
   * a truncated length array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testDecodeTruncatedLengthArrayAsInteger()
      throws Exception
  {
    super.testDecodeTruncatedLengthArrayAsInteger();
  }
  /**
   * Tests the <CODE>readEnumerated</CODE> method that takes a byte array with
   * a truncated length array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testDecodeTruncatedLengthArrayAsEnumerated()
      throws Exception
  {
    super.testDecodeTruncatedLengthArrayAsEnumerated();
  }
  /**
   * Tests the <CODE>decodeAsNull</CODE> method that takes a byte array argument
   * with an array with a truncated length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testDecodeTruncatedLengthArrayAsNull()
      throws Exception
  {
    super.testDecodeTruncatedLengthArrayAsNull();
  }
  /**
   * Tests the <CODE>decodeAsOctetString</CODE> method that takes a byte array
   * using an array that doesn't fully contain the length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions  = { IllegalBlockingModeException.class })
  public void testDecodeTruncatedLengthArrayAsOctetString()
      throws Exception
  {
    super.testDecodeTruncatedLengthArrayAsOctetString();
  }
  /**
   * Tests the <CODE>decodeAsSequence</CODE> method that takes a byte array
   * argument with an array that doesn't fully describe the length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testDecodeTruncatedLengthArrayAsSequence()
      throws Exception
  {
    super.testDecodeTruncatedLengthArrayAsSequence();
  }
  /**
   * Tests to make sure a premature EOF while reading a sub sequence can be
   * detected.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testDecodeSequencePrematureEof()
      throws Exception
  {
    super.testDecodeSequencePrematureEof();
  }
  /**
   * Tests the <CODE>skipElement</CODE> method.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Override
  @Test(expectedExceptions = { IllegalBlockingModeException.class })
  public void testSkipElementIncompleteRead()
      throws Exception
  {
    super.testSkipElementIncompleteRead();
  }
}
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/ASN1ReaderTestCase.java
New file
@@ -0,0 +1,853 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2014 ForgeRock AS
 */
package org.opends.server.protocols.ldap;
import java.io.IOException;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.DirectoryServerTestCase;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
/**
 * An abstract base class for all ASN1Reader test cases.
 */
@Test(groups = { "precommit", "asn1" }, sequential = true)
public abstract class ASN1ReaderTestCase extends DirectoryServerTestCase
{
  /**
   * Retrieves the set of byte array values that may be used for testing.
   *
   * @return  The set of byte array values that may be used for testing.
   */
  @DataProvider(name = "byteValues")
  public Object[][] getByteValues()
  {
    Object[][] array = new Object[256][1];
    for (int i=0; i < 256; i++)
    {
      array[i] = new Object[] { new byte[] { (byte) (i & 0xFF) } };
    }
    return array;
  }
  /**
   * Create byte arrays with encoded ASN.1 elements to test decoding them as
   * octet strings.
   *
   * @return  A list of byte arrays with encoded ASN.1 elements that can be
   *          decoded as octet strings.
   */
  @DataProvider(name = "elementArrays")
  public Object[][] getElementArrays()
  {
    return new Object[][]
        {
            new Object[] { new byte[] { 0x04, 0x00 } },
            new Object[] { new byte[] { (byte) 0x50, 0x00 } },
            new Object[] { new byte[] { 0x04, 0x05, 0x48, 0x65, 0x6C, 0x6C, 0x6F } },
            new Object[] { new byte[] { 0x01, 0x01, 0x00 } },
            new Object[] { new byte[] { 0x01, 0x01, (byte) 0xFF } },
            new Object[] { new byte[] { 0x0A, 0x01, 0x00 } },
            new Object[] { new byte[] { 0x0A, 0x01, 0x01 } },
            new Object[] { new byte[] { 0x0A, 0x01, 0x7F } },
            new Object[] { new byte[] { 0x0A, 0x01, (byte) 0x80 } },
            new Object[] { new byte[] { 0x0A, 0x01, (byte) 0xFF } },
            new Object[] { new byte[] { 0x0A, 0x02, 0x01, 0x00 } },
            new Object[] { new byte[] { 0x02, 0x01, 0x00 } },
            new Object[] { new byte[] { 0x02, 0x01, 0x01 } },
            new Object[] { new byte[] { 0x02, 0x01, 0x7F } },
            new Object[] { new byte[] { 0x02, 0x02, 0x00, (byte) 0x80 } },
            new Object[] { new byte[] { 0x02, 0x02, 0x00, (byte) 0xFF } },
            new Object[] { new byte[] { 0x02, 0x02, 0x01, 0x00 } },
            new Object[] { new byte[] { 0x05, 0x00 } },
            new Object[] { new byte[] { 0x30, 0x00 } },
            new Object[] { new byte[] { 0x31, 0x00 } },
            new Object[] { new byte[] { 0x05, (byte) 0x81, 0x00 } },
            new Object[] { new byte[] { 0x05, (byte) 0x82, 0x00, 0x00 } },
            new Object[] { new byte[] { 0x05, (byte) 0x83, 0x00, 0x00, 0x00 } },
            new Object[] { new byte[] { 0x05, (byte) 0x84, 0x00, 0x00, 0x00, 0x00 } },
        };
  }
  /**
   * Gets the reader to be use for the unit tests.
   *
   * @param b
   *          The array of bytes to be read.
   * @param maxElementSize
   *          The max element size.
   * @return The reader to be use for the unit tests.
   * @throws IOException
   *           In an unexpected IO exception occurred.
   */
  abstract ASN1Reader getReader(byte[] b, int maxElementSize)
      throws IOException;
  /**
   * Tests the <CODE>decodeAsNull</CODE> method that takes a byte array argument
   * with a short array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeShortArrayAsNull()
      throws Exception
  {
    byte[] b = new byte[1];
    getReader(b, 0).readNull();
  }
  /**
   * Tests the <CODE>decodeAsNull</CODE> method that takes a byte array argument
   * with an array with a long length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeLongLengthArrayAsNull()
      throws Exception
  {
    byte[] b = new byte[] { 0x05, (byte) 0x85, 0x00, 0x00, 0x00, 0x00, 0x00 };
    getReader(b, 0).readNull();
  }
  /**
   * Tests the <CODE>decodeAsNull</CODE> method that takes a byte array argument
   * with an array with a truncated length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeTruncatedLengthArrayAsNull()
      throws Exception
  {
    byte[] b = new byte[] { 0x05, (byte) 0x82, 0x00 };
    getReader(b, 0).readNull();
  }
  /**
   * Tests the <CODE>decodeAsNull</CODE> method that takes a byte array argument
   * with an arry with a nonzero length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeNonZeroLengthArrayAsNull()
      throws Exception
  {
    byte[] b = new byte[] { 0x05, 0x01, 0x00 };
    getReader(b, 0).readNull();
  }
  /**
   * Tests the <CODE>decodeAsNull</CODE> method that takes a byte array argument
   * with an arry with a zero length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test()
  public void testDecodeZeroLengthArrayAsNull()
      throws Exception
  {
    byte[] b = new byte[] { 0x05, 0x00 };
    getReader(b, 0).readNull();
  }
  /**
   * Tests the <CODE>decodeAsNull</CODE> method that takes a byte array argument
   * with an arry with a zero length that takes multiple bytes to encode.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test()
  public void testDecodeExtendedZeroLengthArrayAsNull()
      throws Exception
  {
    byte[] b = new byte[] { 0x05, (byte) 0x81, 0x00 };
    getReader(b, 0).readNull();
  }
  /**
   * Tests the <CODE>decodeAsInteger</CODE> method that takes a byte array with
   * a short array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeShortArrayAsInteger()
      throws Exception
  {
    byte[] b = new byte[0];
    getReader(b, 0).readInteger();
  }
  /**
   * Tests the <CODE>readEnumerated</CODE> method that takes a byte array with
   * a short array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeShortArrayAsEnumerated()
      throws Exception
  {
    byte[] b = new byte[0];
    getReader(b, 0).readEnumerated();
  }
  /**
   * Tests the <CODE>decodeAsInteger</CODE> method that takes a byte array with
   * a long length array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeLongLengthArrayAsInteger()
      throws Exception
  {
    byte[] b = { 0x02, (byte) 0x85, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 };
    getReader(b, 0).readInteger();
  }
  /**
   * Tests the <CODE>readEnumerated</CODE> method that takes a byte array with
   * a long length array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeLongLengthArrayAsEnumerated()
      throws Exception
  {
    byte[] b = { 0x02, (byte) 0x85, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 };
    getReader(b, 0).readEnumerated();
  }
  /**
   * Tests the <CODE>decodeAsInteger</CODE> method that takes a byte array with
   * a truncated length array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeTruncatedLengthArrayAsInteger()
      throws Exception
  {
    byte[] b = { 0x02, (byte) 0x82, 0x00 };
    getReader(b, 0).readInteger();
  }
  /**
   * Tests the <CODE>readEnumerated</CODE> method that takes a byte array with
   * a truncated length array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeTruncatedLengthArrayAsEnumerated()
      throws Exception
  {
    byte[] b = { 0x02, (byte) 0x82, 0x00 };
    getReader(b, 0).readEnumerated();
  }
  /**
   * Tests the <CODE>decodeAsInteger</CODE> method that takes a byte array with
   * a length mismatch.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeLengthMismatchArrayAsInteger()
      throws Exception
  {
    byte[] b = { 0x02, (byte) 0x81, 0x01 };
    getReader(b, 0).readInteger();
  }
  /**
   * Tests the <CODE>readEnumerated</CODE> method that takes a byte array with
   * a length mismatch.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeLengthMismatchArrayAsEnumerated()
      throws Exception
  {
    byte[] b = { 0x02, (byte) 0x81, 0x01 };
    getReader(b, 0).readEnumerated();
  }
  /**
   * Tests the <CODE>decodeAsBoolean</CODE> method that takes a byte array
   * argument with valid arrays.
   *
   * @param  b  The byte array to use for the element values.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(dataProvider = "byteValues")
  public void testDecodeValidArrayAsBoolean(byte[] b)
      throws Exception
  {
    // First, test with the standard Boolean type.
    byte[] elementArray = new byte[] { 0x01, 0x01, b[0] };
    assertEquals(getReader(elementArray, 0).readBoolean(), (b[0] != 0x00));
    // Next, test with a nonstandard Boolean type.
    elementArray[0] = (byte) 0x50;
    assertEquals(getReader(elementArray, 0).readBoolean(), (b[0] != 0x00));
  }
  /**
   * Tests the <CODE>decodeAsBoolean</CODE> method that takes a byte array
   * argument with valid arrays using extended lengths.
   *
   * @param  b  The byte array to use for the element values.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(dataProvider = "byteValues")
  public void testDecodeValidExtendedArrayAsBoolean(byte[] b)
      throws Exception
  {
    // First, test with the standard Boolean type.
    byte[] elementArray = new byte[] { 0x01, (byte) 0x81, 0x01, b[0] };
    assertEquals(getReader(elementArray, 0).readBoolean(), (b[0] != 0x00));
    // Next, test with a nonstandard Boolean type.
    elementArray[0] = (byte) 0x50;
    assertEquals(getReader(elementArray, 0).readBoolean(), (b[0] != 0x00));
  }
  /**
   * Tests the <CODE>decodeAsBoolean</CODE> method that takes a byte array
   * argument with a short array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeShortArrayAsBoolean()
      throws Exception
  {
    byte[] b = new byte[1];
    getReader(b, 0).readBoolean();
  }
  /**
   * Tests the <CODE>decodeAsBoolean</CODE> method that takes a byte array
   * argument with an array that takes too many bytes to expressthe length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeLongLengthArrayAsBoolean()
      throws Exception
  {
    byte[] b = { 0x01, (byte) 0x85, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 };
    getReader(b, 0).readBoolean();
  }
  /**
   * Tests the <CODE>decodeAsBoolean</CODE> method that takes a byte array
   * argument with an array that doesn't contain a full length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeTruncatedLengthArrayAsBoolean()
      throws Exception
  {
    byte[] b = { 0x01, (byte) 0x82, 0x00 };
    getReader(b, 0).readBoolean();
  }
  /**
   * Tests the <CODE>decodeAsBoolean</CODE> method that takes a byte array
   * argument with an array that has less bytes than indicated by the length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeLengthMismatchArrayAsBoolean()
      throws Exception
  {
    byte[] b = { 0x01, 0x01 };
    getReader(b, 0).readBoolean();
  }
  /**
   * Tests the <CODE>decodeAsBoolean</CODE> method that takes a byte array
   * argument with an array that has an invalid number of bytes in the value.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeShortValueArrayAsBoolean()
      throws Exception
  {
    byte[] b = { 0x01, 0x00, 0x00, 0x00 };
    getReader(b, 0).readBoolean();
  }
  /**
   * Tests the <CODE>decodeAsBoolean</CODE> method that takes a byte array
   * argument with an array that has an invalid number of bytes in the value.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeLongValueArrayAsBoolean()
      throws Exception
  {
    byte[] b = { 0x01, 0x02, 0x00, 0x00 };
    getReader(b, 0).readBoolean();
  }
  /**
   * Tests the <CODE>decodeAsOctetString</CODE> method that takes a byte array
   * using a valid array.
   *
   * @param  b  The byte array to decode.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(dataProvider = "elementArrays")
  public void testDecodeValidArrayAsOctetString(byte[] b)
      throws Exception
  {
    ByteStringBuilder bsb = new ByteStringBuilder();
    bsb.append(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    bsb.appendBERLength(b.length);
    bsb.append(b);
    assertEquals(getReader(bsb.toByteArray(), 0).readOctetString(),
        ByteString.wrap(b));
  }
  /**
   * Tests the <CODE>decodeAsOctetStringAsString</CODE> method that takes a
   * byte array using a valid array.
   *
   * @param  b  The byte array to decode.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(dataProvider = "elementArrays")
  public void testDecodeValidArrayAsOctetStringAsString(byte[] b)
      throws Exception
  {
    ByteStringBuilder bsb = new ByteStringBuilder();
    bsb.append(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    bsb.appendBERLength(b.length);
    bsb.append(b);
    assertEquals(getReader(bsb.toByteArray(), 0).readOctetStringAsString(),
        new String(b, "UTF-8"));
  }
  /**
   * Tests the <CODE>decodeAsOctetStringBuilder</CODE> method that takes a
   * byte array using a valid array.
   *
   * @param  b  The byte array to decode.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(dataProvider = "elementArrays")
  public void testDecodeValidArrayAsOctetStringBuilder(byte[] b)
      throws Exception
  {
    ByteStringBuilder bsb = new ByteStringBuilder();
    bsb.append(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    bsb.appendBERLength(b.length);
    bsb.append(b);
    ByteStringBuilder bsb2 = new ByteStringBuilder();
    getReader(bsb.toByteArray(), 0).readOctetString(bsb2);
    assertEquals(bsb2.toByteString(), ByteString.wrap(b));
  }
  /**
   * Tests the <CODE>decodeAsOctetString</CODE> method that takes a byte array
   * using a short array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions  = { DecodeException.class })
  public void testDecodeShortArrayAsOctetString()
      throws Exception
  {
    byte[] b = new byte[1];
    getReader(b, 0).readOctetString();
  }
  /**
   * Tests the <CODE>decodeAsOctetString</CODE> method that takes a byte array
   * using an array that indicates it takes more than four bytes to encode the
   * length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions  = { DecodeException.class })
  public void testDecodeLongLengthArrayAsOctetString()
      throws Exception
  {
    byte[] b = { 0x04, (byte) 0x85, 0x00, 0x00, 0x00, 0x00, 0x00 };
    getReader(b, 0).readOctetString();
  }
  /**
   * Tests the <CODE>decodeAsOctetString</CODE> method that takes a byte array
   * using an array that doesn't fully contain the length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions  = { DecodeException.class })
  public void testDecodeTruncatedLengthArrayAsOctetString()
      throws Exception
  {
    byte[] b = { 0x04, (byte) 0x82, 0x00 };
    getReader(b, 0).readOctetString();
  }
  /**
   * Tests the <CODE>decodeAsOctetString</CODE> method that takes a byte array
   * using an array whose actual length doesn't match with the decoded length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions  = { DecodeException.class })
  public void testDecodeLengthMismatchArrayAsOctetString()
      throws Exception
  {
    byte[] b = { 0x04, 0x02, 0x00 };
    getReader(b, 0).readOctetString();
  }
  /**
   * Tests the <CODE>decodeAsSequence</CODE> method that takes a byte array
   * argument with valid arrays.
   *
   * @param  encodedElements  Byte arrays that may be used as valid values for
   *                          encoded elements.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(dataProvider = "elementArrays")
  public void testDecodeValidArrayAsSequence(byte[] encodedElements)
      throws Exception
  {
    ByteStringBuilder bsb = new ByteStringBuilder();
    bsb.append(ASN1.UNIVERSAL_SEQUENCE_TYPE);
    bsb.appendBERLength(encodedElements.length + 2);
    bsb.append(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    bsb.appendBERLength(encodedElements.length);
    bsb.append(encodedElements);
    ASN1Reader reader = getReader(bsb.toByteArray(), 0);
    assertEquals(reader.peekLength(), encodedElements.length + 2);
    reader.readStartSequence();
    assertEquals(reader.peekType(), ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    assertEquals(reader.peekLength(), encodedElements.length);
    reader.readOctetString().equals(ByteString.wrap(encodedElements));
    reader.readEndSequence();
  }
  /**
   * Tests the <CODE>decodeAsSequence</CODE> method that takes a byte array
   * argument with a short array.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeShortArrayAsSequence()
      throws Exception
  {
    byte[] b = new byte[1];
    getReader(b, 0).readStartSequence();
  }
  /**
   * Tests the <CODE>decodeAsSequence</CODE> method that takes a byte array
   * argument with an array that takes too many bytes to encode the length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeLongLengthArrayAsSequence()
      throws Exception
  {
    byte[] b = { 0x30, (byte) 0x85, 0x00, 0x00, 0x00, 0x00, 0x00 };
    getReader(b, 0).readStartSequence();
  }
  /**
   * Tests the <CODE>decodeAsSequence</CODE> method that takes a byte array
   * argument with an array that doesn't fully describe the length.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeTruncatedLengthArrayAsSequence()
      throws Exception
  {
    byte[] b = { 0x30, (byte) 0x82, 0x00 };
    getReader(b, 0).readStartSequence();
  }
  /**
   * Tests the <CODE>readOctetString</CODE> method when the max element size
   * is exceeded.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeOctetStringExceedMaxSize()
      throws Exception
  {
    byte[] b = new byte[] { 0x04, 0x05, 0x48, 0x65, 0x6C, 0x6C, 0x6F };
    getReader(b, 3).readOctetString();
  }
  /**
   * Tests the <CODE>readOctetString</CODE> method when the max element size
   * is exceeded.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeSequenceExceedMaxSize()
      throws Exception
  {
    byte[] b = new byte[] { 0x30, 0x07, 0x04, 0x05, 0x48, 0x65, 0x6C, 0x6C, 0x6F };
    getReader(b, 3).readOctetString();
  }
  /**
   * Tests to make sure a premature EOF while reading a sub sequence can be
   * detected.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testDecodeSequencePrematureEof()
      throws Exception
  {
    // An ASN.1 sequence of booleans missing one boolean element at the end
    byte[] b = new byte[] { 0x30, 0x09, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00 };
    ASN1Reader reader = getReader(b, 0);
    reader.readStartSequence();
    while(reader.hasNextElement())
    {
      reader.readBoolean();
    }
    reader.readEndSequence();
  }
  /**
   * Tests to make sure trailing components are ignored if not used.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test
  public void testDecodeSequenceIncompleteRead()
      throws Exception
  {
    // An ASN.1 sequence of booleans missing one boolean element at the end
    byte[] b = new byte[] { 0x30, 0x06, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 };
    ASN1Reader reader = getReader(b, 0);
    reader.readStartSequence();
    reader.readEndSequence();
    assertFalse(reader.readBoolean());
  }
  /**
   * Tests the <CODE>skipElement</CODE> method.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { DecodeException.class })
  public void testSkipElementIncompleteRead()
      throws Exception
  {
    // An ASN.1 sequence of booleans missing one boolean element at the end
    byte[] b = new byte[] { 0x30, 0x09, 0x01, 0x01, 0x00, 0x01, 0x02 };
    ASN1Reader reader = getReader(b, 0);
    reader.readStartSequence();
    reader.readBoolean();
    reader.skipElement();
    reader.readEndSequence();
  }
  /**
   * Tests the <CODE>skipElement</CODE> method.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test
  public void testSkipElement()
      throws Exception
  {
    // An ASN.1 sequence of booleans missing one boolean element at the end
    byte[] b = new byte[] { 0x30, 0x09, 0x02, 0x01, 0x00, 0x02, 0x01, 0x01,
        0x02, 0x01, 0x02 };
    ASN1Reader reader = getReader(b, 0);
    reader.readStartSequence();
    reader.readInteger();
    reader.skipElement();
    assertEquals(reader.readInteger(), 2);
    reader.readEndSequence();
  }
  /**
   * Tests the <CODE>elementAvailable</CODE> method.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test
  public void testElementAvailable()
      throws Exception
  {
    // An ASN.1 sequence of booleans missing one boolean element at the end
    byte[] b = new byte[] { 0x30, 0x06, 0x02, 0x01, 0x00, 0x02 };
    ASN1Reader reader = getReader(b, 0);
    assertFalse(reader.elementAvailable());
    b = new byte[] { 0x30, 0x03, 0x02, 0x01, 0x00 };
    reader = getReader(b, 0);
    assertTrue(reader.elementAvailable());
    reader.readStartSequence();
    assertTrue(reader.elementAvailable());
    reader.readInteger();
    assertFalse(reader.elementAvailable());
  }
  /**
   * Tests the <CODE>hasNextElement</CODE> method.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test
  public void testHasNextElement()
      throws Exception
  {
    // An ASN.1 sequence of booleans missing one boolean element at the end
    byte[] b = new byte[] { 0x30, 0x06, 0x02, 0x01, 0x00, 0x02, 0x00, 0x03 };
    ASN1Reader reader = getReader(b, 0);
    assertTrue(reader.hasNextElement());
    reader.readStartSequence();
    assertTrue(reader.hasNextElement());
    reader.readInteger();
    assertTrue(reader.hasNextElement());
    b = new byte[] { 0x30, 0x03, 0x02, 0x01, 0x00 };
    reader = getReader(b, 0);
    assertTrue(reader.hasNextElement());
    reader.readStartSequence();
    assertTrue(reader.hasNextElement());
    reader.readInteger();
    assertFalse(reader.hasNextElement());
  }
  /**
   * Tests the <CODE>readEndSequence</CODE> method without first calling
   * readStartSequence.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(expectedExceptions = { IllegalStateException.class })
  public void testReadEndSequenceNoStartSequence() throws Exception
  {
    byte[] b = { 0x30, 0x01, 0x00 };
    getReader(b, 0).readEndSequence();
  }
}
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestAbandonRequestProtocolOp.java
@@ -30,9 +30,9 @@
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.testng.annotations.Test;
import static org.opends.server.protocols.ldap.LDAPConstants.OP_TYPE_ABANDON_REQUEST;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.io.ASN1Reader;
import static org.testng.Assert.*;
public class
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestAddRequestProtocolOp.java
@@ -34,9 +34,9 @@
import java.util.ArrayList;
import java.util.List;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.types.LDAPException;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestAddResponseProtocolOp.java
@@ -26,7 +26,7 @@
 */
package org.opends.server.protocols.ldap;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import static org.opends.server.util.ServerConstants.EOL;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteStringBuilder;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestBindRequestProtocolOp.java
@@ -31,9 +31,9 @@
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.testng.annotations.Test;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
//import org.testng.Reporter;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestBindResponseProtocolOp.java
@@ -32,9 +32,9 @@
import org.opends.server.TestCaseUtils;
import org.forgerock.i18n.LocalizableMessage;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestCompareRequestProtocolOp.java
@@ -30,9 +30,9 @@
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import static org.opends.server.util.ServerConstants.EOL;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestCompareResponseProtocolOp.java
@@ -27,7 +27,7 @@
package org.opends.server.protocols.ldap;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import static org.opends.server.util.ServerConstants.EOL;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestDeleteRequestProtocolOp.java
@@ -33,9 +33,9 @@
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import static org.opends.server.util.ServerConstants.EOL;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
/**
 * This class defines a set of tests for the
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestDeleteResponseProtocolOp.java
@@ -28,7 +28,7 @@
import static org.testng.Assert.*;
import org.testng.annotations.*;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.core.DirectoryServer;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestLDAPFilter.java
@@ -35,9 +35,9 @@
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.TestCaseUtils;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import static org.testng.Assert.*;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestModifyDNRequestProtocolOp.java
@@ -26,7 +26,7 @@
 */
package org.opends.server.protocols.ldap;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import org.opends.server.types.LDAPException;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestModifyDNResponseProtocolOp.java
@@ -29,7 +29,7 @@
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import static org.opends.server.util.ServerConstants.EOL;
import org.opends.server.DirectoryServerTestCase;
import org.forgerock.i18n.LocalizableMessage;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestModifyRequestProtocolOp.java
@@ -32,9 +32,9 @@
import java.util.ArrayList;
import java.util.List;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.types.LDAPException;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestModifyResponseProtocolOp.java
@@ -29,7 +29,7 @@
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import static org.opends.server.util.ServerConstants.EOL;
import org.forgerock.i18n.LocalizableMessage;
import org.testng.annotations.BeforeClass;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestSearchProtocolOp.java
@@ -32,8 +32,7 @@
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.protocols.asn1.*;
import static org.opends.server.protocols.asn1.ASN1Constants.UNIVERSAL_OCTET_STRING_TYPE;
import org.forgerock.opendj.io.*;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
import static org.testng.Assert.*;
@@ -277,7 +276,7 @@
    ASN1Writer writer = ASN1.getWriter(builder);
    writer.writeStartSequence(OP_TYPE_SEARCH_REQUEST);
    writer.writeOctetString(baseDN);
    writer.writeNull(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeNull(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeInteger(dereferencePolicy.intValue());
    writer.writeInteger(sizeLimit);
    writer.writeInteger(timeLimit);
@@ -305,7 +304,7 @@
    writer.writeStartSequence(OP_TYPE_SEARCH_REQUEST);
    writer.writeOctetString(baseDN);
    writer.writeInteger(scope.intValue());
    writer.writeNull(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeNull(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeInteger(sizeLimit);
    writer.writeInteger(timeLimit);
    writer.writeBoolean(typesOnly);
@@ -333,7 +332,7 @@
    writer.writeOctetString(baseDN);
    writer.writeInteger(scope.intValue());
    writer.writeInteger(dereferencePolicy.intValue());
    writer.writeNull(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeNull(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeInteger(timeLimit);
    writer.writeBoolean(typesOnly);
    filter.write(writer);
@@ -361,7 +360,7 @@
    writer.writeInteger(scope.intValue());
    writer.writeInteger(dereferencePolicy.intValue());
    writer.writeInteger(sizeLimit);
    writer.writeNull(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeNull(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeBoolean(typesOnly);
    filter.write(writer);
@@ -389,7 +388,7 @@
    writer.writeInteger(dereferencePolicy.intValue());
    writer.writeInteger(sizeLimit);
    writer.writeInteger(timeLimit);
    writer.writeNull(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeNull(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    filter.write(writer);
    writer.writeStartSequence();
@@ -417,7 +416,7 @@
    writer.writeInteger(sizeLimit);
    writer.writeInteger(timeLimit);
    writer.writeBoolean(typesOnly);
    writer.writeNull(UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeNull(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeStartSequence();
    for(String attribute : attributes)
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestSearchResultEntryProtocolOp.java
@@ -31,7 +31,7 @@
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.TestCaseUtils;
import org.opends.server.protocols.asn1.*;
import org.forgerock.opendj.io.*;
import static org.opends.server.protocols.ldap.LDAPConstants.
     OP_TYPE_SEARCH_RESULT_ENTRY;
import static org.testng.Assert.*;
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestUnbindRequestProtocolOp.java
@@ -26,9 +26,9 @@
 */
package org.opends.server.protocols.ldap;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.opends.server.protocols.asn1.ASN1;
import org.opends.server.protocols.asn1.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.testng.annotations.Test;
import static org.testng.Assert.*;