use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class AbstractReadInteger method action.
/**
* {@inheritDoc}
*/
@Override
public final void action(E container) throws DecoderException {
TLV tlv = container.getCurrentTLV();
// The Length should not be null
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_01101_NULL_LENGTH);
LOG.error(msg);
// This will generate a PROTOCOL_ERROR
throw new DecoderException(msg);
}
BerValue value = tlv.getValue();
try {
int number = IntegerDecoder.parse(value, minValue, maxValue);
if (IS_DEBUG) {
LOG.debug(I18n.msg(I18n.MSG_01100_INTEGER_VALUE, number));
}
setIntegerValue(number, container);
} catch (IntegerDecoderException ide) {
LOG.error(I18n.err(I18n.ERR_01102_INVALID_INTEGER, Strings.dumpBytes(value.getData()), ide.getLocalizedMessage()));
// This will generate a PROTOCOL_ERROR
throw new DecoderException(ide.getMessage(), ide);
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class CheckNotNullLength method action.
/**
* {@inheritDoc}
*/
@Override
public void action(C container) throws DecoderException {
TLV tlv = container.getCurrentTLV();
// The Length should not be null
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_01101_NULL_LENGTH);
LOG.error(msg);
// This will generate a PROTOCOL_ERROR
throw new DecoderException(msg);
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class Asn1Decoder method isTLVDecoded.
/**
* Check if the TLV tree is fully decoded
*
* @param container The container
* @return <code>true</code> if the TLV has been decoded
*/
private boolean isTLVDecoded(Asn1Container container) {
TLV current = container.getCurrentTLV();
TLV parent = current.getParent();
while (parent != null) {
if (parent.getExpectedLength() != 0) {
return false;
}
parent = parent.getParent();
}
BerValue value = current.getValue();
if ((value != null) && (value.getData() != null)) {
return current.getExpectedLength() == value.getData().length;
} else {
return current.getExpectedLength() == 0;
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class Asn1Decoder method treatValuePendingState.
/**
* Treat a pending Value when we get more bytes in the buffer.
*
* @param stream The ByteBuffer containing the PDU to decode
* @param container The container that stores the current state,
* the result and other informations.
* @return <code>MORE</code> if some bytes remain in the buffer when the
* value has been decoded, <code>END</code> if whe still need to get some
* more bytes.
*/
private boolean treatValuePendingState(ByteBuffer stream, Asn1Container container) {
TLV currentTlv = container.getCurrentTLV();
int length = currentTlv.getLength();
int currentLength = currentTlv.getValue().getCurrentLength();
int nbBytes = stream.remaining();
if ((currentLength + nbBytes) < length) {
currentTlv.getValue().addData(stream);
container.setState(TLVStateEnum.VALUE_STATE_PENDING);
return END;
} else {
int remaining = length - currentLength;
byte[] data = new byte[remaining];
stream.get(data, 0, remaining);
currentTlv.getValue().addData(data);
container.setState(TLVStateEnum.TLV_STATE_DONE);
return MORE;
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class Asn1Decoder method getParentLength.
/**
* A debug function used to dump the expected length stack.
*
* @param tlv The current TLV.
* @return A string which represent the expected length stack.
*/
private String getParentLength(TLV tlv) {
StringBuilder buffer = new StringBuilder();
buffer.append("TLV expected length stack : ");
TLV currentTlv = tlv;
while (true) {
if (currentTlv == null) {
buffer.append(" - null");
break;
} else {
buffer.append(" - ").append(currentTlv.getExpectedLength());
}
currentTlv = currentTlv.getParent();
}
return buffer.toString();
}
Aggregations