directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1037674 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/ main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/ main/java/org/apache/directory/sha...
Date Mon, 22 Nov 2010 11:18:57 GMT
Author: kayyagari
Date: Mon Nov 22 11:18:56 2010
New Revision: 1037674

URL: http://svn.apache.org/viewvc?rev=1037674&view=rev
Log:
o implementation of EncKrbPrivPart's codec

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/EncKrbPrivPartInit.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreRecipientAddress.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreSenderAddress.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreSeqNumber.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreTimestamp.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreUsec.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreUserData.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKrbPrivPart.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbPrivPartDecoderTest.java

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartContainer.java?rev=1037674&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartContainer.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartContainer.java Mon Nov 22 11:18:56 2010
@@ -0,0 +1,67 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.encKrbPrivPart;
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.kerberos.components.EncKrbPrivPart;
+
+
+/**
+ * The EncKrbPrivPart container stores the EncKrbPrivPart decoded by the Asn1Decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncKrbPrivPartContainer extends AbstractContainer
+{
+    /** An EncKrbPrivPart container */
+    private EncKrbPrivPart encKrbPrivPart;
+    
+    /**
+     * Creates a new EncKrbPrivPartContainer object.
+     */
+    public EncKrbPrivPartContainer()
+    {
+        super();
+        this.stateStack = new int[1];
+        this.grammar = EncKrbPrivPartGrammar.getInstance();
+        setTransition( EncKrbPrivPartStatesEnum.START_STATE );
+    }
+
+
+    /**
+     * @return Returns the EncKrbPrivPart.
+     */
+    public EncKrbPrivPart getEncKrbPrivPart()
+    {
+        return encKrbPrivPart;
+    }
+
+    
+    /**
+     * Set a EncKrbPrivPart Object into the container. It will be completed by the
+     * KerberosDecoder.
+     * 
+     * @param encKrbPrivPart The EncKrbPrivPart to set.
+     */
+    public void setEncKrbPrivPart( EncKrbPrivPart encKrbPrivPart )
+    {
+        this.encKrbPrivPart = encKrbPrivPart;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartGrammar.java?rev=1037674&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartGrammar.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartGrammar.java Mon Nov 22 11:18:56 2010
@@ -0,0 +1,227 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.encKrbPrivPart;
+
+
+import org.apache.directory.shared.asn1.ber.grammar.AbstractGrammar;
+import org.apache.directory.shared.asn1.ber.grammar.Grammar;
+import org.apache.directory.shared.asn1.ber.grammar.GrammarTransition;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.codec.actions.CheckNotNullLength;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.actions.EncKrbPrivPartInit;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.actions.StoreRecipientAddress;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.actions.StoreSenderAddress;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.actions.StoreSeqNumber;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.actions.StoreTimestamp;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.actions.StoreUsec;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.actions.StoreUserData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the EncKrbPrivPart structure. All the actions are declared
+ * in this class. As it is a singleton, these declaration are only done once. If
+ * an action is to be added or modified, this is where the work is to be done !
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public final class EncKrbPrivPartGrammar extends AbstractGrammar
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( EncKrbPrivPartGrammar.class );
+
+    /** A speedup for logger */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. EncKrbPrivPartGrammar is a singleton */
+    private static Grammar instance = new EncKrbPrivPartGrammar();
+
+
+    /**
+     * Creates a new EncKrbPrivPartGrammar object.
+     */
+    private EncKrbPrivPartGrammar()
+    {
+        setName( EncKrbPrivPartGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[EncKrbPrivPartStatesEnum.LAST_ENC_KRB_PRIV_PART_STATE.ordinal()][256];
+
+        // ============================================================================================
+        // EncKrbPrivPart 
+        // ============================================================================================
+        // --------------------------------------------------------------------------------------------
+        // Transition from EncKrbPrivPart init to EncKrbPrivPart tag
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart  ::= [APPLICATION 28] EncKrbPrivPart   ::= SEQUENCE {
+        super.transitions[EncKrbPrivPartStatesEnum.START_STATE.ordinal()][KerberosConstants.ENC_KRB_PRIV_PART_TAG] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.START_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_TAG_STATE, KerberosConstants.ENC_KRB_PRIV_PART_TAG,
+            new EncKrbPrivPartInit() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from EncKrbPrivPart tag to EncKrbPrivPart seq
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart  ::= [APPLICATION 28] SEQUENCE {
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_TAG_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_TAG_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SEQ_TAG_STATE, UniversalTag.SEQUENCE.getValue(),
+            new CheckNotNullLength() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from EncKrbPrivPart seq to user-data tag
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart   ::= SEQUENCE {
+        // user-data       [0]
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SEQ_TAG_STATE.ordinal()][KerberosConstants.ENC_KRB_PRIV_PART_USER_DATA_TAG] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SEQ_TAG_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USER_DATA_TAG_STATE, KerberosConstants.ENC_KRB_PRIV_PART_USER_DATA_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from user-data tag to user-data value
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart   ::= SEQUENCE {
+        // user-data       [0] OCTET STRING
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USER_DATA_TAG_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USER_DATA_TAG_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USER_DATA_STATE, UniversalTag.OCTET_STRING.getValue(),
+            new StoreUserData() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from user-data value to timestamp tag
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart   ::= SEQUENCE {
+        // timestamp       [1]
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USER_DATA_STATE.ordinal()][KerberosConstants.ENC_KRB_PRIV_PART_TIMESTAMP_TAG] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USER_DATA_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_TIMESTAMP_TAG_STATE, KerberosConstants.ENC_KRB_PRIV_PART_TIMESTAMP_TAG,
+            new CheckNotNullLength() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from timestamp tag to timestamp value
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart   ::= SEQUENCE {
+        // timestamp       [1] KerberosTime OPTIONAL
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_TIMESTAMP_TAG_STATE.ordinal()][UniversalTag.GENERALIZED_TIME.getValue()] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_TIMESTAMP_TAG_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_TIMESTAMP_STATE, UniversalTag.GENERALIZED_TIME.getValue(),
+            new StoreTimestamp() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from timestamp value to usec tag
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart   ::= SEQUENCE {
+        // usec            [2]
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_TIMESTAMP_STATE.ordinal()][KerberosConstants.ENC_KRB_PRIV_PART_USEC_TAG] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_TIMESTAMP_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USEC_TAG_STATE, KerberosConstants.ENC_KRB_PRIV_PART_USEC_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from usec tag to usec value
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart   ::= SEQUENCE {
+        // usec            [2] Microseconds OPTIONAL
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USEC_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USEC_TAG_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USEC_STATE, UniversalTag.INTEGER.getValue(),
+            new StoreUsec() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from usec value to seq-number tag
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart   ::= SEQUENCE {
+        // seq-number      [3]
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USEC_STATE.ordinal()][KerberosConstants.ENC_KRB_PRIV_PART_SEQ_NUMBER_TAG] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USEC_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SEQ_NUMBER_TAG_STATE, KerberosConstants.ENC_KRB_PRIV_PART_SEQ_NUMBER_TAG,
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from seq-number tag to seq-number value
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart   ::= SEQUENCE {
+        // seq-number      [3] UInt32 OPTIONAL
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SEQ_NUMBER_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SEQ_NUMBER_TAG_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SEQ_NUMBER_STATE, UniversalTag.INTEGER.getValue(),
+            new StoreSeqNumber() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from seq-number to s-address tag
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart   ::= SEQUENCE {
+        // s-address       [4] HostAddress
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SEQ_NUMBER_STATE.ordinal()][KerberosConstants.ENC_KRB_PRIV_PART_SENDER_ADDRESS_TAG] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SEQ_NUMBER_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SENDER_ADDRESS_TAG_STATE, KerberosConstants.ENC_KRB_PRIV_PART_SENDER_ADDRESS_TAG,
+            new StoreSenderAddress() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from s-address tag to r-address tag
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart   ::= SEQUENCE {
+        // r-address       [5] HostAddress
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SENDER_ADDRESS_TAG_STATE.ordinal()][KerberosConstants.ENC_KRB_PRIV_PART_RECIPIENT_ADDRESS_TAG] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SENDER_ADDRESS_TAG_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_RECIPIENT_ADDRESS_TAG_STATE, KerberosConstants.ENC_KRB_PRIV_PART_RECIPIENT_ADDRESS_TAG,
+            new StoreRecipientAddress() );
+        
+        //----------------------------- OPTIONAL transitions ---------------------------
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from user-data value to usec tag
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart   ::= SEQUENCE {
+        // usec       [2]
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USER_DATA_STATE.ordinal()][KerberosConstants.ENC_KRB_PRIV_PART_USEC_TAG] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USER_DATA_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USEC_TAG_STATE, KerberosConstants.ENC_KRB_PRIV_PART_USEC_TAG,
+            new CheckNotNullLength() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from user-data value to seq-number tag
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart   ::= SEQUENCE {
+        // seq-number       [3]
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USER_DATA_STATE.ordinal()][KerberosConstants.ENC_KRB_PRIV_PART_SEQ_NUMBER_TAG] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USER_DATA_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SEQ_NUMBER_TAG_STATE, KerberosConstants.ENC_KRB_PRIV_PART_SEQ_NUMBER_TAG,
+            new CheckNotNullLength() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from user-data value to s-address tag
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart   ::= SEQUENCE {
+        // s-address       [4]
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USER_DATA_STATE.ordinal()][KerberosConstants.ENC_KRB_PRIV_PART_SENDER_ADDRESS_TAG] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USER_DATA_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SENDER_ADDRESS_TAG_STATE, KerberosConstants.ENC_KRB_PRIV_PART_SENDER_ADDRESS_TAG,
+            new StoreSenderAddress() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from usec value to s-address tag
+        // --------------------------------------------------------------------------------------------
+        // EncKrbPrivPart   ::= SEQUENCE {
+        // s-address       [4]
+        super.transitions[EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USEC_STATE.ordinal()][KerberosConstants.ENC_KRB_PRIV_PART_SENDER_ADDRESS_TAG] = new GrammarTransition(
+            EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_USEC_STATE, EncKrbPrivPartStatesEnum.ENC_KRB_PRIV_PART_SENDER_ADDRESS_TAG_STATE, KerberosConstants.ENC_KRB_PRIV_PART_SENDER_ADDRESS_TAG,
+            new StoreSenderAddress() );
+    }
+
+
+    /**
+     * Get the instance of this grammar
+     * 
+     * @return An instance on the EncKrbPrivPart Grammar
+     */
+    public static Grammar getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartStatesEnum.java?rev=1037674&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartStatesEnum.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/EncKrbPrivPartStatesEnum.java Mon Nov 22 11:18:56 2010
@@ -0,0 +1,124 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.encKrbPrivPart;
+
+
+import org.apache.directory.shared.asn1.ber.grammar.Grammar;
+import org.apache.directory.shared.asn1.ber.grammar.States;
+import org.apache.directory.shared.kerberos.codec.KerberosMessageGrammar;
+
+
+/**
+ * This class stores the EncKrbPrivPart grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum EncKrbPrivPartStatesEnum implements States
+{
+    // Start
+    START_STATE,                                // 0
+    
+    // ----- KRB-ERROR component --------------------------------------
+    
+    ENC_KRB_PRIV_PART_TAG_STATE,                // 2
+    
+    ENC_KRB_PRIV_PART_SEQ_TAG_STATE,                // 3
+    
+    ENC_KRB_PRIV_PART_USER_DATA_TAG_STATE,          // 4
+    ENC_KRB_PRIV_PART_USER_DATA_STATE,              // 5
+    
+    ENC_KRB_PRIV_PART_TIMESTAMP_TAG_STATE,          // 5
+    ENC_KRB_PRIV_PART_TIMESTAMP_STATE,              // 6
+    
+    ENC_KRB_PRIV_PART_USEC_TAG_STATE,               // 7
+    ENC_KRB_PRIV_PART_USEC_STATE,                   // 8
+    
+    ENC_KRB_PRIV_PART_SEQ_NUMBER_TAG_STATE,         // 9
+    ENC_KRB_PRIV_PART_SEQ_NUMBER_STATE,             // 10
+    
+    ENC_KRB_PRIV_PART_SENDER_ADDRESS_TAG_STATE,     // 11
+    
+    ENC_KRB_PRIV_PART_RECIPIENT_ADDRESS_TAG_STATE,  // 12
+
+    // End
+    LAST_ENC_KRB_PRIV_PART_STATE;                   // 13
+
+    
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "ENC_KRB_PRIV_PART_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar grammar )
+    {
+        if ( grammar instanceof KerberosMessageGrammar )
+        {
+            return "ENC_KRB_PRIV_PART_GRAMMAR";
+        }
+        else
+        {
+            return "UNKNOWN GRAMMAR";
+        }
+    }
+
+
+    /**
+     * Get the string representing the state
+     * 
+     * @param state The state number
+     * @return The String representing the state
+     */
+    public String getState( int state )
+    {
+        return ( ( state == LAST_ENC_KRB_PRIV_PART_STATE.ordinal() ) ? "LAST_ENC_KRB_PRIV_PART_STATE" : name() );
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == LAST_ENC_KRB_PRIV_PART_STATE;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public EncKrbPrivPartStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/EncKrbPrivPartInit.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/EncKrbPrivPartInit.java?rev=1037674&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/EncKrbPrivPartInit.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/EncKrbPrivPartInit.java Mon Nov 22 11:18:56 2010
@@ -0,0 +1,83 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.encKrbPrivPart.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.EncKrbPrivPartContainer;
+import org.apache.directory.shared.kerberos.components.EncKrbPrivPart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to initialize the EncKrbPrivPart object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncKrbPrivPartInit extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( EncKrbPrivPartInit.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new EncKrbPrivPartInit action.
+     */
+    public EncKrbPrivPartInit()
+    {
+        super( "Creates a EncKrbPrivPart instance" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        EncKrbPrivPartContainer encKrbPrivPartContainer = ( EncKrbPrivPartContainer ) container;
+
+        TLV tlv = encKrbPrivPartContainer.getCurrentTLV();
+
+        // The Length should not be null
+        if ( tlv.getLength() == 0 )
+        {
+            LOG.error( I18n.err( I18n.ERR_04066 ) );
+
+            // This will generate a PROTOCOL_ERROR
+            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
+        }
+        
+        EncKrbPrivPart encKrbPrivPart = new EncKrbPrivPart();
+        encKrbPrivPartContainer.setEncKrbPrivPart( encKrbPrivPart );
+        
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "EncKrbPrivPart created" );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreRecipientAddress.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreRecipientAddress.java?rev=1037674&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreRecipientAddress.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreRecipientAddress.java Mon Nov 22 11:18:56 2010
@@ -0,0 +1,56 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.shared.kerberos.codec.encKrbPrivPart.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadHostAddress;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.EncKrbPrivPartContainer;
+import org.apache.directory.shared.kerberos.components.HostAddress;
+
+
+/**
+ * Store the r-address of EncKrbPrivPart.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreRecipientAddress extends AbstractReadHostAddress
+{
+
+    public StoreRecipientAddress()
+    {
+        super( "EncKrbPrivPart r-address" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setAddress( HostAddress hostAddress, Asn1Container container )
+    {
+        EncKrbPrivPartContainer encKrbPrivPartContainer = ( EncKrbPrivPartContainer ) container;
+        encKrbPrivPartContainer.getEncKrbPrivPart().setRecipientAddress( hostAddress );
+        
+        container.setGrammarEndAllowed( true );
+    }
+
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreSenderAddress.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreSenderAddress.java?rev=1037674&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreSenderAddress.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreSenderAddress.java Mon Nov 22 11:18:56 2010
@@ -0,0 +1,56 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.shared.kerberos.codec.encKrbPrivPart.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadHostAddress;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.EncKrbPrivPartContainer;
+import org.apache.directory.shared.kerberos.components.HostAddress;
+
+
+/**
+ * Store the s-address of EncKrbPrivPart.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreSenderAddress extends AbstractReadHostAddress
+{
+
+    public StoreSenderAddress()
+    {
+        super( "EncKrbPrivPart s-address" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setAddress( HostAddress hostAddress, Asn1Container container )
+    {
+        EncKrbPrivPartContainer encKrbPrivPartContainer = ( EncKrbPrivPartContainer ) container;
+        encKrbPrivPartContainer.getEncKrbPrivPart().setSenderAddress( hostAddress );
+        
+        container.setGrammarEndAllowed( true );
+    }
+
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreSeqNumber.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreSeqNumber.java?rev=1037674&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreSeqNumber.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreSeqNumber.java Mon Nov 22 11:18:56 2010
@@ -0,0 +1,54 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.encKrbPrivPart.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadInteger;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.EncKrbPrivPartContainer;
+
+
+/**
+ * The action used to store the EncKrbPrivPart seq-number
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreSeqNumber extends AbstractReadInteger
+{
+
+    /**
+     * Instantiates a new StoreSeqNumber action.
+     */
+    public StoreSeqNumber()
+    {
+        super( "EncKrbPrivPart seq-number" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setIntegerValue( int value, Asn1Container container )
+    {
+        EncKrbPrivPartContainer encKrbPrivPartContainer = ( EncKrbPrivPartContainer ) container;
+        encKrbPrivPartContainer.getEncKrbPrivPart().setSeqNumber( value );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreTimestamp.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreTimestamp.java?rev=1037674&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreTimestamp.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreTimestamp.java Mon Nov 22 11:18:56 2010
@@ -0,0 +1,55 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.encKrbPrivPart.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.KerberosTime;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadKerberosTime;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.EncKrbPrivPartContainer;
+
+
+/**
+ * The action used to store the EncKrbPrivPart timemstamp
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreTimestamp extends AbstractReadKerberosTime
+{
+
+    /**
+     * Instantiates a new StoreCTime action.
+     */
+    public StoreTimestamp()
+    {
+        super( "EncKrbPrivPart timemstamp" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setKerberosTime( KerberosTime krbtime, Asn1Container container )
+    {
+        EncKrbPrivPartContainer encKrbPrivPartContainer = ( EncKrbPrivPartContainer ) container;
+        encKrbPrivPartContainer.getEncKrbPrivPart().setTimestamp( krbtime );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreUsec.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreUsec.java?rev=1037674&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreUsec.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreUsec.java Mon Nov 22 11:18:56 2010
@@ -0,0 +1,55 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.encKrbPrivPart.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.kerberos.codec.actions.AbstractReadInteger;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.EncKrbPrivPartContainer;
+
+
+/**
+ * The action used to store the EncKrbPrivPart usec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreUsec extends AbstractReadInteger
+{
+
+    /**
+     * Instantiates a new StoreUsec action.
+     */
+    public StoreUsec()
+    {
+        super( "EncKrbPrivPart usec" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setIntegerValue( int value, Asn1Container container )
+    {
+        EncKrbPrivPartContainer encKrbPrivPartContainer = ( EncKrbPrivPartContainer ) container;
+        encKrbPrivPartContainer.getEncKrbPrivPart().setUsec( value );
+    }
+
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreUserData.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreUserData.java?rev=1037674&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreUserData.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/encKrbPrivPart/actions/StoreUserData.java Mon Nov 22 11:18:56 2010
@@ -0,0 +1,88 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.kerberos.codec.encKrbPrivPart.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.EncKrbPrivPartContainer;
+import org.apache.directory.shared.kerberos.components.EncKrbPrivPart;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to read the EncKrbPrivPart user-data
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreUserData extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( StoreUserData.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new StoreUserData action.
+     */
+    public StoreUserData()
+    {
+        super( "EncKrbPrivPart user-data" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public final void action( Asn1Container container ) throws DecoderException
+    {
+        EncKrbPrivPartContainer encKrbPrivPartContainer = ( EncKrbPrivPartContainer ) container;
+        
+        TLV tlv = encKrbPrivPartContainer.getCurrentTLV();
+
+        // The Length should not be null
+        if ( tlv.getLength() == 0 )
+        {
+            LOG.error( I18n.err( I18n.ERR_04066 ) );
+
+            // This will generate a PROTOCOL_ERROR
+            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
+        }
+        
+        // The value is the realm
+        Value value = tlv.getValue();
+
+        EncKrbPrivPart encKrbPrivPart = encKrbPrivPartContainer.getEncKrbPrivPart();
+        encKrbPrivPart.setUserData( value.getData() );
+        
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "user-data: " + StringTools.dumpBytes( value.getData() ) );
+        }
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKrbPrivPart.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKrbPrivPart.java?rev=1037674&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKrbPrivPart.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/components/EncKrbPrivPart.java Mon Nov 22 11:18:56 2010
@@ -0,0 +1,398 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.shared.kerberos.components;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.shared.asn1.AbstractAsn1Object;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.KerberosConstants;
+import org.apache.directory.shared.kerberos.KerberosTime;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * EncKrbPrivPart  ::= [APPLICATION 28] SEQUENCE {
+ *      user-data       [0] OCTET STRING,
+ *      timestamp       [1] KerberosTime OPTIONAL,
+ *      usec            [2] Microseconds OPTIONAL,
+ *      seq-number      [3] UInt32 OPTIONAL,
+ *      s-address       [4] HostAddress -- sender's addr --,
+ *      r-address       [5] HostAddress OPTIONAL -- recip's addr
+ * }
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+//NOTE: this ASN.1 structure is quite identical to KrbSafeBody
+public class EncKrbPrivPart extends AbstractAsn1Object
+{
+    /** The logger */
+    private static final Logger log = LoggerFactory.getLogger( EncKrbPrivPart.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = log.isDebugEnabled();
+
+    /** the user data */
+    private byte[] userData;
+
+    /** the current time of the sender */
+    private KerberosTime timestamp;
+
+    /** the microsecond part of the timestamp */
+    private Integer usec;
+
+    /** the sequence number */
+    private Integer seqNumber;
+
+    /** the sender's address */
+    private HostAddress senderAddress;
+
+    /** the recipient's address */
+    private HostAddress recipientAddress;
+
+    private transient int userDataLen;
+    private transient int timestampLen;
+    private transient int usecLen;
+    private transient int seqNumberLen;
+    private transient int senderAddressLen;
+    private transient int recipientAddressLen;
+    private transient int encKrbPrivPartSeqLen;
+    private transient int encKrbPrivPartLen;
+
+    /**
+     * Compute the EncKrbPrivPart length:
+     * 
+     * <pre>
+     * 0x7C L0 EncKrbPrivPart
+     *  |
+     *  |
+     * 0x30 L1 EncKrbPrivPart SEQ
+     *  |
+     *  +--> 0xA0 L2 user-data tag
+     *  |     |
+     *  |     +--> 0x04 L2-1 user-data (Octet String)
+     *  |
+     *  +--> 0xA1 0x11 timestamp tag
+     *  |     |
+     *  |     +--> 0x18 0x0F timestamp (KerberosTime)
+     *  |
+     *  +--> 0xA2 L3 usec tag
+     *  |     |
+     *  |     +--> 0x02 L3-1 usec (Microseconds)
+     *  |
+     *  +--> 0xA3 L4 seq-number tag
+     *  |     |
+     *  |     +--> 0x02 L4-1 seqnumber (UInt32)
+     *  |
+     *  +--> 0xA4 L5 s-address tag
+     *  |     |
+     *  |     +--> 0x30 L5-1 s-address (HostAddress)
+     *  |
+     *  +--> 0xA5 L6 r-address tag
+     *        |
+     *        +--> 0x30 L6-1 r-address (HostAddress)
+     * </pre>       
+     */
+    @Override
+    public int computeLength()
+    {
+        userDataLen = 1 + TLV.getNbBytes( userData.length ) + userData.length;
+        encKrbPrivPartSeqLen = 1 + TLV.getNbBytes( userDataLen ) + userDataLen;
+
+        senderAddressLen = senderAddress.computeLength();
+        encKrbPrivPartSeqLen += 1 + TLV.getNbBytes( senderAddressLen ) + senderAddressLen;
+
+        if ( timestamp != null )
+        {
+            timestampLen = timestamp.getBytes().length;
+            timestampLen = 1 + TLV.getNbBytes( timestampLen ) + timestampLen;
+            encKrbPrivPartSeqLen += 1 + TLV.getNbBytes( timestampLen ) + timestampLen;
+        }
+
+        if ( usec != null )
+        {
+            usecLen = Value.getNbBytes( usec );
+            usecLen = 1 + TLV.getNbBytes( usecLen ) + usecLen;
+            encKrbPrivPartSeqLen += 1 + TLV.getNbBytes( usecLen ) + usecLen;
+        }
+
+        if ( seqNumber != null )
+        {
+            seqNumberLen = Value.getNbBytes( seqNumber );
+            seqNumberLen = 1 + TLV.getNbBytes( seqNumberLen ) + seqNumberLen;
+            encKrbPrivPartSeqLen += 1 + TLV.getNbBytes( seqNumberLen ) + seqNumberLen;
+        }
+
+        if ( recipientAddress != null )
+        {
+            recipientAddressLen = recipientAddress.computeLength();
+            encKrbPrivPartSeqLen += 1 + TLV.getNbBytes( recipientAddressLen ) + recipientAddressLen;
+        }
+
+        encKrbPrivPartLen = 1 + TLV.getNbBytes( encKrbPrivPartSeqLen ) + encKrbPrivPartSeqLen;
+        
+        return 1 + TLV.getNbBytes( encKrbPrivPartLen ) + encKrbPrivPartLen;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_148 ) );
+        }
+
+        try
+        {
+            buffer.put( ( byte ) KerberosConstants.ENC_KRB_PRIV_PART_TAG );
+            buffer.put( TLV.getBytes( encKrbPrivPartLen ) );
+            
+            buffer.put( UniversalTag.SEQUENCE.getValue() );
+            buffer.put( TLV.getBytes( encKrbPrivPartSeqLen ) );
+
+            // user-data
+            buffer.put( ( byte ) KerberosConstants.KRB_SAFE_BODY_USER_DATA_TAG );
+            buffer.put( TLV.getBytes( userDataLen ) );
+            Value.encode( buffer, userData );
+
+            if ( timestamp != null )
+            {
+                // timestamp tag
+                buffer.put( ( byte ) KerberosConstants.KRB_SAFE_BODY_TIMESTAMP_TAG );
+                buffer.put( TLV.getBytes( timestampLen ) );
+
+                // timestamp value
+                buffer.put( ( byte ) UniversalTag.GENERALIZED_TIME.getValue() );
+                buffer.put( ( byte ) 0x0F );
+                buffer.put( timestamp.getBytes() );
+            }
+
+            if ( usec != null )
+            {
+                // usec
+                buffer.put( ( byte ) KerberosConstants.KRB_SAFE_BODY_USEC_TAG );
+                buffer.put( TLV.getBytes( usecLen ) );
+                Value.encode( buffer, usec );
+            }
+
+            if ( seqNumber != null )
+            {
+                // seq-number
+                buffer.put( ( byte ) KerberosConstants.KRB_SAFE_BODY_SEQ_NUMBER_TAG );
+                buffer.put( TLV.getBytes( seqNumberLen ) );
+                Value.encode( buffer, seqNumber );
+            }
+
+            // s-address
+            buffer.put( ( byte ) KerberosConstants.KRB_SAFE_BODY_SENDER_ADDRESS_TAG );
+            buffer.put( TLV.getBytes( senderAddressLen ) );
+            senderAddress.encode( buffer );
+
+            if ( recipientAddress != null )
+            {
+                // s-address
+                buffer.put( ( byte ) KerberosConstants.KRB_SAFE_BODY_RECIPIENT_ADDRESS_TAG );
+                buffer.put( TLV.getBytes( recipientAddressLen ) );
+                recipientAddress.encode( buffer );
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            log.error( I18n.err( I18n.ERR_735_CANNOT_ENCODE_KRBSAFEBODY, 1 + TLV.getNbBytes( encKrbPrivPartLen )
+                + encKrbPrivPartLen, buffer.capacity() ) );
+            throw new EncoderException( I18n.err( I18n.ERR_138 ) );
+        }
+
+        if ( IS_DEBUG )
+        {
+            log.debug( "EncKrbPrivPart encoding : {}", StringTools.dumpBytes( buffer.array() ) );
+            log.debug( "EncKrbPrivPart initial value : {}", toString() );
+        }
+
+        return buffer;
+    }
+
+
+    /**
+     * @return the userData
+     */
+    public byte[] getUserData()
+    {
+        return userData;
+    }
+
+
+    /**
+     * @param userData the userData to set
+     */
+    public void setUserData( byte[] userData )
+    {
+        this.userData = userData;
+    }
+
+
+    /**
+     * @return the timestamp
+     */
+    public KerberosTime getTimestamp()
+    {
+        return timestamp;
+    }
+
+
+    /**
+     * @param timestamp the timestamp to set
+     */
+    public void setTimestamp( KerberosTime timestamp )
+    {
+        this.timestamp = timestamp;
+    }
+
+
+    /**
+     * @return the usec
+     */
+    public int getUsec()
+    {
+        if ( usec == null )
+        {
+            return 0;
+        }
+
+        return usec;
+    }
+
+
+    /**
+     * @param usec the usec to set
+     */
+    public void setUsec( int usec )
+    {
+        this.usec = usec;
+    }
+
+
+    /**
+     * @return the seqNumber
+     */
+    public int getSeqNumber()
+    {
+        if ( seqNumber == null )
+        {
+            return 0;
+        }
+
+        return seqNumber;
+    }
+
+
+    /**
+     * @param seqNumber the seqNumber to set
+     */
+    public void setSeqNumber( int seqNumber )
+    {
+        this.seqNumber = seqNumber;
+    }
+
+
+    /**
+     * @return the senderAddress
+     */
+    public HostAddress getSenderAddress()
+    {
+        return senderAddress;
+    }
+
+
+    /**
+     * @param senderAddress the senderAddress to set
+     */
+    public void setSenderAddress( HostAddress senderAddress )
+    {
+        this.senderAddress = senderAddress;
+    }
+
+
+    /**
+     * @return the recipientAddress
+     */
+    public HostAddress getRecipientAddress()
+    {
+        return recipientAddress;
+    }
+
+
+    /**
+     * @param recipientAddress the recipientAddress to set
+     */
+    public void setRecipientAddress( HostAddress recipientAddress )
+    {
+        this.recipientAddress = recipientAddress;
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append( "EncKrbPrivPart : {\n" );
+        sb.append( "    user-data: " ).append( StringTools.dumpBytes( userData ) ).append( '\n' );
+
+        if ( timestamp != null )
+        {
+            sb.append( "    timestamp: " ).append( timestamp.getDate() ).append( '\n' );
+        }
+
+        if ( usec != null )
+        {
+            sb.append( "    usec: " ).append( usec ).append( '\n' );
+        }
+
+        if ( seqNumber != null )
+        {
+            sb.append( "    seq-number: " ).append( seqNumber ).append( '\n' );
+        }
+
+        sb.append( "    s-address: " ).append( senderAddress ).append( '\n' );
+
+        if ( recipientAddress != null )
+        {
+            sb.append( "    r-address: " ).append( recipientAddress ).append( '\n' );
+        }
+
+        sb.append( "}\n" );
+
+        return sb.toString();
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbPrivPartDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbPrivPartDecoderTest.java?rev=1037674&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbPrivPartDecoderTest.java (added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EncKrbPrivPartDecoderTest.java Mon Nov 22 11:18:56 2010
@@ -0,0 +1,505 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.shared.kerberos.codec;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.net.InetAddress;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.kerberos.codec.encKrbPrivPart.EncKrbPrivPartContainer;
+import org.apache.directory.shared.kerberos.components.EncKrbPrivPart;
+import org.apache.directory.shared.kerberos.components.HostAddress;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+
+/**
+ * Test cases for EncKrbPrivPart codec.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EncKrbPrivPartDecoderTest
+{
+    @Test
+    public void testDecodeEncKrbPrivPart() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x49;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x7C, 0x47,
+            0x30, 0x45,
+              (byte)0xA0, 0x4,        // user-data
+                     0x04, 0x02, 0x00, 0x01,
+              (byte)0xA1, 0x11,       // timestamp
+                     0x18, 0xF, '2', '0', '1', '0', '1', '1', '1', '9', '0', '8', '0', '0', '4', '3', 'Z',
+              (byte)0xA2, 0x03,       // usec
+                     0x02, 0x01, 0x01,
+              (byte)0xA3, 0x03,       // seq-number
+                     0x02, 0x01, 0x01,
+              (byte)0xA4, 0xF,        // s-address
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1,
+              (byte)0xA5, 0xF,        // r-adress
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1
+        } );
+
+        String decoded = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+        
+        EncKrbPrivPartContainer container = new EncKrbPrivPartContainer();
+        container.setStream( stream );
+        
+        try
+        {
+            decoder.decode( stream, container );
+        }
+        catch( DecoderException e )
+        {
+            fail();
+        }
+        
+        EncKrbPrivPart encKrbPrivPart = container.getEncKrbPrivPart();
+        
+        String time = "20101119080043Z";
+        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );
+        
+        assertTrue( Arrays.equals( new byte[]{0,1}, encKrbPrivPart.getUserData() ) );
+        assertEquals( time, encKrbPrivPart.getTimestamp().getDate() );
+        assertEquals( 1, encKrbPrivPart.getUsec() );
+        assertEquals( 1, encKrbPrivPart.getSeqNumber() );
+        assertEquals( ad, encKrbPrivPart.getSenderAddress() );
+        assertEquals( ad, encKrbPrivPart.getRecipientAddress() );
+
+        int computedLen = encKrbPrivPart.computeLength();
+        
+        assertEquals( streamLen, computedLen );
+        
+        try
+        {
+            ByteBuffer bb = ByteBuffer.allocate( computedLen );
+            
+            encKrbPrivPart.encode( bb );
+            
+            String encoded = StringTools.dumpBytes( bb.array() );
+            assertEquals( decoded, encoded );
+        }
+        catch( EncoderException e )
+        {
+            fail();
+        }
+    }
+    
+    
+    @Test
+    public void testDecodeEncKrbPrivPartWithoutTimestamp() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x36;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x7C, 0x34,
+            0x30, 0x32,
+              (byte)0xA0, 0x4,        // user-data
+                     0x04, 0x02, 0x00, 0x01,
+                     // NO timestamp
+              (byte)0xA2, 0x03,       // usec
+                     0x02, 0x01, 0x01,
+              (byte)0xA3, 0x03,       // seq-number
+                     0x02, 0x01, 0x01,
+              (byte)0xA4, 0xF,        // s-address
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1,
+              (byte)0xA5, 0xF,        // r-adress
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1
+        } );
+
+        String decoded = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+        
+        EncKrbPrivPartContainer container = new EncKrbPrivPartContainer();
+        container.setStream( stream );
+        
+        try
+        {
+            decoder.decode( stream, container );
+        }
+        catch( DecoderException e )
+        {
+            fail();
+        }
+        
+        EncKrbPrivPart enKrbPrivPart = container.getEncKrbPrivPart();
+        
+        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );
+        
+        assertTrue( Arrays.equals( new byte[]{0,1}, enKrbPrivPart.getUserData() ) );
+        assertNull( enKrbPrivPart.getTimestamp() );
+        assertEquals( 1, enKrbPrivPart.getUsec() );
+        assertEquals( 1, enKrbPrivPart.getSeqNumber() );
+        assertEquals( ad, enKrbPrivPart.getSenderAddress() );
+        assertEquals( ad, enKrbPrivPart.getRecipientAddress() );
+
+        int computedLen = enKrbPrivPart.computeLength();
+        
+        assertEquals( streamLen, computedLen );
+        
+        try
+        {
+            ByteBuffer bb = ByteBuffer.allocate( computedLen );
+            
+            enKrbPrivPart.encode( bb );
+            
+            String encoded = StringTools.dumpBytes( bb.array() );
+            assertEquals( decoded, encoded );
+        }
+        catch( EncoderException e )
+        {
+            fail();
+        }
+    }
+
+    
+    @Test
+    public void testDecodeEncKrbPrivPartWithoutTimestampAndUsec() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x31;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x7C, 0x2F,
+            0x30, 0x2D,
+              (byte)0xA0, 0x4,        // user-data
+                     0x04, 0x02, 0x00, 0x01,
+                     // NO timestamp and usec
+              (byte)0xA3, 0x03,       // seq-number
+                     0x02, 0x01, 0x01,
+              (byte)0xA4, 0xF,        // s-address
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1,
+              (byte)0xA5, 0xF,        // r-adress
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1
+        } );
+
+        String decoded = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+        
+        EncKrbPrivPartContainer container = new EncKrbPrivPartContainer();
+        container.setStream( stream );
+        
+        try
+        {
+            decoder.decode( stream, container );
+        }
+        catch( DecoderException e )
+        {
+            fail();
+        }
+        
+        EncKrbPrivPart encKrbPrivPart = container.getEncKrbPrivPart();
+        
+        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );
+        
+        assertTrue( Arrays.equals( new byte[]{0,1}, encKrbPrivPart.getUserData() ) );
+        assertNull( encKrbPrivPart.getTimestamp() );
+        assertEquals( 0, encKrbPrivPart.getUsec() );
+        assertEquals( 1, encKrbPrivPart.getSeqNumber() );
+        assertEquals( ad, encKrbPrivPart.getSenderAddress() );
+        assertEquals( ad, encKrbPrivPart.getRecipientAddress() );
+
+        int computedLen = encKrbPrivPart.computeLength();
+        
+        assertEquals( streamLen, computedLen );
+        
+        try
+        {
+            ByteBuffer bb = ByteBuffer.allocate( computedLen );
+            
+            encKrbPrivPart.encode( bb );
+            
+            String encoded = StringTools.dumpBytes( bb.array() );
+            assertEquals( decoded, encoded );
+        }
+        catch( EncoderException e )
+        {
+            fail();
+        }
+    }
+
+    
+    @Test
+    public void testDecodeEncKrbPrivPartWithoutTimestampUsecAndSeqNumber() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x2C;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x7C, 0x2A,
+            0x30, 0x28,
+              (byte)0xA0, 0x4,        // user-data
+                     0x04, 0x02, 0x00, 0x01,
+                     // NO timestamp, usec and seq-number
+              (byte)0xA4, 0xF,        // s-address
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1,
+              (byte)0xA5, 0xF,        // r-adress
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1
+        } );
+
+        String decoded = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+        
+        EncKrbPrivPartContainer container = new EncKrbPrivPartContainer();
+        container.setStream( stream );
+        
+        try
+        {
+            decoder.decode( stream, container );
+        }
+        catch( DecoderException e )
+        {
+            e.printStackTrace();
+            fail();
+        }
+        
+        EncKrbPrivPart encKrbPrivPart = container.getEncKrbPrivPart();
+        
+        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );
+        
+        assertTrue( Arrays.equals( new byte[]{0,1}, encKrbPrivPart.getUserData() ) );
+        assertNull( encKrbPrivPart.getTimestamp() );
+        assertEquals( 0, encKrbPrivPart.getUsec() );
+        assertEquals( 0, encKrbPrivPart.getSeqNumber() );
+        assertEquals( ad, encKrbPrivPart.getSenderAddress() );
+        assertEquals( ad, encKrbPrivPart.getRecipientAddress() );
+
+        int computedLen = encKrbPrivPart.computeLength();
+        
+        assertEquals( streamLen, computedLen );
+        
+        try
+        {
+            ByteBuffer bb = ByteBuffer.allocate( computedLen );
+            
+            encKrbPrivPart.encode( bb );
+            
+            String encoded = StringTools.dumpBytes( bb.array() );
+            assertEquals( decoded, encoded );
+        }
+        catch( EncoderException e )
+        {
+            fail();
+        }
+    }
+
+    
+    @Test
+    public void testDecodeEncKrbPrivPartWithoutSequenceNumber() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x44;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x7C, 0x42,
+            0x30, 0x40,
+              (byte)0xA0, 0x4,        // user-data
+                     0x04, 0x02, 0x00, 0x01,
+              (byte)0xA1, 0x11,       // timestamp
+                     0x18, 0xF, '2', '0', '1', '0', '1', '1', '1', '9', '0', '8', '0', '0', '4', '3', 'Z',
+              (byte)0xA2, 0x03,       // usec
+                     0x02, 0x01, 0x01,
+                     // NO seq-number
+              (byte)0xA4, 0xF,        // s-address
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1,
+              (byte)0xA5, 0xF,        // r-adress
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1
+        } );
+
+        String decoded = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+        
+        EncKrbPrivPartContainer container = new EncKrbPrivPartContainer();
+        container.setStream( stream );
+        
+        try
+        {
+            decoder.decode( stream, container );
+        }
+        catch( DecoderException e )
+        {
+            fail();
+        }
+        
+        EncKrbPrivPart encKrbPrivPart = container.getEncKrbPrivPart();
+        
+        String time = "20101119080043Z";
+        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );
+        
+        assertTrue( Arrays.equals( new byte[]{0,1}, encKrbPrivPart.getUserData() ) );
+        assertEquals( time, encKrbPrivPart.getTimestamp().getDate() );
+        assertEquals( 1, encKrbPrivPart.getUsec() );
+        assertEquals( 0, encKrbPrivPart.getSeqNumber() );
+        assertEquals( ad, encKrbPrivPart.getSenderAddress() );
+        assertEquals( ad, encKrbPrivPart.getRecipientAddress() );
+
+        int computedLen = encKrbPrivPart.computeLength();
+        
+        assertEquals( streamLen, computedLen );
+        
+        try
+        {
+            ByteBuffer bb = ByteBuffer.allocate( computedLen );
+            
+            encKrbPrivPart.encode( bb );
+            
+            String encoded = StringTools.dumpBytes( bb.array() );
+            assertEquals( decoded, encoded );
+        }
+        catch( EncoderException e )
+        {
+            fail();
+        }
+    }
+
+    
+    @Test
+    public void testDecodeEncKrbPrivPartWithoutOptionalValues() throws Exception
+    {
+        Asn1Decoder decoder = new Asn1Decoder();
+        
+        int streamLen = 0x1B;
+        ByteBuffer stream = ByteBuffer.allocate( streamLen );
+        stream.put( new byte[]
+        {
+            0x7C, 0x19,
+            0x30, 0x17,
+              (byte)0xA0, 0x4,        // user-data
+                     0x04, 0x02, 0x00, 0x01,
+                     // NO timestamp, usec and seq-number
+              (byte)0xA4, 0xF,        // s-address
+                     0x30, 0x0D,
+                      (byte)0xA0, 0x03,
+                             0x02, 0x01, 0x02,
+                       (byte)0xA1, 0x06,
+                              0x04, 0x04, 127, 0, 0, 1,
+                    // NO r-address
+        } );
+
+        String decoded = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+        
+        EncKrbPrivPartContainer container = new EncKrbPrivPartContainer();
+        container.setStream( stream );
+        
+        try
+        {
+            decoder.decode( stream, container );
+        }
+        catch( DecoderException e )
+        {
+            e.printStackTrace();
+            fail();
+        }
+        
+        EncKrbPrivPart encKrbPrivPart = container.getEncKrbPrivPart();
+        
+        HostAddress ad = new HostAddress( InetAddress.getByName( "127.0.0.1" ) );
+        
+        assertTrue( Arrays.equals( new byte[]{0,1}, encKrbPrivPart.getUserData() ) );
+        assertNull( encKrbPrivPart.getTimestamp() );
+        assertEquals( 0, encKrbPrivPart.getUsec() );
+        assertEquals( 0, encKrbPrivPart.getSeqNumber() );
+        assertEquals( ad, encKrbPrivPart.getSenderAddress() );
+        assertNull( encKrbPrivPart.getRecipientAddress() );
+
+        int computedLen = encKrbPrivPart.computeLength();
+        
+        assertEquals( streamLen, computedLen );
+        
+        try
+        {
+            ByteBuffer bb = ByteBuffer.allocate( computedLen );
+            
+            encKrbPrivPart.encode( bb );
+            
+            String encoded = StringTools.dumpBytes( bb.array() );
+            assertEquals( decoded, encoded );
+        }
+        catch( EncoderException e )
+        {
+            fail();
+        }
+    }
+
+}



Mime
View raw message