View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.shared.kerberos.messages;
21  
22  
23  import java.nio.ByteBuffer;
24  
25  import org.apache.directory.api.asn1.EncoderException;
26  import org.apache.directory.api.asn1.ber.tlv.TLV;
27  import org.apache.directory.shared.kerberos.KerberosConstants;
28  import org.apache.directory.shared.kerberos.KerberosMessageType;
29  import org.apache.directory.shared.kerberos.components.EncKdcRepPart;
30  
31  
32  /**
33   * EncTGSRepPart message. 
34   *  It will store the object described by the ASN.1 grammar :
35   * <pre>
36   * EncTGSRepPart   ::= [APPLICATION 26] EncKDCRepPart
37   * </pre>
38   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
39   */
40  public class EncTgsRepPart extends KerberosMessage
41  {
42      /** The EncKdcRepPart */
43      private EncKdcRepPart encKdcRepPart;
44  
45      // Storage for computed lengths
46      private int encKdcRepPartLength;
47  
48  
49      /**
50       * Creates a new instance of EncTgsRepPart.
51       */
52      public EncTgsRepPart()
53      {
54          super( KerberosMessageType.ENC_TGS_REP_PART );
55      }
56  
57  
58      /**
59       * @return the encKdcRepPart
60       */
61      public EncKdcRepPart getEncKdcRepPart()
62      {
63          return encKdcRepPart;
64      }
65  
66  
67      /**
68       * @param encKdcRepPart the encKdcRepPart to set
69       */
70      public void setEncKdcRepPart( EncKdcRepPart encKdcRepPart )
71      {
72          this.encKdcRepPart = encKdcRepPart;
73      }
74  
75  
76      /**
77       * Compute the EncTgsRepPart length
78       * <pre>
79       * EncTgsRepPart :
80       * 
81       * 0x7A L1 EncTgsRepPart message
82       *  |
83       *  +--&gt;  0x30 L2 EncKdcRepPart sequence
84       * </pre>
85       */
86      public int computeLength()
87      {
88          encKdcRepPartLength = encKdcRepPart.computeLength();
89          return 1 + TLV.getNbBytes( encKdcRepPartLength ) + encKdcRepPartLength;
90      }
91  
92  
93      /**
94       * Encode the EncTgsRepPart component
95       * 
96       * @param buffer The buffer containing the encoded result
97       * @return The encoded component
98       * @throws EncoderException If the encoding failed
99       */
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 }