directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1038118 - in /directory/apacheds/trunk/kerberos-codec/src: main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/actions/ test/java/org/apache/directory/shared/kerber...
Date Tue, 23 Nov 2010 13:57:16 GMT
Author: elecharny
Date: Tue Nov 23 13:57:16 2010
New Revision: 1038118

URL: http://svn.apache.org/viewvc?rev=1038118&view=rev
Log:
Added the ETYPE-INFO codec

Added:
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoContainer.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoGrammar.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoStatesEnum.java
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/actions/
    directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/actions/AddETypeInfoEntry.java
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EtypeInfoDecoderTest.java

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoContainer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoContainer.java?rev=1038118&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoContainer.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoContainer.java
Tue Nov 23 13:57:16 2010
@@ -0,0 +1,79 @@
+/*
+ *  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.etypeInfo;
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+import org.apache.directory.shared.kerberos.components.ETypeInfo;
+import org.apache.directory.shared.kerberos.components.ETypeInfoEntry;
+
+
+/**
+ * The ETypeInfo container stores the ETYPE-INFO decoded by the Asn1Decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ETypeInfoContainer extends AbstractContainer
+{
+    /** holds ETypeInfo */
+    private ETypeInfo etypeInfo = new ETypeInfo();
+
+    /**
+     * Creates a new ETypeInfoContainer object.
+     */
+    public ETypeInfoContainer()
+    {
+        super();
+        this.stateStack = new int[1];
+        this.grammar = ETypeInfoGrammar.getInstance();
+        setTransition( ETypeInfoStatesEnum.START_STATE );
+    }
+
+
+    /**
+     * @return Returns the ETypeInfo.
+     */
+    public ETypeInfo getETypeInfo()
+    {
+        return etypeInfo;
+    }
+
+    
+    /**
+     * Set a ETypeInfo Object into the container
+     * 
+     * @param etypeInfo The ETypeInfo to set.
+     */
+    public void setETypeInfo( ETypeInfo etypeInfo )
+    {
+        this.etypeInfo = etypeInfo;
+    }
+
+    
+    /**
+     * Add a EtypeInfoEntry Object into the list. It will be completed by the
+     * KerberosDecoder.
+     * 
+     * @param hostAddress The HostAddress to add.
+     */
+    public void addEtypeInfoEntry( ETypeInfoEntry etypeInfoEntry )
+    {
+        etypeInfo.addETypeInfoEntry( etypeInfoEntry );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoGrammar.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoGrammar.java?rev=1038118&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoGrammar.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoGrammar.java
Tue Nov 23 13:57:16 2010
@@ -0,0 +1,93 @@
+/*
+ *  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.etypeInfo;
+
+
+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.codec.actions.CheckNotNullLength;
+import org.apache.directory.shared.kerberos.codec.etypeInfo.actions.AddETypeInfoEntry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the ETYPE-INFO 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 ETypeInfoGrammar extends AbstractGrammar
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( ETypeInfoGrammar.class );
+
+    /** A speedup for logger */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. ETypeInfoGrammar is a singleton */
+    private static Grammar instance = new ETypeInfoGrammar();
+
+
+    /**
+     * Creates a new ETypeInfoGrammar object.
+     */
+    private ETypeInfoGrammar()
+    {
+        setName( ETypeInfoGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[ETypeInfoStatesEnum.LAST_ETYPE_INFO_STATE.ordinal()][256];
+
+        // ============================================================================================
+        // ETYPE-INFO 
+        // ============================================================================================
+        // --------------------------------------------------------------------------------------------
+        // Transition from ETYPE-INFO init to ETYPE-INFO SEQ
+        // --------------------------------------------------------------------------------------------
+        // ETYPE-INFO-ENTRY         ::= SEQUENCE
+        super.transitions[ETypeInfoStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            ETypeInfoStatesEnum.START_STATE, ETypeInfoStatesEnum.ETYPE_INFO_SEQ_STATE, UniversalTag.SEQUENCE.getValue(),
+            new CheckNotNullLength() );
+        
+        // --------------------------------------------------------------------------------------------
+        // Transition from ETYPE-INFO init to ETYPE-INFO SEQ
+        // --------------------------------------------------------------------------------------------
+        // ETYPE-INFO-ENTRY         ::= SEQUENCE OF <ETYPE-INFO-ENTRY>
+        // 
+        super.transitions[ETypeInfoStatesEnum.ETYPE_INFO_SEQ_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()]
= new GrammarTransition(
+            ETypeInfoStatesEnum.ETYPE_INFO_SEQ_STATE, ETypeInfoStatesEnum.ETYPE_INFO_SEQ_STATE,
UniversalTag.SEQUENCE.getValue(),
+            new AddETypeInfoEntry() );
+    }
+
+
+    /**
+     * Get the instance of this grammar
+     * 
+     * @return An instance on the ETYPE-INFO Grammar
+     */
+    public static Grammar getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoStatesEnum.java?rev=1038118&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoStatesEnum.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/ETypeInfoStatesEnum.java
Tue Nov 23 13:57:16 2010
@@ -0,0 +1,106 @@
+/*
+ *  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.etypeInfo;
+
+
+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 store the ETYPE-INFO grammar's constants. It is also used for debugging
+ * purpose
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum ETypeInfoStatesEnum implements States
+{
+    // Start
+    START_STATE,                        // 0
+    
+    ETYPE_INFO_SEQ_STATE,               // 1
+    
+    ETYPE_INFO_ETYPE_INFO_ENTRY_STATE,  // 2
+    
+    // End
+    LAST_ETYPE_INFO_STATE;              // 3
+
+    
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "ETYPE_INFO_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar grammar )
+    {
+        if ( grammar instanceof KerberosMessageGrammar )
+        {
+            return "ETYPE_INFO_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_ETYPE_INFO_STATE.ordinal() ) ? "LAST_ETYPE_INFO_STATE" :
name() );
+    }
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEndState()
+    {
+        return this == LAST_ETYPE_INFO_STATE;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public ETypeInfoStatesEnum getStartState()
+    {
+        return START_STATE;
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/actions/AddETypeInfoEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/actions/AddETypeInfoEntry.java?rev=1038118&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/actions/AddETypeInfoEntry.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/shared/kerberos/codec/etypeInfo/actions/AddETypeInfoEntry.java
Tue Nov 23 13:57:16 2010
@@ -0,0 +1,116 @@
+/*
+ *  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.etypeInfo.actions;
+
+
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+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.KerberosMessageGrammar;
+import org.apache.directory.shared.kerberos.codec.etypeInfo.ETypeInfoContainer;
+import org.apache.directory.shared.kerberos.codec.etypeInfoEntry.ETypeInfoEntryContainer;
+import org.apache.directory.shared.kerberos.components.ETypeInfoEntry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The action used to add an ETypeInfoEntry object
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AddETypeInfoEntry extends GrammarAction
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( KerberosMessageGrammar.class
);
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+
+    /**
+     * Instantiates a new AddETypeInfoEntry action.
+     */
+    public AddETypeInfoEntry()
+    {
+        super( "Add an ETypeInfoEntry instance" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void action( Asn1Container container ) throws DecoderException
+    {
+        ETypeInfoContainer etypeInfoContainer = ( ETypeInfoContainer ) container;
+
+        TLV tlv = etypeInfoContainer.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 ) );
+        }
+        
+        // Now, let's decode the ETYPE-INFO-ENTRY
+        Asn1Decoder etypeInfoEntryDecoder = new Asn1Decoder();
+        
+        ETypeInfoEntryContainer etypeInfoEntryContainer = new ETypeInfoEntryContainer();
+        etypeInfoEntryContainer.setStream( container.getStream() );
+        
+        // Compute the start position in the stream for the ETypeInfoEntry to decode : 
+        // We have to move back to the ETypeInfoEntry tag
+        container.rewind();
+
+        // Decode the ETypeInfoEntry PDU
+        try
+        {
+            etypeInfoEntryDecoder.decode( container.getStream(), etypeInfoEntryContainer
);
+        }
+        catch ( DecoderException de )
+        {
+            throw de;
+        }
+        
+        // Update the expected length for the current TLV
+        tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
+
+        // Update the parent
+        container.updateParent();
+
+        // Store the ETypeInfoEntry in the container
+        ETypeInfoEntry etypeInfoEntry = etypeInfoEntryContainer.getETypeInfoEntry();
+        etypeInfoContainer.addEtypeInfoEntry( etypeInfoEntry );
+        
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "ETYPE-INFO-ENTRY added : {}", etypeInfoEntry );
+        }
+        
+        container.setGrammarEndAllowed( true );
+    }
+}

