use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class WhoAmIResponseTest method testDecodeWhoAmINull.
/**
* Test the normal WhoAmI response message
*/
@Test
public void testDecodeWhoAmINull() {
Asn1Decoder whoAmIResponseDecoder = new WhoAmIResponseDecoder();
ByteBuffer stream = ByteBuffer.allocate(0x00);
stream.put(new byte[] {}).flip();
Strings.dumpBytes(stream.array());
// Allocate a WhoAmI Container
Asn1Container whoAmIResponseContainer = new WhoAmIResponseContainer();
// Decode a WhoAmI message
try {
whoAmIResponseDecoder.decode(stream, whoAmIResponseContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
WhoAmIResponseDecorator whoAmIResponse = ((WhoAmIResponseContainer) whoAmIResponseContainer).getWhoAmIResponse();
assertNull(whoAmIResponse);
}
use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class ApiAsn1BerOsgiTest method useBundleClasses.
@Override
protected void useBundleClasses() throws Exception {
new CheckNotNullLength<Asn1Container>();
new Asn1Decoder().getMaxLengthLength();
new BerValue().init(5);
new TLV(1).getValue();
}
use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class Asn1Decoder method treatTagStartState.
/**
* Treat the start of a TLV. It reads the tag and get its value.
*
* @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>true</code> if there are more bytes to read, <code>false
* </code> otherwise
*/
private boolean treatTagStartState(ByteBuffer stream, Asn1Container container) {
if (stream.hasRemaining()) {
byte octet = stream.get();
TLV tlv = new TLV(container.getNewTlvId());
tlv.setTag(octet);
// Store the current TLV in the container.
container.setCurrentTLV(tlv);
// Create a link between the current TLV with its parent
tlv.setParent(container.getParentTLV());
// Switch to the next state, which is the Length decoding
container.setState(TLVStateEnum.LENGTH_STATE_START);
if (IS_DEBUG) {
byte tag = container.getCurrentTLV().getTag();
LOG.debug(I18n.msg(I18n.MSG_01000_TAG_DECODED, Asn1StringUtils.dumpByte(tag)));
}
return MORE;
} else {
// The stream has been exhausted
return END;
}
}
use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class Asn1Decoder method treatLengthStartState.
/**
* Treat the Length start. The tag has been decoded, so we have to deal with
* the LENGTH, which can be multi-bytes.
*
* @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>true</code> if there are more bytes to read, <code>false
* </code> otherwise
* @throws DecoderException Thrown if anything went wrong
*/
private boolean treatLengthStartState(ByteBuffer stream, Asn1Container container) throws DecoderException {
if (stream.hasRemaining()) {
byte octet = stream.get();
TLV tlv = container.getCurrentTLV();
if ((octet & TLV.LENGTH_LONG_FORM) == 0) {
// We don't have a long form. The Length of the Value part is
// given by this byte.
tlv.setLength(octet);
tlv.setLengthNbBytes(1);
container.setState(TLVStateEnum.LENGTH_STATE_END);
} else if ((octet & TLV.LENGTH_EXTENSION_RESERVED) != TLV.LENGTH_EXTENSION_RESERVED) {
int expectedLength = octet & TLV.LENGTH_SHORT_MASK;
if (expectedLength > 4) {
String msg = I18n.err(I18n.ERR_01000_LENGTH_OVERFLOW);
LOG.error(msg);
throw new DecoderException(msg);
}
tlv.setLength(0);
tlv.setLengthNbBytes(1 + expectedLength);
tlv.setLengthBytesRead(1);
container.setState(TLVStateEnum.LENGTH_STATE_PENDING);
} else {
String msg = I18n.err(I18n.ERR_01001_LENGTH_EXTENSION_RESERVED);
LOG.error(msg);
throw new DecoderException(msg);
}
return MORE;
} else {
return END;
}
}
use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class LdapResultTest method testDecodeAddResponseEmptyResultCodeNoMatchedDN.
/**
* Test the decoding of a AddResponse with no matched Dn
*/
@Test
public void testDecodeAddResponseEmptyResultCodeNoMatchedDN() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x0A);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x08, 0x02, 0x01, // messageID MessageID
0x01, 0x69, // CHOICE { ..., addResponse AddResponse, ...
0x03, 0x0A, 0x01, // resultCode success
0x00 });
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a AddResponse message
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
Aggregations