| | |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.protocols.asn1; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | 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.*; |
| | |
| | | { |
| | | if ((value != null) && (value.length != 0)) |
| | | { |
| | | int msgID = MSGID_ASN1_NULL_SET_VALUE_INVALID_LENGTH; |
| | | String message = getMessage(msgID, value.length); |
| | | throw new ASN1Exception(msgID, message); |
| | | Message message = |
| | | ERR_ASN1_NULL_SET_VALUE_INVALID_LENGTH.get(value.length); |
| | | throw new ASN1Exception(message); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | if (element == null) |
| | | { |
| | | int msgID = MSGID_ASN1_NULL_DECODE_ELEMENT_NULL; |
| | | String message = getMessage(msgID); |
| | | throw new ASN1Exception(msgID, message); |
| | | Message message = ERR_ASN1_NULL_DECODE_ELEMENT_NULL.get(); |
| | | throw new ASN1Exception(message); |
| | | } |
| | | |
| | | byte[] value = element.value(); |
| | | if (value.length != 0) |
| | | { |
| | | int msgID = MSGID_ASN1_NULL_DECODE_ELEMENT_INVALID_LENGTH; |
| | | String message = getMessage(msgID, value.length); |
| | | throw new ASN1Exception(msgID, message); |
| | | Message message = |
| | | ERR_ASN1_NULL_DECODE_ELEMENT_INVALID_LENGTH.get(value.length); |
| | | throw new ASN1Exception(message); |
| | | } |
| | | |
| | | return new ASN1Null(element.getType()); |
| | |
| | | // a valid ASN.1 null element. |
| | | if (encodedElement == null) |
| | | { |
| | | int msgID = MSGID_ASN1_NULL_DECODE_ARRAY_NULL; |
| | | String message = getMessage(msgID); |
| | | throw new ASN1Exception(msgID, message); |
| | | Message message = ERR_ASN1_NULL_DECODE_ARRAY_NULL.get(); |
| | | throw new ASN1Exception(message); |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | |
| | |
| | | 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; |
| | |
| | | // 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); |
| | | } |
| | | |
| | | |
| | | // Make sure that the decoded length is exactly zero byte. |
| | | if (length != 0) |
| | | { |
| | | int msgID = MSGID_ASN1_NULL_DECODE_ARRAY_INVALID_LENGTH; |
| | | String message = getMessage(msgID, length); |
| | | throw new ASN1Exception(msgID, message); |
| | | Message message = ERR_ASN1_NULL_DECODE_ARRAY_INVALID_LENGTH.get(length); |
| | | throw new ASN1Exception(message); |
| | | } |
| | | |
| | | |