| | |
| | | package org.opends.server.protocols.asn1; |
| | | |
| | | import static org.opends.messages.ProtocolMessages.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import static org.opends.server.protocols.ldap.LDAPConstants.*; |
| | | |
| | | import java.io.IOException; |
| | |
| | | import java.util.LinkedList; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import org.opends.server.util.SizeLimitInputStream; |
| | | |
| | | /** |
| | |
| | | final class ASN1InputStreamReader implements ASN1Reader |
| | | { |
| | | |
| | | private static final DebugTracer TRACER = getTracer(); |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | private int state = ELEMENT_READ_STATE_NEED_TYPE; |
| | | private byte peekType = 0; |
| | |
| | | throw new ASN1Exception(message); |
| | | } |
| | | |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("READ ASN.1 BOOLEAN(type=0x%x, length=%d, value=%s)", |
| | | peekType, peekLength, String.valueOf(readByte != 0x00))); |
| | | } |
| | |
| | | intValue = (intValue << 8) | (readByte & 0xFF); |
| | | } |
| | | |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("READ ASN.1 INTEGER(type=0x%x, length=%d, " + |
| | | "value=%d)", peekType, peekLength, intValue)); |
| | | } |
| | |
| | | throw new ASN1Exception(message); |
| | | } |
| | | |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("READ ASN.1 NULL(type=0x%x, length=%d)", |
| | | peekType, peekLength)); |
| | | } |
| | |
| | | bytesNeeded -= bytesRead; |
| | | } |
| | | |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("READ ASN.1 OCTETSTRING(type=0x%x, length=%d)", |
| | | peekType, peekLength)); |
| | | } |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | logger.traceException(e); |
| | | |
| | | str = new String(buffer, 0, peekLength); |
| | | } |
| | | |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("READ ASN.1 OCTETSTRING(type=0x%x, length=%d, " + |
| | | "value=%s)", peekType, peekLength, str)); |
| | | } |
| | |
| | | bytesNeeded -= bytesRead; |
| | | } |
| | | |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("READ ASN.1 OCTETSTRING(type=0x%x, length=%d)", |
| | | peekType, peekLength)); |
| | | } |
| | |
| | | SizeLimitInputStream subStream = |
| | | new SizeLimitInputStream(in, peekLength); |
| | | |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, |
| | | logger.trace( |
| | | String.format("READ ASN.1 SEQUENCE(type=0x%x, length=%d)", |
| | | peekType, peekLength)); |
| | | } |
| | |
| | | SizeLimitInputStream subSq = (SizeLimitInputStream)in; |
| | | if(subSq.getSizeLimit() - subSq.getBytesRead() > 0) |
| | | { |
| | | if(debugEnabled()) |
| | | if(logger.isTraceEnabled()) |
| | | { |
| | | TRACER.debugWarning("Ignoring %d unused trailing bytes in " + |
| | | logger.trace("Ignoring %d unused trailing bytes in " + |
| | | "ASN.1 SEQUENCE", subSq.getSizeLimit() - subSq.getBytesRead()); |
| | | } |
| | | |