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

kenneth_suter
15.34.2007 80c58327faaa4873369f6bb949e62792c2f708e0
opends/src/server/org/opends/server/protocols/asn1/ASN1Element.java
@@ -25,6 +25,7 @@
 *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
 */
package org.opends.server.protocols.asn1;
import org.opends.messages.Message;
@@ -35,8 +36,7 @@
import org.opends.server.api.ProtocolElement;
import org.opends.server.types.ByteString;
import static org.opends.server.messages.MessageHandler.*;
import static org.opends.server.messages.ProtocolMessages.*;
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.*;
@@ -573,15 +573,13 @@
    // a valid ASN.1 element.
    if (encodedElement == null)
    {
      int    msgID   = MSGID_ASN1_NULL_ELEMENT;
      String message = getMessage(msgID);
      throw new ASN1Exception(msgID, message);
      Message message = ERR_ASN1_NULL_ELEMENT.get();
      throw new ASN1Exception(message);
    }
    else if (encodedElement.length < 2)
    {
      int    msgID   = MSGID_ASN1_SHORT_ELEMENT;
      String message = getMessage(msgID, encodedElement.length);
      throw new ASN1Exception(msgID, message);
      Message message = ERR_ASN1_SHORT_ELEMENT.get(encodedElement.length);
      throw new ASN1Exception(message);
    }
@@ -595,15 +593,13 @@
      int numLengthBytes = length;
      if (numLengthBytes > 4)
      {
        int    msgID   = MSGID_ASN1_INVALID_NUM_LENGTH_BYTES;
        String message = getMessage(msgID, numLengthBytes);
        throw new ASN1Exception(msgID, message);
        Message message = ERR_ASN1_INVALID_NUM_LENGTH_BYTES.get(numLengthBytes);
        throw new ASN1Exception(message);
      }
      else if (encodedElement.length < (2 + numLengthBytes))
      {
        int    msgID   = MSGID_ASN1_TRUNCATED_LENGTH;
        String message = getMessage(msgID, numLengthBytes);
        throw new ASN1Exception(msgID, message);
        Message message = ERR_ASN1_TRUNCATED_LENGTH.get(numLengthBytes);
        throw new ASN1Exception(message);
      }
      length = 0x00;
@@ -619,10 +615,9 @@
    // in the value.
    if ((encodedElement.length - valueStartPos) != length)
    {
      int    msgID   = MSGID_ASN1_LENGTH_MISMATCH;
      String message = getMessage(msgID, length,
                                  (encodedElement.length - valueStartPos));
      throw new ASN1Exception(msgID, message);
      Message message = ERR_ASN1_LENGTH_MISMATCH.get(
          length, (encodedElement.length - valueStartPos));
      throw new ASN1Exception(message);
    }
@@ -658,16 +653,14 @@
    // a valid ASN.1 element.
    if (encodedElement == null)
    {
      int    msgID   = MSGID_ASN1_NULL_ELEMENT;
      String message = getMessage(msgID);
      throw new ASN1Exception(msgID, message);
      Message message = ERR_ASN1_NULL_ELEMENT.get();
      throw new ASN1Exception(message);
    }
    else if ((startPos < 0) || (startPos+length > encodedElement.length) ||
             (length < 2))
    {
      int    msgID   = MSGID_ASN1_SHORT_ELEMENT;
      String message = getMessage(msgID, encodedElement.length);
      throw new ASN1Exception(msgID, message);
      Message message = ERR_ASN1_SHORT_ELEMENT.get(encodedElement.length);
      throw new ASN1Exception(message);
    }
@@ -681,15 +674,13 @@
      int numLengthBytes = elementLength;
      if (numLengthBytes > 4)
      {
        int    msgID   = MSGID_ASN1_INVALID_NUM_LENGTH_BYTES;
        String message = getMessage(msgID, numLengthBytes);
        throw new ASN1Exception(msgID, message);
        Message message = ERR_ASN1_INVALID_NUM_LENGTH_BYTES.get(numLengthBytes);
        throw new ASN1Exception(message);
      }
      else if (startPos+length < (2 + numLengthBytes))
      {
        int    msgID   = MSGID_ASN1_TRUNCATED_LENGTH;
        String message = getMessage(msgID, numLengthBytes);
        throw new ASN1Exception(msgID, message);
        Message message = ERR_ASN1_TRUNCATED_LENGTH.get(numLengthBytes);
        throw new ASN1Exception(message);
      }
      elementLength = 0x00;
@@ -705,10 +696,9 @@
    // in the value.
    if ((startPos+length - valueStartPos) != elementLength)
    {
      int    msgID   = MSGID_ASN1_LENGTH_MISMATCH;
      String message = getMessage(msgID, elementLength,
                                  (startPos+length - valueStartPos));
      throw new ASN1Exception(msgID, message);
      Message message = ERR_ASN1_LENGTH_MISMATCH.get(
          elementLength, (startPos+length - valueStartPos));
      throw new ASN1Exception(message);
    }
@@ -865,9 +855,8 @@
    // Make sure that the element array is not null.
    if (encodedElements == null)
    {
      int    msgID   = MSGID_ASN1_ELEMENT_SET_NULL;
      String message = getMessage(msgID);
      throw new ASN1Exception(msgID, message);
      Message message = ERR_ASN1_ELEMENT_SET_NULL.get();
      throw new ASN1Exception(message);
    }
@@ -880,9 +869,8 @@
      byte type = encodedElements[startPos++];
      if (startPos >= encodedElements.length)
      {
        int    msgID   = MSGID_ASN1_ELEMENT_SET_NO_LENGTH;
        String message = getMessage(msgID);
        throw new ASN1Exception(msgID, message);
        Message message = ERR_ASN1_ELEMENT_SET_NO_LENGTH.get();
        throw new ASN1Exception(message);
      }
@@ -893,16 +881,16 @@
        int numLengthBytes = length;
        if (numLengthBytes > 4)
        {
          int    msgID   = MSGID_ASN1_ELEMENT_SET_INVALID_NUM_LENGTH_BYTES;
          String message = getMessage(msgID, numLengthBytes);
          throw new ASN1Exception(msgID, message);
          Message message =
              ERR_ASN1_ELEMENT_SET_INVALID_NUM_LENGTH_BYTES.get(numLengthBytes);
          throw new ASN1Exception(message);
        }
        if (numLengthBytes > encodedElements.length - startPos)
        {
          int    msgID   = MSGID_ASN1_ELEMENT_SET_TRUNCATED_LENGTH;
          String message = getMessage(msgID, numLengthBytes);
          throw new ASN1Exception(msgID, message);
          Message message =
              ERR_ASN1_ELEMENT_SET_TRUNCATED_LENGTH.get(numLengthBytes);
          throw new ASN1Exception(message);
        }
        length = 0x00;
@@ -916,10 +904,9 @@
      // Make sure that there are at least enough bytes to hold the value.
      if (length > encodedElements.length - startPos)
      {
        int    msgID   = MSGID_ASN1_ELEMENT_SET_TRUNCATED_VALUE;
        String message = getMessage(msgID, length,
                                    (encodedElements.length-startPos));
        throw new ASN1Exception(msgID, message);
        Message message = ERR_ASN1_ELEMENT_SET_TRUNCATED_VALUE.get(
            length, (encodedElements.length-startPos));
        throw new ASN1Exception(message);
      }