@Override
public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
{
if ( buffer == null )
{
throw new EncoderException( I18n.err( I18n.ERR_148 ) );
}
try
{
buffer.put( UniversalTag.SEQUENCE.getValue() );
buffer.put( TLV.getBytes( krbKredInfoSeqLen ) );
//key tag and value
buffer.put( ( byte ) KerberosConstants.KRB_CRED_INFO_KEY_TAG );
buffer.put( TLV.getBytes( keyLen ) );
key.encode( buffer );
if ( pRealm != null )
{
// prealm tag and value
buffer.put( ( byte ) KerberosConstants.KRB_CRED_INFO_PREALM_TAG );
buffer.put( TLV.getBytes( pRealmLen ) );
buffer.put( UniversalTag.GENERAL_STRING.getValue() );
buffer.put( TLV.getBytes( pRealmBytes.length ) );
buffer.put( pRealmBytes );
}
if ( pName != null )
{
// pname tag and value
buffer.put( ( byte ) KerberosConstants.KRB_CRED_INFO_PNAME_TAG );
buffer.put( TLV.getBytes( pNameLen ) );
pName.encode( buffer );
}
if ( ticketFlags != null )
{
// flags tag and value
buffer.put( ( byte ) KerberosConstants.KRB_CRED_INFO_FLAGS_TAG );
buffer.put( TLV.getBytes( ticketFlagsLen ) );
BerValue.encode( buffer, ticketFlags );
}
if ( authTime != null )
{
// authtime tag and value
buffer.put( ( byte ) KerberosConstants.KRB_CRED_INFO_AUTHTIME_TAG );
buffer.put( TLV.getBytes( authTimeLen ) );
buffer.put( ( byte ) UniversalTag.GENERALIZED_TIME.getValue() );
buffer.put( ( byte ) 0x0F );
buffer.put( authTimeBytes );
}
if ( startTime != null )
{
// starttime tag and value
buffer.put( ( byte ) KerberosConstants.KRB_CRED_INFO_STARTTIME_TAG );
buffer.put( TLV.getBytes( startTimeLen ) );
buffer.put( UniversalTag.GENERALIZED_TIME.getValue() );
buffer.put( ( byte ) 0x0F );
buffer.put( startTimeBytes );
}
if ( endTime != null )
{
// endtime tag and value
buffer.put( ( byte ) KerberosConstants.KRB_CRED_INFO_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.KRB_CRED_INFO_RENEWTILL_TAG );
buffer.put( TLV.getBytes( renewtillLen ) );
buffer.put( UniversalTag.GENERALIZED_TIME.getValue() );
buffer.put( ( byte ) 0x0F );
buffer.put( renewtillBytes );
}
if ( sRealm != null )
{
// srealm tag and value
buffer.put( ( byte ) KerberosConstants.KRB_CRED_INFO_SREALM_TAG );
buffer.put( TLV.getBytes( sRealmLen ) );
buffer.put( UniversalTag.GENERAL_STRING.getValue() );
buffer.put( TLV.getBytes( sRealmBytes.length ) );
buffer.put( sRealmBytes );
}
if ( sName != null )
{
// sname tag and value
buffer.put( ( byte ) KerberosConstants.KRB_CRED_INFO_SNAME_TAG );
buffer.put( TLV.getBytes( sNameLen ) );
sName.encode( buffer );
}
if ( clientAddresses != null )
{
// caddr tag and value
buffer.put( ( byte ) KerberosConstants.KRB_CRED_INFO_CADDR_TAG );
buffer.put( TLV.getBytes( clientAddressesLen ) );
clientAddresses.encode( buffer );
}
}
catch ( BufferOverflowException boe )
{
log.error( I18n.err( I18n.ERR_739_CANNOT_ENCODE_KRB_CRED_INFO, 1 + TLV.getNbBytes( krbKredInfoSeqLen )
+ krbKredInfoSeqLen, buffer.capacity() ) );
throw new EncoderException( I18n.err( I18n.ERR_138 ) );
}
if ( IS_DEBUG )
{
log.debug( "KrbCredInfo encoding : {}", Strings.dumpBytes( buffer.array() ) );