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_00005_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_00006_LENGTH_EXTENSION_RESERVED );