001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.shared.kerberos.messages; 021 022 023import java.nio.ByteBuffer; 024 025import org.apache.directory.api.asn1.EncoderException; 026import org.apache.directory.api.asn1.ber.tlv.TLV; 027import org.apache.directory.shared.kerberos.KerberosConstants; 028import org.apache.directory.shared.kerberos.KerberosMessageType; 029import org.apache.directory.shared.kerberos.components.EncKdcRepPart; 030 031 032/** 033 * EncTGSRepPart message. 034 * It will store the object described by the ASN.1 grammar : 035 * <pre> 036 * EncTGSRepPart ::= [APPLICATION 26] EncKDCRepPart 037 * </pre> 038 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 039 */ 040public class EncTgsRepPart extends KerberosMessage 041{ 042 /** The EncKdcRepPart */ 043 private EncKdcRepPart encKdcRepPart; 044 045 // Storage for computed lengths 046 private int encKdcRepPartLength; 047 048 049 /** 050 * Creates a new instance of EncTgsRepPart. 051 */ 052 public EncTgsRepPart() 053 { 054 super( KerberosMessageType.ENC_TGS_REP_PART ); 055 } 056 057 058 /** 059 * @return the encKdcRepPart 060 */ 061 public EncKdcRepPart getEncKdcRepPart() 062 { 063 return encKdcRepPart; 064 } 065 066 067 /** 068 * @param encKdcRepPart the encKdcRepPart to set 069 */ 070 public void setEncKdcRepPart( EncKdcRepPart encKdcRepPart ) 071 { 072 this.encKdcRepPart = encKdcRepPart; 073 } 074 075 076 /** 077 * Compute the EncTgsRepPart length 078 * <pre> 079 * EncTgsRepPart : 080 * 081 * 0x7A L1 EncTgsRepPart message 082 * | 083 * +--> 0x30 L2 EncKdcRepPart sequence 084 * </pre> 085 */ 086 public int computeLength() 087 { 088 encKdcRepPartLength = encKdcRepPart.computeLength(); 089 return 1 + TLV.getNbBytes( encKdcRepPartLength ) + encKdcRepPartLength; 090 } 091 092 093 /** 094 * Encode the EncTgsRepPart component 095 * 096 * @param buffer The buffer containing the encoded result 097 * @return The encoded component 098 * @throws EncoderException If the encoding failed 099 */ 100 public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException 101 { 102 if ( buffer == null ) 103 { 104 buffer = ByteBuffer.allocate( computeLength() ); 105 } 106 107 // The EncAsRepPart Tag 108 buffer.put( ( byte ) KerberosConstants.ENC_TGS_REP_PART_TAG ); 109 buffer.put( TLV.getBytes( encKdcRepPartLength ) ); 110 111 // The EncKdcRepPart -------------------------------------------------------- 112 encKdcRepPart.encode( buffer ); 113 114 return buffer; 115 } 116}