public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
{
if ( buffer == null )
{
throw new EncoderException( I18n.err( I18n.ERR_148 ) );
}
try
{
// EncTicketPart application tag and length
buffer.put( ( byte ) KerberosConstants.ENC_TICKET_PART_TAG );
buffer.put( TLV.getBytes( encTikcetPartLen ) );
// EncTicketPart sequence tag and length
buffer.put( UniversalTag.SEQUENCE.getValue() );
buffer.put( TLV.getBytes( encTikcetPartSeqLen ) );
// flags tag and int value
buffer.put( ( byte ) KerberosConstants.ENC_TICKET_PART_FLAGS_TAG );
buffer.put( TLV.getBytes( flagsLen ) );
BerValue.encode( buffer, flags );
// key tag and value
buffer.put( ( byte ) KerberosConstants.ENC_TICKET_PART_KEY_TAG );
buffer.put( TLV.getBytes( keyLen ) );
key.encode( buffer );
// crealm tag and value
buffer.put( ( byte ) KerberosConstants.ENC_TICKET_PART_CREALM_TAG );
buffer.put( TLV.getBytes( cRealmLen ) );
buffer.put( UniversalTag.GENERAL_STRING.getValue() );
buffer.put( TLV.getBytes( cRealmBytes.length ) );
buffer.put( cRealmBytes );
// cname tag and value
buffer.put( ( byte ) KerberosConstants.ENC_TICKET_PART_CNAME_TAG );
buffer.put( TLV.getBytes( cNameLen ) );
cName.encode( buffer );
// transited tag and value
buffer.put( ( byte ) KerberosConstants.ENC_TICKET_PART_TRANSITED_TAG );
buffer.put( TLV.getBytes( transitedLen ) );
transited.encode( buffer );
// authtime tag and value
buffer.put( ( byte ) KerberosConstants.ENC_TICKET_PART_AUTHTIME_TAG );
buffer.put( TLV.getBytes( authTimeLen ) );
buffer.put( UniversalTag.GENERALIZED_TIME.getValue() );
buffer.put( ( byte ) 0x0F );
buffer.put( authTimeBytes );
if ( startTime != null )
{
// strattime tag and value
buffer.put( ( byte ) KerberosConstants.ENC_TICKET_PART_STARTTIME_TAG );
buffer.put( TLV.getBytes( startTimeLen ) );
buffer.put( UniversalTag.GENERALIZED_TIME.getValue() );
buffer.put( ( byte ) 0x0F );
buffer.put( startTimeBytes );
}
// endtime tag and value
buffer.put( ( byte ) KerberosConstants.ENC_TICKET_PART_ENDTIME_TAG );
buffer.put( TLV.getBytes( endTimeLen ) );
buffer.put( UniversalTag.GENERALIZED_TIME.getValue() );
buffer.put( ( byte ) 0x0F );
buffer.put( endTimeBytes );
if ( renewtill != null )
{
// renewtill tag and value
buffer.put( ( byte ) KerberosConstants.ENC_TICKET_PART_RENEWTILL_TAG );
buffer.put( TLV.getBytes( renewtillLen ) );
buffer.put( UniversalTag.GENERALIZED_TIME.getValue() );
buffer.put( ( byte ) 0x0F );
buffer.put( renewtillBytes );
}
if ( clientAddresses != null )
{
// caddr tag and value
buffer.put( ( byte ) KerberosConstants.ENC_TICKET_PART_CADDR_TAG );
buffer.put( TLV.getBytes( clientAddressesLen ) );
clientAddresses.encode( buffer );
}
if ( authorizationData != null )
{
// authorization-data tag and value
buffer.put( ( byte ) KerberosConstants.ENC_TICKET_PART_AUTHORIZATION_DATA_TAG );
buffer.put( TLV.getBytes( authzDataLen ) );
authorizationData.encode( buffer );
}
}
catch ( BufferOverflowException boe )
{
log.error( I18n.err( I18n.ERR_742_CANNOT_ENCODE_ENC_TICKET_PART, 1 + TLV.getNbBytes( encTikcetPartLen )
+ encTikcetPartLen, buffer.capacity() ) );
throw new EncoderException( I18n.err( I18n.ERR_138 ) );
}
if ( IS_DEBUG )
{
log.debug( "EncTicketPart encoding : {}", Strings.dumpBytes( buffer.array() ) );