use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class LdapDecoderTest method testDecodeSplittedLength.
/**
* Test the decoding of a split Length.
*
* The length is 3 bytes long, but the PDU has been split
* just after the first byte
*/
@Test
public void testDecodeSplittedLength() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(3);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
(byte) 0x82, // LDAPMessage ::=SEQUENCE {
0x01 });
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a BindRequest PDU first block of data
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
assertEquals(TLVStateEnum.LENGTH_STATE_PENDING, ldapMessageContainer.getState());
// Second block of data
stream = ByteBuffer.allocate(1);
stream.put(new byte[] { // End of the length
(byte) 0x80 });
stream.flip();
// Decode a BindRequest PDU second block of data
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
assertEquals(TLVStateEnum.TAG_STATE_START, ldapMessageContainer.getState());
// Check the decoded length
assertEquals(384, ldapMessageContainer.getCurrentTLV().getLength());
}
use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class LdapMessageTest method testDecodeMessageIdLengthNull.
/**
* Test the decoding of null length messageId
*/
@Test
public void testDecodeMessageIdLengthNull() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x04);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x02, 0x02, // messageID MessageID
0x00 });
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a BindRequest PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point !");
}
use of org.apache.directory.api.asn1.ber.Asn1Container in project directory-ldap-api by apache.
the class LdapMessageTest method testDecodeMessageLengthNull.
/**
* Test the decoding of null length messageId
*/
@Test
public void testDecodeMessageLengthNull() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x02);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x00 });
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a BindRequest PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point !");
}
Aggregations