Added: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EtypeInfoDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EtypeInfoDecoderTest.java?rev=1038118&view=auto
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EtypeInfoDecoderTest.java
(added)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/EtypeInfoDecoderTest.java
Tue Nov 23 13:57:16 2010
@@ -0,0 +1,181 @@
+/*
+ *  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.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.asn1.ber.Asn1Container;
+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.etypeInfo.ETypeInfoContainer;
+import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
+import org.apache.directory.shared.kerberos.components.ETypeInfo;
+import org.apache.directory.shared.kerberos.components.ETypeInfoEntry;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test the ETYPE-INFO decoder.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class EtypeInfoDecoderTest
+{
+    /**
+     * Test the decoding of a ETYPE-INFO
+     */
+    @Test
+    public void testETypeInfo()
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x20 );
+        
+        stream.put( new byte[]
+            { 
+              0x30, 0x1E,
+                0x30, 0x0D,
+                  (byte)0xA0, 0x03,                 // etype
+                    0x02, 0x01, 0x05,
+                  (byte)0xA1, 0x06,                 // salt
+                    0x04, 0x04, 0x31, 0x32, 0x33, 0x34,
+                0x30, 0x0D,
+                  (byte)0xA0, 0x03,                 // etype
+                    0x02, 0x01, 0x05,
+                  (byte)0xA1, 0x06,                 // salt
+                    0x04, 0x04, 0x35, 0x36, 0x37, 0x38
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a ETypeInfo Container
+        Asn1Container etypeInfoContainer = new ETypeInfoContainer();
+        etypeInfoContainer.setStream( stream );
+
+        // Decode the ETypeInfo PDU
+        try
+        {
+            kerberosDecoder.decode( stream, etypeInfoContainer );
+        }
+        catch ( DecoderException de )
+        {
+            fail( de.getMessage() );
+        }
+
+        // Check the decoded ETypeInfo
+        ETypeInfo etypeInfo = ( ( ETypeInfoContainer ) etypeInfoContainer ).getETypeInfo();
+
+        assertEquals( 2, etypeInfo.getETypeInfoEntries().length );
+        
+        String[] expected = new String[]{ "1234", "5678" };
+        int i = 0;
+        
+        for ( ETypeInfoEntry etypeInfoEntry : etypeInfo.getETypeInfoEntries() )
+        {
+            assertEquals( EncryptionType.DES3_CBC_MD5, etypeInfoEntry.getEType() );
+            assertTrue( Arrays.equals( StringTools.getBytesUtf8( expected[i] ), etypeInfoEntry.getSalt()
) );
+            i++;
+        }
+
+        // Check the encoding
+        ByteBuffer bb = ByteBuffer.allocate( etypeInfo.computeLength() );
+        
+        try
+        {
+            bb = etypeInfo.encode( bb );
+    
+            // Check the length
+            assertEquals( 0x20, bb.limit() );
+    
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+    
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            fail();
+        }
+    }
+    
+    
+    /**
+     * Test the decoding of a ETypeInfo with nothing in it
+     */
+    @Test( expected = DecoderException.class)
+    public void testETypeInfoEmpty() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x02 );
+        
+        stream.put( new byte[]
+            { 0x30, 0x00 } );
+
+        stream.flip();
+
+        // Allocate a ETypeInfo Container
+        Asn1Container etypeInfoContainer = new ETypeInfoContainer();
+
+        // Decode the ETypeInfo PDU
+        kerberosDecoder.decode( stream, etypeInfoContainer );
+        fail();
+    }
+    
+    
+    /**
+     * Test the decoding of a ETypeInfo with empty ETypeInfoEntry in it
+     */
+    @Test( expected = DecoderException.class)
+    public void testETypeInfoNoETypeInfoEntry() throws DecoderException
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x04 );
+        
+        stream.put( new byte[]
+            { 
+              0x30, 0x02,
+                (byte)0x30, 0x00                  // empty ETypeInfoEntry
+            } );
+
+        stream.flip();
+
+        // Allocate a ETypeInfo Container
+        Asn1Container etypeInfoContainer = new ETypeInfoContainer();
+
+        // Decode the ETypeInfo PDU
+        kerberosDecoder.decode( stream, etypeInfoContainer );
+        fail();
+    }
+}



Mime
View raw message