/** * Compute the Cancel length * * 0x30 L1 * | * +--> 0x02 0x0(1-4) [0..2^31-1] */ public int computeLength() { // The messageId length cancelSequenceLength = 1 + 1 + Value.getNbBytes( cancelId ); // Add the sequence and the length return 1 + 1 + cancelSequenceLength; }
/** * Compute the Cancel length * * 0x30 L1 * | * +--> 0x02 0x0(1-4) [0..2^31-1] */ public int computeLength() { // The messageId length cancelSequenceLength = 1 + 1 + Value.getNbBytes( cancelId ); // Add the sequence and the length return 1 + 1 + cancelSequenceLength; }
/** * Compute the GracefulShutdown length * 0x30 L1 * | * +--> [0x02 0x0(1-4) [0..720] ] * +--> [0x80 0x0(1-3) [0..86400] ] * * L1 will always be < 11. */ public int computeLength() { int gracefulLength = 1 + 1; gracefulSequenceLength = 0; if ( timeOffline != 0 ) { gracefulSequenceLength += 1 + 1 + Value.getNbBytes( timeOffline ); } if ( delay != 0 ) { gracefulSequenceLength += 1 + 1 + Value.getNbBytes( delay ); } return gracefulLength + gracefulSequenceLength; }
/** * Compute the GracefulShutdown length * 0x30 L1 * | * +--> [0x02 0x0(1-4) [0..720] ] * +--> [0x80 0x0(1-3) [0..86400] ] * * L1 will always be < 11. */ public int computeLength() { int gracefulLength = 1 + 1; gracefulSequenceLength = 0; if ( timeOffline != 0 ) { gracefulSequenceLength += 1 + 1 + Value.getNbBytes( timeOffline ); } if ( delay != 0 ) { gracefulSequenceLength += 1 + 1 + Value.getNbBytes( delay ); } return gracefulLength + gracefulSequenceLength; }
/** * Compute the AbandonRequest length * * AbandonRequest : * 0x50 0x0(1..4) abandoned MessageId * * Length(AbandonRequest) = Length(0x50) + 1 + Length(abandoned MessageId) */ protected int computeLengthProtocolOp() { int length = 1 + 1 + Value.getNbBytes( abandonedMessageId ); if ( IS_DEBUG ) { LOGGER.debug( "Message length : {}", Integer.valueOf( length ) ); } return length; }
@Override public int computeLength() { int len = StringTools.getBytesUtf8( targetDN ).length; requestLength = 1 + Value.getNbBytes( len ) + len; len = StringTools.getBytesUtf8( issuerDN ).length; requestLength += 1 + Value.getNbBytes( len ) + len; len = StringTools.getBytesUtf8( subjectDN ).length; requestLength += 1 + Value.getNbBytes( len ) + len; len = StringTools.getBytesUtf8( keyAlgorithm ).length; requestLength += 1 + Value.getNbBytes( len ) + len; return 1 + Value.getNbBytes( requestLength ) + requestLength; }
@Override public int computeLength() { int len = Strings.getBytesUtf8(targetDN).length; requestLength = 1 + Value.getNbBytes( len ) + len; len = Strings.getBytesUtf8(issuerDN).length; requestLength += 1 + Value.getNbBytes( len ) + len; len = Strings.getBytesUtf8(subjectDN).length; requestLength += 1 + Value.getNbBytes( len ) + len; len = Strings.getBytesUtf8(keyAlgorithm).length; requestLength += 1 + Value.getNbBytes( len ) + len; return 1 + Value.getNbBytes( requestLength ) + requestLength; }
/** * Compute the AbandonRequest length * * AbandonRequest : * 0x50 0x0(1..4) abandoned MessageId * * Length(AbandonRequest) = Length(0x50) + 1 + Length(abandoned MessageId) */ public int computeLength() { int length = 1 + 1 + Value.getNbBytes( getAbandoned() ); return length; } }
/** * Encode the Abandon protocolOp part */ protected void encodeProtocolOp( ByteBuffer buffer ) throws EncoderException { try { // The tag buffer.put( LdapConstants.ABANDON_REQUEST_TAG ); // The length. It has to be evaluated depending on // the abandoned messageId value. buffer.put( ( byte ) Value.getNbBytes( abandonedMessageId ) ); // The abandoned messageId buffer.put( Value.getBytes( abandonedMessageId ) ); } catch ( BufferOverflowException boe ) { String msg = I18n.err( I18n.ERR_04005 ); LOGGER.error( msg ); throw new EncoderException( msg ); } }
/** * Encodes the gracefulShutdown extended operation. * * @return A ByteBuffer that contains the encoded PDU * @throws EncoderException If anything goes wrong. */ public ByteBuffer encode() throws EncoderException { // Allocate the bytes buffer. ByteBuffer bb = ByteBuffer.allocate( computeLength() ); bb.put( UniversalTag.SEQUENCE_TAG ); bb.put( TLV.getBytes( gracefulSequenceLength ) ); if ( timeOffline != 0 ) { Value.encode( bb, timeOffline ); } if ( delay != 0 ) { bb.put( ( byte ) GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG ); bb.put( ( byte ) Value.getNbBytes( delay ) ); bb.put( Value.getBytes( delay ) ); } return bb; }
/** * Compute the PagedSearchControl length, which is the sum * of the control length and the value length. * * <pre> * PersistentSearchDecorator value length : * * 0x30 L1 * | * +--> 0x02 0x0(1-4) [0..2^31-1] (changeTypes) * +--> 0x01 0x01 [0x00 | 0xFF] (changeOnly) * +--> 0x01 0x01 [0x00 | 0xFF] (returnRCs) * </pre> */ public int computeLength() { int changeTypesLength = 1 + 1 + Value.getNbBytes( getChangeTypes() ); int changesOnlyLength = 1 + 1 + 1; int returnRCsLength = 1 + 1 + 1; psearchSeqLength = changeTypesLength + changesOnlyLength + returnRCsLength; int valueLength = 1 + TLV.getNbBytes( psearchSeqLength ) + psearchSeqLength; return valueLength; }
/** * Encodes the gracefulShutdown extended operation. * * @return A ByteBuffer that contains the encoded PDU * @throws org.apache.directory.shared.asn1.EncoderException If anything goes wrong. */ public ByteBuffer encode() throws EncoderException { // Allocate the bytes buffer. ByteBuffer bb = ByteBuffer.allocate( computeLength() ); bb.put( UniversalTag.SEQUENCE.getValue() ); bb.put( TLV.getBytes( gracefulSequenceLength ) ); if ( timeOffline != 0 ) { Value.encode( bb, timeOffline ); } if ( delay != 0 ) { bb.put( ( byte ) GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG ); bb.put( ( byte ) Value.getNbBytes( delay ) ); bb.put( Value.getBytes( delay ) ); } return bb; }
/** * Compute the PagedSearchControl length, which is the sum * of the control length and the value length. * * <pre> * PersistentSearchControl value length : * * 0x30 L1 * | * +--> 0x02 0x0(1-4) [0..2^31-1] (changeTypes) * +--> 0x01 0x01 [0x00 | 0xFF] (changeOnly) * +--> 0x01 0x01 [0x00 | 0xFF] (returnRCs) * </pre> */ public int computeLength() { int changeTypesLength = 1 + 1 + Value.getNbBytes( changeTypes ); int changesOnlyLength = 1 + 1 + 1; int returnRCsLength = 1 + 1 + 1; psearchSeqLength = changeTypesLength + changesOnlyLength + returnRCsLength; int valueLength = 1 + TLV.getNbBytes( psearchSeqLength ) + psearchSeqLength; // Call the super class to compute the global control length return super.computeLength( valueLength ); }
/** * Encode the Abandon protocolOp part */ public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { try { // The tag buffer.put( LdapConstants.ABANDON_REQUEST_TAG ); // The length. It has to be evaluated depending on // the abandoned messageId value. buffer.put( ( byte ) Value.getNbBytes( getAbandoned() ) ); // The abandoned messageId buffer.put( Value.getBytes( getAbandoned() ) ); } catch ( BufferOverflowException boe ) { String msg = I18n.err( I18n.ERR_04005 ); throw new EncoderException( msg ); } return buffer; }
/** * Encode a long value * * @param buffer The PDU in which the value will be put * @param value The long to be encoded * @throws EncoderException if the PDU in which the value should be encoded is * two small */ public static void encode( ByteBuffer buffer, long value ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_00003 ) ); } try { buffer.put( UniversalTag.INTEGER_TAG ); buffer.put( ( byte ) getNbBytes( value ) ); buffer.put( getBytes( value ) ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_00004 ) ); } return; }
/** * Encode an integer value * * @param buffer The PDU in which the value will be put * @param tag The tag if it's not an UNIVERSAL one * @param value The integer to be encoded * @throws EncoderException if the PDU in which the value should be encoded is * two small */ public static void encode( ByteBuffer buffer, byte tag, int value ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_00003 ) ); } try { buffer.put( tag ); buffer.put( ( byte ) getNbBytes( value ) ); buffer.put( getBytes( value ) ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_00004 ) ); } return; }
/** * Encode an integer value * * @param buffer The PDU in which the value will be put * @param value The integer to be encoded * @throws EncoderException if the PDU in which the value should be encoded is * two small */ public static void encode( ByteBuffer buffer, int value ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_00003 ) ); } try { buffer.put( UniversalTag.INTEGER_TAG ); buffer.put( ( byte ) getNbBytes( value ) ); buffer.put( getBytes( value ) ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_00004 ) ); } return; }
/** * Encode an enumerated value * * @param buffer The PDU in which the value will be put * @param value The integer to be encoded * @throws EncoderException if the PDU in which the value should be encoded is * two small */ public static void encodeEnumerated( ByteBuffer buffer, int value ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_00003 ) ); } try { buffer.put( UniversalTag.ENUMERATED_TAG ); buffer.put( TLV.getBytes( getNbBytes( value ) ) ); buffer.put( getBytes( value ) ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_00004 ) ); } return; }
/** * Compute the EntryChangeControl length * * 0x30 L1 * | * +--> 0x0A 0x0(1-4) [1|2|4|8] (changeType) * [+--> 0x04 L2 previousDN] * [+--> 0x02 0x0(1-4) [0..2^63-1] (changeNumber)] */ public int computeLength() { int changeTypesLength = 1 + 1 + 1; int previousDnLength = 0; int changeNumberLength = 0; if ( previousDn != null ) { previousDnBytes = StringTools.getBytesUtf8( previousDn.getName() ); previousDnLength = 1 + TLV.getNbBytes( previousDnBytes.length ) + previousDnBytes.length; } if ( changeNumber != UNDEFINED_CHANGE_NUMBER ) { changeNumberLength = 1 + 1 + Value.getNbBytes( changeNumber ); } eccSeqLength = changeTypesLength + previousDnLength + changeNumberLength; valueLength = 1 + TLV.getNbBytes( eccSeqLength ) + eccSeqLength; // Call the super class to compute the global control length return super.computeLength( valueLength ); }
/** * Compute the EntryChangeControl length * * 0x30 L1 * | * +--> 0x0A 0x0(1-4) [1|2|4|8] (changeType) * [+--> 0x04 L2 previousDN] * [+--> 0x02 0x0(1-4) [0..2^63-1] (changeNumber)] */ public int computeLength() { int changeTypesLength = 1 + 1 + 1; int previousDnLength = 0; int changeNumberLength = 0; if ( getPreviousDn() != null ) { previousDnBytes = Strings.getBytesUtf8( getPreviousDn().getName() ); previousDnLength = 1 + TLV.getNbBytes( previousDnBytes.length ) + previousDnBytes.length; } if ( getChangeNumber() != UNDEFINED_CHANGE_NUMBER ) { changeNumberLength = 1 + 1 + Value.getNbBytes( getChangeNumber() ); } eccSeqLength = changeTypesLength + previousDnLength + changeNumberLength; valueLength = 1 + TLV.getNbBytes( eccSeqLength ) + eccSeqLength; return valueLength; }