*/
public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
{
if ( buffer == null )
{
throw new EncoderException( I18n.err( I18n.ERR_148 ) );
}
try
{
// The EncKdcRepPart sequence
buffer.put( UniversalTag.SEQUENCE.getValue() );
buffer.put( TLV.getBytes( encKdcRepPartSeqLength ) );
// The Key
buffer.put( ( byte ) KerberosConstants.ENC_KDC_REP_PART_KEY_TAG );
buffer.put( TLV.getBytes( keyLength ) );
key.encode( buffer );
// The LastReq
buffer.put( ( byte ) KerberosConstants.ENC_KDC_REP_PART_LAST_REQ_TAG );
buffer.put( TLV.getBytes( lastReqLength ) );
lastReq.encode( buffer );
// The nonce
buffer.put( ( byte ) KerberosConstants.ENC_KDC_REP_PART_NONCE_TAG );
buffer.put( TLV.getBytes( nonceLength ) );
BerValue.encode( buffer, nonce );
// The key-expiration, if any
if ( keyExpiration != null )
{
buffer.put( ( byte ) KerberosConstants.ENC_KDC_REP_PART_KEY_EXPIRATION_TAG );
buffer.put( TLV.getBytes( 0x11 ) );
buffer.put( UniversalTag.GENERALIZED_TIME.getValue() );
buffer.put( ( byte ) 0x0F );
buffer.put( keyExpiration.getBytes() );
}
// The flags
buffer.put( ( byte ) KerberosConstants.ENC_KDC_REP_PART_FLAGS_TAG );
buffer.put( TLV.getBytes( 0x07 ) );
BerValue.encode( buffer, flags );
// The authtime
buffer.put( ( byte ) KerberosConstants.ENC_KDC_REP_PART_AUTH_TIME_TAG );
buffer.put( TLV.getBytes( 0x11 ) );
buffer.put( UniversalTag.GENERALIZED_TIME.getValue() );
buffer.put( ( byte ) 0x0F );
buffer.put( authTime.getBytes() );
// The starttime if any
if ( startTime != null )
{
buffer.put( ( byte ) KerberosConstants.ENC_KDC_REP_PART_START_TIME_TAG );
buffer.put( TLV.getBytes( 0x11 ) );
buffer.put( UniversalTag.GENERALIZED_TIME.getValue() );
buffer.put( ( byte ) 0x0F );
buffer.put( startTime.getBytes() );
}
// The endtime
buffer.put( ( byte ) KerberosConstants.ENC_KDC_REP_PART_END_TIME_TAG );
buffer.put( TLV.getBytes( 0x11 ) );
buffer.put( UniversalTag.GENERALIZED_TIME.getValue() );
buffer.put( ( byte ) 0x0F );
buffer.put( endTime.getBytes() );
// The renew-till if any
if ( renewTill != null )
{
buffer.put( ( byte ) KerberosConstants.ENC_KDC_REP_PART_RENEW_TILL_TAG );
buffer.put( TLV.getBytes( 0x11 ) );
buffer.put( UniversalTag.GENERALIZED_TIME.getValue() );
buffer.put( ( byte ) 0x0F );
buffer.put( renewTill.getBytes() );
}
// The srealm
buffer.put( ( byte ) KerberosConstants.ENC_KDC_REP_PART_SREALM_TAG );
buffer.put( TLV.getBytes( srealmLength ) );
buffer.put( UniversalTag.GENERAL_STRING.getValue() );
buffer.put( TLV.getBytes( srealmBytes.length ) );
buffer.put( srealmBytes );
// The sname
buffer.put( ( byte ) KerberosConstants.ENC_KDC_REP_PART_SNAME_TAG );
buffer.put( TLV.getBytes( snameLength ) );
sname.encode( buffer );
// The caddr if any
if ( caddr != null )
{
buffer.put( ( byte ) KerberosConstants.ENC_KDC_REP_PART_CADDR_TAG );
buffer.put( TLV.getBytes( caddrLength ) );
caddr.encode( buffer );
}
}
catch ( BufferOverflowException boe )
{
log.error( I18n.err( I18n.ERR_140, 1 + TLV.getNbBytes( 0 ) + 0,
buffer.capacity() ) );
throw new EncoderException( I18n.err( I18n.ERR_138 ) );
}
if ( IS_DEBUG )
{
log.debug( "EncKdcRepPart encoding : {}", Strings.dumpBytes( buffer.array() ) );