directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r151239 - in incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io: decoder/ encoder/
Date Thu, 03 Feb 2005 21:57:18 GMT
Author: erodriguez
Date: Thu Feb  3 13:57:13 2005
New Revision: 151239

URL: http://svn.apache.org/viewcvs?view=rev&rev=151239
Log:
Moved Kerberos encoders to use object composition.

Added:
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/AuthorizationDataEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ChecksumEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptionKeyEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptionTypeEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/HostAddressesEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KerberosTimeEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/LastRequestEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PrincipalNameEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/TicketEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/TransitedEncodingEncoder.java
Removed:
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KerberosMessageEncoder.java
Modified:
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/ChecksumDecoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/EncryptedDataDecoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ApplicationReplyEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncApRepPartEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncAsRepPartEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncKdcRepPartEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncKrbPrivPartEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncTgsRepPartEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncTicketPartEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedDataEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedTimestampEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ErrorMessageEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KdcReplyEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KdcReqBodyEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PreAuthenticationDataEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PrivateMessageEncoder.java

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/ChecksumDecoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/ChecksumDecoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/ChecksumDecoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/ChecksumDecoder.java Thu Feb  3 13:57:13 2005
@@ -36,7 +36,7 @@
      *          checksum[1]    OCTET STRING
      * }
 	 */
-	protected static Checksum decode( DERSequence sequence )
+	public static Checksum decode( DERSequence sequence )
 	{
 		ChecksumType type = ChecksumType.NULL;
 		byte[] data = null;

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/EncryptedDataDecoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/EncryptedDataDecoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/EncryptedDataDecoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/EncryptedDataDecoder.java Thu Feb  3 13:57:13 2005
@@ -49,7 +49,7 @@
 	 *             cipher[2]    OCTET STRING -- ciphertext
 	 * }
 	 */
-	protected static EncryptedData decode( DERSequence sequence )
+	public static EncryptedData decode( DERSequence sequence )
 	{
 		EncryptedDataModifier modifier = new EncryptedDataModifier();
 		

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ApplicationReplyEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ApplicationReplyEncoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ApplicationReplyEncoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ApplicationReplyEncoder.java Thu Feb  3 13:57:13 2005
@@ -27,28 +27,30 @@
 import org.apache.asn1.der.DERTaggedObject;
 import org.apache.kerberos.messages.application.ApplicationReply;
 
-public class ApplicationReplyEncoder extends KerberosMessageEncoder {
-	
+
+public class ApplicationReplyEncoder
+{
 	public static final int APPLICATION_CODE = 15;
 	
-	public byte[] encode(ApplicationReply reply) throws IOException {
+	public byte[] encode( ApplicationReply reply ) throws IOException
+	{
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		ASN1OutputStream aos = new ASN1OutputStream(baos);
+		ASN1OutputStream aos = new ASN1OutputStream( baos );
 		
-		DERSequence replySequence = encodeReplySequence(reply);
-		aos.writeObject( DERApplicationSpecific.valueOf(APPLICATION_CODE, replySequence));
+		DERSequence replySequence = encodeReplySequence( reply );
+		aos.writeObject( DERApplicationSpecific.valueOf( APPLICATION_CODE, replySequence ) );
 		aos.close();
 		
 		return baos.toByteArray();
 	}
 	
-	private DERSequence encodeReplySequence(ApplicationReply message) {
-		
+	private DERSequence encodeReplySequence( ApplicationReply message )
+	{
 		DERSequence sequence = new DERSequence();
 		
-		sequence.add(new DERTaggedObject(0, DERInteger.valueOf( message.getProtocolVersionNumber() )));
-		sequence.add(new DERTaggedObject(1, DERInteger.valueOf(message.getMessageType().getOrdinal())));
-		sequence.add(new DERTaggedObject(2, encodeEncryptedData(message.getEncPart())));
+		sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( message.getProtocolVersionNumber() ) ) );
+		sequence.add( new DERTaggedObject( 1, DERInteger.valueOf( message.getMessageType().getOrdinal() ) ) );
+		sequence.add( new DERTaggedObject( 2, EncryptedDataEncoder.encodeSequence(message.getEncPart() ) ) );
 		
 		return sequence;
 	}

Added: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/AuthorizationDataEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/AuthorizationDataEncoder.java?view=auto&rev=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/AuthorizationDataEncoder.java (added)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/AuthorizationDataEncoder.java Thu Feb  3 13:57:13 2005
@@ -0,0 +1,55 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.kerberos.io.encoder;
+
+import java.util.Iterator;
+
+import org.apache.asn1.der.DERInteger;
+import org.apache.asn1.der.DEROctetString;
+import org.apache.asn1.der.DERSequence;
+import org.apache.asn1.der.DERTaggedObject;
+import org.apache.kerberos.messages.value.AuthorizationData;
+import org.apache.kerberos.messages.value.AuthorizationDataEntry;
+
+
+public class AuthorizationDataEncoder
+{
+	/**
+	 * AuthorizationData ::=   SEQUENCE OF SEQUENCE {
+     *     ad-type[0]               INTEGER,
+     *     ad-data[1]               OCTET STRING
+     * }
+     */
+	protected static DERSequence encode( AuthorizationData data )
+	{
+		Iterator it = data.iterator();
+		DERSequence outerSequence = new DERSequence();
+		
+		while ( it.hasNext() )
+		{
+			AuthorizationDataEntry entry = (AuthorizationDataEntry)it.next();
+			DERSequence sequence = new DERSequence();
+			sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( entry.getAuthorizationDataType().getOrdinal() ) ) );
+			sequence.add( new DERTaggedObject( 1, new DEROctetString( entry.getAuthorizationData() ) ) );
+			outerSequence.add( sequence );
+		}
+		
+		return outerSequence;
+	}
+}
+

Added: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ChecksumEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ChecksumEncoder.java?view=auto&rev=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ChecksumEncoder.java (added)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ChecksumEncoder.java Thu Feb  3 13:57:13 2005
@@ -0,0 +1,45 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.kerberos.io.encoder;
+
+import org.apache.asn1.der.DERInteger;
+import org.apache.asn1.der.DEROctetString;
+import org.apache.asn1.der.DERSequence;
+import org.apache.asn1.der.DERTaggedObject;
+import org.apache.kerberos.messages.value.Checksum;
+
+
+public class ChecksumEncoder
+{
+	/**
+	 * Checksum ::=   SEQUENCE {
+     *          cksumtype[0]   INTEGER,
+     *          checksum[1]    OCTET STRING
+     * }
+	 */
+	public static DERSequence encode( Checksum checksum )
+	{
+		DERSequence vector = new DERSequence();
+		
+		vector.add( new DERTaggedObject( 0, DERInteger.valueOf( checksum.getChecksumType().getOrdinal() ) ) );
+		vector.add( new DERTaggedObject( 1, new DEROctetString( checksum.getChecksumValue() ) ) );
+		
+		return vector;
+	}
+}
+

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncApRepPartEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncApRepPartEncoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncApRepPartEncoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncApRepPartEncoder.java Thu Feb  3 13:57:13 2005
@@ -27,31 +27,39 @@
 import org.apache.asn1.der.DERTaggedObject;
 import org.apache.kerberos.messages.components.EncApRepPart;
 
-public class EncApRepPartEncoder extends KerberosMessageEncoder {
-	
+
+public class EncApRepPartEncoder
+{
 	public static final int APPLICATION_CODE = 27;
 	
-	public byte[] encode(EncApRepPart apRepPart) throws IOException {
+	public byte[] encode( EncApRepPart apRepPart ) throws IOException
+	{
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		ASN1OutputStream aos = new ASN1OutputStream(baos);
+		ASN1OutputStream aos = new ASN1OutputStream( baos );
 		
-		DERSequence privPartSequence = encodeApRepPartSequence(apRepPart);
-		aos.writeObject( DERApplicationSpecific.valueOf(APPLICATION_CODE, privPartSequence));
+		DERSequence privPartSequence = encodeApRepPartSequence( apRepPart );
+		aos.writeObject( DERApplicationSpecific.valueOf( APPLICATION_CODE, privPartSequence ) );
 		aos.close();
 		
 		return baos.toByteArray();
 	}
 	
-	private DERSequence encodeApRepPartSequence(EncApRepPart message) {
-		
+	private DERSequence encodeApRepPartSequence( EncApRepPart message )
+	{
 		DERSequence sequence = new DERSequence();
 		
-		sequence.add(new DERTaggedObject(0, encodeKerberosTime(message.getClientTime())));
-		sequence.add(new DERTaggedObject(1, DERInteger.valueOf(message.getClientMicroSecond())));
-		if (message.getSubSessionKey() != null)
-			sequence.add(new DERTaggedObject(2, encodeEncryptionKey(message.getSubSessionKey())));
-		if (message.getSequenceNumber() != null)
-			sequence.add(new DERTaggedObject(3, DERInteger.valueOf(message.getSequenceNumber().intValue())));
+		sequence.add( new DERTaggedObject(0, KerberosTimeEncoder.encode( message.getClientTime() ) ) );
+		sequence.add( new DERTaggedObject(1, DERInteger.valueOf( message.getClientMicroSecond() ) ) );
+		
+		if ( message.getSubSessionKey() != null)
+		{
+			sequence.add( new DERTaggedObject( 2, EncryptionKeyEncoder.encode( message.getSubSessionKey() ) ) );
+		}
+		
+		if ( message.getSequenceNumber() != null )
+		{
+			sequence.add( new DERTaggedObject( 3, DERInteger.valueOf( message.getSequenceNumber().intValue() ) ) );
+		}
 		
 		return sequence;
 	}

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncAsRepPartEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncAsRepPartEncoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncAsRepPartEncoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncAsRepPartEncoder.java Thu Feb  3 13:57:13 2005
@@ -17,6 +17,7 @@
 
 package org.apache.kerberos.io.encoder;
 
+
 public class EncAsRepPartEncoder extends EncKdcRepPartEncoder
 {
 	/*

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncKdcRepPartEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncKdcRepPartEncoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncKdcRepPartEncoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncKdcRepPartEncoder.java Thu Feb  3 13:57:13 2005
@@ -22,76 +22,90 @@
 
 import org.apache.asn1.der.ASN1OutputStream;
 import org.apache.asn1.der.DERApplicationSpecific;
+import org.apache.asn1.der.DERBitString;
+import org.apache.asn1.der.DERGeneralString;
 import org.apache.asn1.der.DERInteger;
 import org.apache.asn1.der.DERSequence;
 import org.apache.asn1.der.DERTaggedObject;
 import org.apache.kerberos.messages.KdcReply;
 
-public abstract class EncKdcRepPartEncoder extends KerberosMessageEncoder {
-	
-	private int _applicationCode;
+
+public abstract class EncKdcRepPartEncoder
+{
+	private int applicationCode;
 	
-	protected EncKdcRepPartEncoder(int applicationCode) {
-		_applicationCode = applicationCode;
+	protected EncKdcRepPartEncoder( int applicationCode )
+	{
+		this.applicationCode = applicationCode;
 	}
 	
-	public byte[] encode(KdcReply app) throws IOException {
+	public byte[] encode( KdcReply app ) throws IOException
+	{
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		ASN1OutputStream aos = new ASN1OutputStream(baos);
+		ASN1OutputStream aos = new ASN1OutputStream( baos );
 		
-		DERSequence initialSequence = encodeInitialSequence(app);
-		aos.writeObject( DERApplicationSpecific.valueOf(_applicationCode, initialSequence));
+		DERSequence initialSequence = encodeInitialSequence( app );
+		aos.writeObject( DERApplicationSpecific.valueOf( applicationCode, initialSequence ) );
 		
 		return baos.toByteArray();
 	}
 	
-	/*
-	   EncKDCRepPart ::=   SEQUENCE {
-	               key[0]                       EncryptionKey,
-	               last-req[1]                  LastReq,
-
-	               nonce[2]                     INTEGER,
-	               key-expiration[3]            KerberosTime OPTIONAL,
-	               flags[4]                     TicketFlags,
-	               authtime[5]                  KerberosTime,
-	               starttime[6]                 KerberosTime OPTIONAL,
-	               endtime[7]                   KerberosTime,
-	               renew-till[8]                KerberosTime OPTIONAL,
-	               srealm[9]                    Realm,
-	               sname[10]                    PrincipalName,
-	               caddr[11]                    HostAddresses OPTIONAL
-	}*/
-	protected DERSequence encodeInitialSequence(KdcReply reply) {
-
+	/**
+	 *    EncKDCRepPart ::=   SEQUENCE {
+	 *                key[0]                       EncryptionKey,
+	 *                last-req[1]                  LastReq,
+     * 
+	 *                nonce[2]                     INTEGER,
+	 *                key-expiration[3]            KerberosTime OPTIONAL,
+	 *                flags[4]                     TicketFlags,
+	 *                authtime[5]                  KerberosTime,
+	 *                starttime[6]                 KerberosTime OPTIONAL,
+	 *                endtime[7]                   KerberosTime,
+	 *                renew-till[8]                KerberosTime OPTIONAL,
+	 *                srealm[9]                    Realm,
+	 *                sname[10]                    PrincipalName,
+	 *                caddr[11]                    HostAddresses OPTIONAL
+	 * }
+	 */
+	protected DERSequence encodeInitialSequence( KdcReply reply )
+	{
 		DERSequence sequence = new DERSequence();
 		
-		sequence.add(new DERTaggedObject(0, encodeEncryptionKey(reply.getKey())));
-		sequence.add(new DERTaggedObject(1, encodeLastRequest(reply.getLastRequest())));
-		sequence.add(new DERTaggedObject(2, DERInteger.valueOf(reply.getNonce())));
+		sequence.add( new DERTaggedObject( 0, EncryptionKeyEncoder.encode( reply.getKey() ) ) );
+		sequence.add( new DERTaggedObject( 1, LastRequestEncoder.encode( reply.getLastRequest() ) ) );
+		sequence.add( new DERTaggedObject( 2, DERInteger.valueOf( reply.getNonce() ) ) );
 		
 		// OPTIONAL
-		if (reply.getKeyExpiration() != null)
-			sequence.add(new DERTaggedObject(3, encodeKerberosTime(reply.getKeyExpiration())));
+		if ( reply.getKeyExpiration() != null )
+		{
+			sequence.add(new DERTaggedObject( 3, KerberosTimeEncoder.encode(reply.getKeyExpiration() ) ) );
+		}
 		
-		sequence.add(new DERTaggedObject(4, encodeTicketFlags(reply.getFlags())));
-		sequence.add(new DERTaggedObject(5, encodeKerberosTime(reply.getAuthTime())));
+		sequence.add( new DERTaggedObject( 4, new DERBitString(reply.getFlags().getBytes() ) ) );
+		sequence.add( new DERTaggedObject( 5, KerberosTimeEncoder.encode( reply.getAuthTime() ) ) );
 		
 		// OPTIONAL
-		if (reply.getStartTime() != null)
-			sequence.add(new DERTaggedObject(6, encodeKerberosTime(reply.getStartTime())));
+		if ( reply.getStartTime() != null )
+		{
+			sequence.add( new DERTaggedObject( 6, KerberosTimeEncoder.encode( reply.getStartTime() ) ) );
+		}
 		
-		sequence.add(new DERTaggedObject(7, encodeKerberosTime(reply.getEndTime())));
+		sequence.add( new DERTaggedObject( 7, KerberosTimeEncoder.encode( reply.getEndTime() ) ) );
 		
 		// OPTIONAL
-		if (reply.getRenewTill() != null)
-			sequence.add(new DERTaggedObject(8, encodeKerberosTime(reply.getRenewTill())));
+		if ( reply.getRenewTill() != null )
+		{
+			sequence.add( new DERTaggedObject( 8, KerberosTimeEncoder.encode( reply.getRenewTill() ) ) );
+		}
 		
-		sequence.add(new DERTaggedObject(9, encodeRealm(reply.getServerRealm())));
-		sequence.add(new DERTaggedObject(10, encodePrincipalName(reply.getServerPrincipal())));
+		sequence.add( new DERTaggedObject( 9, DERGeneralString.valueOf( reply.getServerRealm().toString() ) ) );
+		sequence.add( new DERTaggedObject( 10, PrincipalNameEncoder.encode( reply.getServerPrincipal() ) ) );
 		
 		// OPTIONAL
-		if (reply.getClientAddresses() != null)
-			sequence.add(new DERTaggedObject(11, encodeHostAddresses(reply.getClientAddresses())));
+		if ( reply.getClientAddresses() != null )
+		{
+			sequence.add( new DERTaggedObject( 11, HostAddressesEncoder.encodeSequence( reply.getClientAddresses() ) ) );
+		}
 		
 		return sequence;
 	}

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncKrbPrivPartEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncKrbPrivPartEncoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncKrbPrivPartEncoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncKrbPrivPartEncoder.java Thu Feb  3 13:57:13 2005
@@ -28,35 +28,50 @@
 import org.apache.asn1.der.DERTaggedObject;
 import org.apache.kerberos.messages.components.EncKrbPrivPart;
 
-public class EncKrbPrivPartEncoder extends KerberosMessageEncoder {
+
+public class EncKrbPrivPartEncoder
+{
+	private static final int APPLICATION_CODE = 28;
 	
-	public static final int APPLICATION_CODE = 28;
-	
-	public byte[] encode(EncKrbPrivPart privPart) throws IOException {
+	public byte[] encode(EncKrbPrivPart privPart) throws IOException
+	{
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		ASN1OutputStream aos = new ASN1OutputStream(baos);
+		ASN1OutputStream aos = new ASN1OutputStream( baos );
 		
-		DERSequence privPartSequence = encodePrivatePartSequence(privPart);
-		aos.writeObject( DERApplicationSpecific.valueOf(APPLICATION_CODE, privPartSequence));
+		DERSequence privPartSequence = encodePrivatePartSequence( privPart );
+		aos.writeObject( DERApplicationSpecific.valueOf( APPLICATION_CODE, privPartSequence ) );
 		aos.close();
 		
 		return baos.toByteArray();
 	}
 	
-	private DERSequence encodePrivatePartSequence(EncKrbPrivPart message) {
-		
+	private DERSequence encodePrivatePartSequence( EncKrbPrivPart message )
+	{
 		DERSequence sequence = new DERSequence();
 		
-		sequence.add(new DERTaggedObject(0, new DEROctetString(message.getUserData())));
-		if (message.getTimestamp() != null)
-			sequence.add(new DERTaggedObject(1, encodeKerberosTime(message.getTimestamp())));
-		if (message.getMicroSecond() != null)
-			sequence.add(new DERTaggedObject(2, DERInteger.valueOf(message.getMicroSecond().intValue())));
-		if (message.getSequenceNumber() != null)
-			sequence.add(new DERTaggedObject(3, DERInteger.valueOf(message.getSequenceNumber().intValue())));
-		sequence.add(new DERTaggedObject(4, encodeHostAddress(message.getSenderAddress())));
-		if (message.getRecipientAddress() != null)
-			sequence.add(new DERTaggedObject(5, encodeHostAddress(message.getRecipientAddress())));
+		sequence.add( new DERTaggedObject( 0, new DEROctetString( message.getUserData() ) ) );
+		
+		if ( message.getTimestamp() != null )
+		{
+			sequence.add( new DERTaggedObject( 1, KerberosTimeEncoder.encode( message.getTimestamp() ) ) );
+		}
+		
+		if ( message.getMicroSecond() != null )
+		{
+			sequence.add(new DERTaggedObject( 2, DERInteger.valueOf( message.getMicroSecond().intValue() ) ) );
+		}
+		
+		if ( message.getSequenceNumber() != null )
+		{
+			sequence.add(new DERTaggedObject( 3, DERInteger.valueOf( message.getSequenceNumber().intValue() ) ) );
+		}
+		
+		sequence.add(new DERTaggedObject( 4, HostAddressesEncoder.encode( message.getSenderAddress() ) ) );
+		
+		if ( message.getRecipientAddress() != null )
+		{
+			sequence.add(new DERTaggedObject( 5, HostAddressesEncoder.encode( message.getRecipientAddress() ) ) );
+		}
 		
 		return sequence;
 	}

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncTgsRepPartEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncTgsRepPartEncoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncTgsRepPartEncoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncTgsRepPartEncoder.java Thu Feb  3 13:57:13 2005
@@ -17,15 +17,17 @@
 
 package org.apache.kerberos.io.encoder;
 
-public class EncTgsRepPartEncoder extends EncKdcRepPartEncoder {
-	
-	/*
+
+public class EncTgsRepPartEncoder extends EncKdcRepPartEncoder
+{
+	/**
 	 * EncTGSRepPart ::=   [APPLICATION 26] EncKDCRepPart
 	 */
 	public static final int APPLICATION_CODE = 26;
 	
-	public EncTgsRepPartEncoder() {
-		super(APPLICATION_CODE);
+	public EncTgsRepPartEncoder()
+	{
+		super( APPLICATION_CODE );
 	}
 }
 

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncTicketPartEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncTicketPartEncoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncTicketPartEncoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncTicketPartEncoder.java Thu Feb  3 13:57:13 2005
@@ -22,63 +22,81 @@
 
 import org.apache.asn1.der.ASN1OutputStream;
 import org.apache.asn1.der.DERApplicationSpecific;
+import org.apache.asn1.der.DERBitString;
+import org.apache.asn1.der.DERGeneralString;
 import org.apache.asn1.der.DERSequence;
 import org.apache.asn1.der.DERTaggedObject;
 import org.apache.kerberos.messages.components.EncTicketPart;
 
-public class EncTicketPartEncoder extends KerberosMessageEncoder {
-	
-	public static final int APPLICATION_CODE = 3;
+
+public class EncTicketPartEncoder
+{
+	private static final int APPLICATION_CODE = 3;
 	
-	public byte[] encode(EncTicketPart ticketPart) throws IOException {
+	public byte[] encode( EncTicketPart ticketPart ) throws IOException
+	{
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		ASN1OutputStream aos = new ASN1OutputStream(baos);
+		ASN1OutputStream aos = new ASN1OutputStream( baos );
 		
-		DERSequence ticketSequence = encodeInitialSequence(ticketPart);
-		aos.writeObject( DERApplicationSpecific.valueOf(APPLICATION_CODE, ticketSequence));
+		DERSequence ticketSequence = encodeInitialSequence( ticketPart );
+		aos.writeObject( DERApplicationSpecific.valueOf( APPLICATION_CODE, ticketSequence ) );
 		aos.close();
 		
 		return baos.toByteArray();
 	}
 	
-	/*
-	-- Encrypted part of ticket
-	EncTicketPart ::=     [APPLICATION 3] SEQUENCE {
-	                      flags[0]             TicketFlags,
-	                      key[1]               EncryptionKey,
-	                      crealm[2]            Realm,
-	                      cname[3]             PrincipalName,
-	                      transited[4]         TransitedEncoding,
-	                      authtime[5]          KerberosTime,
-	                      starttime[6]         KerberosTime OPTIONAL,
-	                      endtime[7]           KerberosTime,
-	                      renew-till[8]        KerberosTime OPTIONAL,
-	                      caddr[9]             HostAddresses OPTIONAL,
-	                      authorization-data[10]   AuthorizationData OPTIONAL
-	}*/
-	public DERSequence encodeInitialSequence(EncTicketPart ticketPart) {
+	/**
+	 * -- Encrypted part of ticket
+	 * EncTicketPart ::=     [APPLICATION 3] SEQUENCE {
+	 *                       flags[0]             TicketFlags,
+	 *                       key[1]               EncryptionKey,
+	 *                       crealm[2]            Realm,
+	 *                       cname[3]             PrincipalName,
+	 *                       transited[4]         TransitedEncoding,
+	 *                       authtime[5]          KerberosTime,
+	 *                       starttime[6]         KerberosTime OPTIONAL,
+	 *                       endtime[7]           KerberosTime,
+	 *                       renew-till[8]        KerberosTime OPTIONAL,
+	 *                       caddr[9]             HostAddresses OPTIONAL,
+	 *                       authorization-data[10]   AuthorizationData OPTIONAL
+	 * }
+	 */
+	public DERSequence encodeInitialSequence( EncTicketPart ticketPart )
+	{
 		DERSequence sequence = new DERSequence();
 		
-		sequence.add(new DERTaggedObject(0, encodeTicketFlags(ticketPart.getFlags())));
-		sequence.add(new DERTaggedObject(1, encodeEncryptionKey(ticketPart.getSessionKey())));
-		sequence.add(new DERTaggedObject(2, encodeRealm(ticketPart.getClientRealm())));
-		sequence.add(new DERTaggedObject(3, encodePrincipalName(ticketPart.getClientPrincipal())));
-		sequence.add(new DERTaggedObject(4, encodeTransitedEncoding(ticketPart.getTransitedEncoding())));
-		sequence.add(new DERTaggedObject(5, encodeKerberosTime(ticketPart.getAuthTime())));
+		sequence.add( new DERTaggedObject( 0, new DERBitString( ticketPart.getFlags().getBytes() ) ) );
+		sequence.add( new DERTaggedObject( 1, EncryptionKeyEncoder.encode( ticketPart.getSessionKey() ) ) );
+		sequence.add( new DERTaggedObject( 2, DERGeneralString.valueOf( ticketPart.getClientRealm().toString() ) ) );
+		sequence.add( new DERTaggedObject( 3, PrincipalNameEncoder.encode( ticketPart.getClientPrincipal() ) ) );
+		sequence.add( new DERTaggedObject( 4, TransitedEncodingEncoder.encode( ticketPart.getTransitedEncoding() ) ) );
+		sequence.add( new DERTaggedObject( 5, KerberosTimeEncoder.encode( ticketPart.getAuthTime() ) ) );
+		
+		// OPTIONAL
+		if ( ticketPart.getStartTime() != null )
+		{
+			sequence.add( new DERTaggedObject( 6, KerberosTimeEncoder.encode( ticketPart.getStartTime() ) ) );
+		}
+		
+		sequence.add( new DERTaggedObject( 7, KerberosTimeEncoder.encode( ticketPart.getEndTime() ) ) );
 		
 		// OPTIONAL
-		if (ticketPart.getStartTime() != null)
-			sequence.add(new DERTaggedObject(6, encodeKerberosTime(ticketPart.getStartTime())));
+		if ( ticketPart.getRenewTill() != null )
+		{
+			sequence.add( new DERTaggedObject( 8, KerberosTimeEncoder.encode( ticketPart.getRenewTill() ) ) );
+		}
 		
-		sequence.add(new DERTaggedObject(7, encodeKerberosTime(ticketPart.getEndTime())));
+		// OPTIONAL
+		if ( ticketPart.getClientAddresses() != null )
+		{
+			sequence.add( new DERTaggedObject( 9, HostAddressesEncoder.encodeSequence( ticketPart.getClientAddresses() ) ) );
+		}
 		
 		// OPTIONAL
-		if (ticketPart.getRenewTill() != null)
-			sequence.add(new DERTaggedObject(8, encodeKerberosTime(ticketPart.getRenewTill())));
-		if (ticketPart.getClientAddresses() != null)
-			sequence.add(new DERTaggedObject(9, encodeHostAddresses(ticketPart.getClientAddresses())));
-		if (ticketPart.getAuthorizationData() != null)
-			sequence.add(new DERTaggedObject(10, encodeAuthorizationData(ticketPart.getAuthorizationData())));
+		if ( ticketPart.getAuthorizationData() != null )
+		{
+			sequence.add( new DERTaggedObject( 10, AuthorizationDataEncoder.encode( ticketPart.getAuthorizationData() ) ) );
+		}
 		
 		return sequence;
 	}

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedDataEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedDataEncoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedDataEncoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedDataEncoder.java Thu Feb  3 13:57:13 2005
@@ -30,12 +30,12 @@
 
 public class EncryptedDataEncoder
 {
-	public byte[] encode( EncryptedData encryptedData ) throws IOException
+	public static byte[] encode( EncryptedData encryptedData ) throws IOException
 	{
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
 		ASN1OutputStream aos = new ASN1OutputStream( baos );
 		
-		aos.writeObject( encodeEncryptedData( encryptedData ) );
+		aos.writeObject( encodeSequence( encryptedData ) );
 		aos.close();
 
 		return baos.toByteArray();
@@ -48,7 +48,7 @@
 	 *             cipher[2]    OCTET STRING -- ciphertext
 	 * }
 	 */
-	protected DERSequence encodeEncryptedData( EncryptedData encryptedData )
+	public static DERSequence encodeSequence( EncryptedData encryptedData )
 	{
 		DERSequence sequence = new DERSequence();
 		

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedTimestampEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedTimestampEncoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedTimestampEncoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedTimestampEncoder.java Thu Feb  3 13:57:13 2005
@@ -27,7 +27,7 @@
 import org.apache.kerberos.messages.value.EncryptedTimeStamp;
 
 
-public class EncryptedTimestampEncoder extends KerberosMessageEncoder
+public class EncryptedTimestampEncoder
 {
 	public byte[] encode( EncryptedTimeStamp encryptedTimestamp ) throws IOException
 	{
@@ -50,7 +50,7 @@
 	{
 		DERSequence sequence = new DERSequence();
 		
-		sequence.add( new DERTaggedObject( 0, encodeKerberosTime( encryptedTimestamp.getTimeStamp() ) ) );
+		sequence.add( new DERTaggedObject( 0, KerberosTimeEncoder.encode( encryptedTimestamp.getTimeStamp() ) ) );
 		
 		if ( encryptedTimestamp.getMicroSeconds() > 0)
 		{

Added: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptionKeyEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptionKeyEncoder.java?view=auto&rev=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptionKeyEncoder.java (added)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptionKeyEncoder.java Thu Feb  3 13:57:13 2005
@@ -0,0 +1,39 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.kerberos.io.encoder;
+
+import org.apache.asn1.der.DERInteger;
+import org.apache.asn1.der.DEROctetString;
+import org.apache.asn1.der.DERSequence;
+import org.apache.asn1.der.DERTaggedObject;
+import org.apache.kerberos.messages.value.EncryptionKey;
+
+
+public class EncryptionKeyEncoder
+{
+	protected static DERSequence encode( EncryptionKey key )
+	{
+		DERSequence vector = new DERSequence();
+		
+		vector.add( new DERTaggedObject( 0, DERInteger.valueOf( key.getKeyType().getOrdinal() ) ) );
+		vector.add( new DERTaggedObject( 1, new DEROctetString( key.getKeyValue() ) ) );
+		
+		return vector;
+	}
+}
+

Added: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptionTypeEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptionTypeEncoder.java?view=auto&rev=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptionTypeEncoder.java (added)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptionTypeEncoder.java Thu Feb  3 13:57:13 2005
@@ -0,0 +1,43 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.kerberos.io.encoder;
+
+import org.apache.asn1.der.DERInteger;
+import org.apache.asn1.der.DERSequence;
+import org.apache.kerberos.crypto.encryption.EncryptionType;
+
+
+public class EncryptionTypeEncoder
+{
+	/**
+     * etype[8]             SEQUENCE OF INTEGER, -- EncryptionEngine,
+     *             -- in preference order
+     */
+	protected static DERSequence encode( EncryptionType[] eType )
+	{
+		DERSequence sequence = new DERSequence();
+		
+		for ( int ii = 0; ii < eType.length; ii++ )
+		{
+			sequence.add( DERInteger.valueOf( eType[ii].getOrdinal() ) );
+		}
+		
+		return sequence;
+	}
+}
+

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ErrorMessageEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ErrorMessageEncoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ErrorMessageEncoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ErrorMessageEncoder.java Thu Feb  3 13:57:13 2005
@@ -31,7 +31,7 @@
 import org.apache.kerberos.messages.ErrorMessage;
 
 
-public class ErrorMessageEncoder extends KerberosMessageEncoder
+public class ErrorMessageEncoder
 {
 	public void encode( ErrorMessage message, ByteBuffer out ) throws IOException
 	{
@@ -43,42 +43,66 @@
 		aos.close();
 	}
 	
-	public byte[] encode(ErrorMessage message) throws IOException
+	public byte[] encode( ErrorMessage message ) throws IOException
 	{
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		ASN1OutputStream aos = new ASN1OutputStream(baos);
+		ASN1OutputStream aos = new ASN1OutputStream( baos );
 		
-		DERSequence errorReply = encodeErrorMessageSequence(message);
-		aos.writeObject( DERApplicationSpecific.valueOf(message.getMessageType().getOrdinal(), errorReply));
+		DERSequence errorReply = encodeErrorMessageSequence( message );
+		aos.writeObject( DERApplicationSpecific.valueOf( message.getMessageType().getOrdinal(), errorReply ) );
 		
 		aos.close();
 		
 		return baos.toByteArray();
 	}
 	
-	private DERSequence encodeErrorMessageSequence(ErrorMessage message)
+	private DERSequence encodeErrorMessageSequence( ErrorMessage message )
 	{
 		DERSequence sequence = new DERSequence();
 		
-		sequence.add(new DERTaggedObject(0, DERInteger.valueOf(message.getProtocolVersionNumber())));
-		sequence.add(new DERTaggedObject(1, DERInteger.valueOf(message.getMessageType().getOrdinal())));
-		if (message.getClientTime() != null)
-			sequence.add(new DERTaggedObject(2, encodeKerberosTime(message.getClientTime())));
-		if (message.getClientMicroSecond() != null)
-			sequence.add(new DERTaggedObject(3, DERInteger.valueOf(message.getClientMicroSecond().intValue())));
-		sequence.add(new DERTaggedObject(4, encodeKerberosTime(message.getServerTime())));
-		sequence.add(new DERTaggedObject(5, DERInteger.valueOf(message.getServerMicroSecond())));
-		sequence.add(new DERTaggedObject(6, DERInteger.valueOf(message.getErrorCode())));
-		if (message.getClientPrincipal() != null)
-			sequence.add(new DERTaggedObject(7, encodeRealm(message.getClientPrincipal().getRealm())));
-		if (message.getClientPrincipal() != null)
-			sequence.add(new DERTaggedObject(8, encodePrincipalName(message.getClientPrincipal())));
-		sequence.add(new DERTaggedObject(9, encodeRealm(message.getServerPrincipal().getRealm())));
-		sequence.add(new DERTaggedObject(10, encodePrincipalName(message.getServerPrincipal())));
-		if (message.getExplanatoryText() != null)
-			sequence.add(new DERTaggedObject(11, DERGeneralString.valueOf(message.getExplanatoryText())));
-		if (message.getExplanatoryData() != null)
-			sequence.add(new DERTaggedObject(12, new DEROctetString(message.getExplanatoryData())));
+		sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( message.getProtocolVersionNumber() ) ) );
+		
+		sequence.add( new DERTaggedObject( 1, DERInteger.valueOf( message.getMessageType().getOrdinal() ) ));
+		
+		if ( message.getClientTime() != null )
+		{
+			sequence.add( new DERTaggedObject( 2, KerberosTimeEncoder.encode( message.getClientTime() ) ) );
+		}
+		
+		if ( message.getClientMicroSecond() != null )
+		{
+			sequence.add(new DERTaggedObject( 3, DERInteger.valueOf( message.getClientMicroSecond().intValue() ) ) );
+		}
+		
+		sequence.add( new DERTaggedObject( 4, KerberosTimeEncoder.encode( message.getServerTime() ) ) );
+		
+		sequence.add( new DERTaggedObject( 5, DERInteger.valueOf( message.getServerMicroSecond() ) ) );
+		
+		sequence.add( new DERTaggedObject( 6, DERInteger.valueOf( message.getErrorCode() ) ) );
+		
+		if ( message.getClientPrincipal() != null )
+		{
+			sequence.add( new DERTaggedObject( 7, DERGeneralString.valueOf( message.getClientPrincipal().getRealm().toString() ) ) );
+		}
+		
+		if ( message.getClientPrincipal() != null )
+		{
+			sequence.add( new DERTaggedObject( 8, PrincipalNameEncoder.encode( message.getClientPrincipal() ) ) );
+		}
+		
+		sequence.add( new DERTaggedObject( 9, DERGeneralString.valueOf( message.getServerPrincipal().getRealm() ) ) );
+		
+		sequence.add( new DERTaggedObject( 10, PrincipalNameEncoder.encode( message.getServerPrincipal() ) ) );
+		
+		if ( message.getExplanatoryText() != null )
+		{
+			sequence.add( new DERTaggedObject( 11, DERGeneralString.valueOf( message.getExplanatoryText() ) ) );
+		}
+		
+		if ( message.getExplanatoryData() != null )
+		{
+			sequence.add( new DERTaggedObject( 12, new DEROctetString( message.getExplanatoryData() ) ) );
+		}
 		
 		return sequence;
 	}

Added: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/HostAddressesEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/HostAddressesEncoder.java?view=auto&rev=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/HostAddressesEncoder.java (added)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/HostAddressesEncoder.java Thu Feb  3 13:57:13 2005
@@ -0,0 +1,65 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.kerberos.io.encoder;
+
+import org.apache.asn1.der.DERInteger;
+import org.apache.asn1.der.DEROctetString;
+import org.apache.asn1.der.DERSequence;
+import org.apache.asn1.der.DERTaggedObject;
+import org.apache.kerberos.messages.value.HostAddress;
+import org.apache.kerberos.messages.value.HostAddresses;
+
+
+public class HostAddressesEncoder
+{
+	/**
+	 * HostAddresses ::=   SEQUENCE OF SEQUENCE {
+	 *                     addr-type[0]             INTEGER,
+	 *                     address[1]               OCTET STRING
+	 * }
+	 */
+	protected static DERSequence encodeSequence( HostAddresses hosts )
+	{
+		HostAddress[] addresses = hosts.getAddresses();
+		DERSequence vector = new DERSequence();
+		
+		for ( int ii = 0; ii < addresses.length; ii++ )
+		{
+			vector.add( encode( addresses[ii] ) );
+		}
+		
+		return vector;
+	}
+	
+	/**
+	 *  HostAddress ::=     SEQUENCE  {
+     *                     addr-type[0]             INTEGER,
+     *                     address[1]               OCTET STRING
+     * }
+     */
+	protected static DERSequence encode( HostAddress host )
+	{
+		DERSequence sequence = new DERSequence();
+		
+		sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( host.getAddressType().getOrdinal() ) ) );
+		sequence.add( new DERTaggedObject( 1, new DEROctetString( host.getAddress() ) ) );
+		
+		return sequence;
+	}
+}
+

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KdcReplyEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KdcReplyEncoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KdcReplyEncoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KdcReplyEncoder.java Thu Feb  3 13:57:13 2005
@@ -22,6 +22,7 @@
 
 import org.apache.asn1.der.ASN1OutputStream;
 import org.apache.asn1.der.DERApplicationSpecific;
+import org.apache.asn1.der.DERGeneralString;
 import org.apache.asn1.der.DERInteger;
 import org.apache.asn1.der.DEROctetString;
 import org.apache.asn1.der.DERSequence;
@@ -30,7 +31,7 @@
 import org.apache.kerberos.messages.value.PreAuthenticationData;
 
 
-public class KdcReplyEncoder extends KerberosMessageEncoder
+public class KdcReplyEncoder
 {
 	/*
  	AS-REP ::=    [APPLICATION 11] KDC-REP
@@ -56,18 +57,26 @@
 	              ticket[5]                  Ticket,
 	              enc-part[6]                EncryptedData
 	}*/
-	private DERSequence encodeKdcReplySequence(KdcReply app)
+	private DERSequence encodeKdcReplySequence( KdcReply app )
 	{
 		DERSequence sequence = new DERSequence();
 		
-		sequence.add(new DERTaggedObject(0, DERInteger.valueOf(app.getProtocolVersionNumber())));
-		sequence.add(new DERTaggedObject(1, DERInteger.valueOf(app.getMessageType().getOrdinal())));
-		if (app.getPaData() != null)
-			sequence.add(new DERTaggedObject(2, encodePaData(app.getPaData())));
-		sequence.add(new DERTaggedObject(3, encodeRealm(app.getClientRealm())));
-		sequence.add(new DERTaggedObject(4, encodePrincipalName(app.getClientPrincipal())));
-		sequence.add(new DERTaggedObject(5, encodeTicket(app.getTicket())));
-		sequence.add(new DERTaggedObject(6, encodeEncryptedData(app.getEncPart())));
+		sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( app.getProtocolVersionNumber() ) ) );
+		
+		sequence.add( new DERTaggedObject( 1, DERInteger.valueOf( app.getMessageType().getOrdinal() ) ) );
+		
+		if ( app.getPaData() != null )
+		{
+			sequence.add( new DERTaggedObject( 2, encodePreAuthData( app.getPaData() ) ) );
+		}
+		
+		sequence.add( new DERTaggedObject(3, DERGeneralString.valueOf( app.getClientRealm().toString() ) ) );
+		
+		sequence.add( new DERTaggedObject(4, PrincipalNameEncoder.encode( app.getClientPrincipal() ) ) );
+		
+		sequence.add( new DERTaggedObject(5, TicketEncoder.encode( app.getTicket() ) ) );
+		
+		sequence.add( new DERTaggedObject(6, EncryptedDataEncoder.encodeSequence( app.getEncPart() ) ) );
 		
 		return sequence;
 	}
@@ -78,20 +87,20 @@
 	           padata-value[2]       OCTET STRING,
 	                         -- might be encoded AP-REQ
 	}*/
-	private DERSequence encodePaData(PreAuthenticationData[] paData)
+	private DERSequence encodePreAuthData( PreAuthenticationData[] preAuthData )
 	{
-		DERSequence pa = new DERSequence();
+		DERSequence preAuth = new DERSequence();
 		
-		for (int i = 0; i < paData.length; i++)
+		for ( int ii = 0; ii < preAuthData.length; ii++ )
 		{
 			DERSequence sequence = new DERSequence();
 
-			sequence.add(new DERTaggedObject(1, DERInteger.valueOf(paData[i].getDataType().getOrdinal())));
-			sequence.add(new DERTaggedObject(2, new DEROctetString(paData[i].getDataValue())));
-			pa.add( sequence );
+			sequence.add( new DERTaggedObject( 1, DERInteger.valueOf( preAuthData[ii].getDataType().getOrdinal() ) ) );
+			sequence.add( new DERTaggedObject( 2, new DEROctetString( preAuthData[ii].getDataValue() ) ) );
+			preAuth.add( sequence );
 		}
 		
-		return pa;
+		return preAuth;
 	}
 }
 

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KdcReqBodyEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KdcReqBodyEncoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KdcReqBodyEncoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KdcReqBodyEncoder.java Thu Feb  3 13:57:13 2005
@@ -21,74 +21,104 @@
 import java.io.IOException;
 
 import org.apache.asn1.der.ASN1OutputStream;
+import org.apache.asn1.der.DERBitString;
+import org.apache.asn1.der.DERGeneralString;
 import org.apache.asn1.der.DERInteger;
 import org.apache.asn1.der.DERSequence;
 import org.apache.asn1.der.DERTaggedObject;
 import org.apache.kerberos.messages.KdcRequest;
 
-public class KdcReqBodyEncoder extends KerberosMessageEncoder {
 
-	public byte[] encode(KdcRequest request) throws IOException {
+public class KdcReqBodyEncoder
+{
+	public byte[] encode( KdcRequest request ) throws IOException
+	{
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		ASN1OutputStream aos = new ASN1OutputStream(baos);
+		ASN1OutputStream aos = new ASN1OutputStream( baos );
 		
-		aos.writeObject(encodeInitialSequence(request));
-		aos.flush();
+		aos.writeObject( encodeInitialSequence( request ) );
 		aos.close();
 
 		return baos.toByteArray();
 	}
 	
-	/*
-	KDC-REQ-BODY ::=   SEQUENCE {
-        kdc-options[0]       KDCOptions,
-        cname[1]             PrincipalName OPTIONAL,
-                     -- Used only in AS-REQ
-        realm[2]             Realm, -- Server's realm
-                     -- Also client's in AS-REQ
-        sname[3]             PrincipalName OPTIONAL,
-        from[4]              KerberosTime OPTIONAL,
-        till[5]              KerberosTime,
-        rtime[6]             KerberosTime OPTIONAL,
-        nonce[7]             INTEGER,
-
-        etype[8]             SEQUENCE OF INTEGER, -- EncryptionEngine,
-                     -- in preference order
-        addresses[9]         HostAddresses OPTIONAL,
-        enc-authorization-data[10]   EncryptedData OPTIONAL,
-                     -- Encrypted AuthorizationData encoding
-        additional-tickets[11]       SEQUENCE OF Ticket OPTIONAL
-    }*/
-	private DERSequence encodeInitialSequence(KdcRequest request) {
+	/**
+	 * KDC-REQ-BODY ::=   SEQUENCE {
+     *     kdc-options[0]       KDCOptions,
+     *     cname[1]             PrincipalName OPTIONAL,
+     *                  -- Used only in AS-REQ
+     *     realm[2]             Realm, -- Server's realm
+     *                  -- Also client's in AS-REQ
+     *     sname[3]             PrincipalName OPTIONAL,
+     *     from[4]              KerberosTime OPTIONAL,
+     *     till[5]              KerberosTime,
+     *     rtime[6]             KerberosTime OPTIONAL,
+     *     nonce[7]             INTEGER,
+     * 
+     *     etype[8]             SEQUENCE OF INTEGER, -- EncryptionEngine,
+     *                  -- in preference order
+     *     addresses[9]         HostAddresses OPTIONAL,
+     *     enc-authorization-data[10]   EncryptedData OPTIONAL,
+     *                  -- Encrypted AuthorizationData encoding
+     *     additional-tickets[11]       SEQUENCE OF Ticket OPTIONAL
+     * }
+     */
+	private DERSequence encodeInitialSequence( KdcRequest request )
+	{
 		DERSequence sequence = new DERSequence();
 		
-		sequence.add(new DERTaggedObject(0, encodeKdcOptions(request.getKdcOptions())));
+		sequence.add( new DERTaggedObject( 0, new DERBitString( request.getKdcOptions().getBytes() ) ) );
+		
 		// OPTIONAL
-		if (request.getClientPrincipal() != null)
-			sequence.add(new DERTaggedObject(1, encodePrincipalName(request.getClientPrincipal())));
-		sequence.add(new DERTaggedObject(2, encodeRealm(request.getRealm())));
+		if ( request.getClientPrincipal() != null )
+		{
+			sequence.add( new DERTaggedObject( 1, PrincipalNameEncoder.encode( request.getClientPrincipal() ) ) );
+		}
+		
+		sequence.add( new DERTaggedObject( 2, DERGeneralString.valueOf( request.getRealm().toString() ) ) );
+		
 		// OPTIONAL
-		if (request.getServerPrincipal() != null)
-			sequence.add(new DERTaggedObject(3, encodePrincipalName(request.getServerPrincipal())));
+		if ( request.getServerPrincipal() != null )
+		{
+			sequence.add( new DERTaggedObject( 3, PrincipalNameEncoder.encode( request.getServerPrincipal() ) ) );
+		}
+		
 		// OPTIONAL
 		if (request.getFrom() != null)
-			sequence.add(new DERTaggedObject(4, encodeKerberosTime(request.getFrom())));
-		sequence.add(new DERTaggedObject(5, encodeKerberosTime(request.getTill())));
+		{
+			sequence.add(new DERTaggedObject(4, KerberosTimeEncoder.encode(request.getFrom())));
+		}
+		
+		sequence.add( new DERTaggedObject( 5, KerberosTimeEncoder.encode( request.getTill() ) ) );
+		
 		// OPTIONAL
-		if (request.getRtime() != null)
-			sequence.add(new DERTaggedObject(6, encodeKerberosTime(request.getRtime())));
-		sequence.add(new DERTaggedObject(7, DERInteger.valueOf(request.getNonce())));
-		sequence.add(new DERTaggedObject(8, encodeEncryptionType(request.getEType())));
+		if ( request.getRtime() != null )
+		{
+			sequence.add( new DERTaggedObject( 6, KerberosTimeEncoder.encode( request.getRtime() ) ) );
+		}
+		
+		sequence.add( new DERTaggedObject( 7, DERInteger.valueOf( request.getNonce() ) ) );
+		
+		sequence.add( new DERTaggedObject( 8, EncryptionTypeEncoder.encode( request.getEType() ) ) );
+		
 		// OPTIONAL
-		if (request.getAddresses() != null)
-			sequence.add(new DERTaggedObject(9, encodeHostAddresses(request.getAddresses())));
+		if ( request.getAddresses() != null )
+		{
+			sequence.add( new DERTaggedObject( 9, HostAddressesEncoder.encodeSequence( request.getAddresses() ) ) );
+		}
+		
 		// OPTIONAL
-		if (request.getEncAuthorizationData() != null)
-			sequence.add(new DERTaggedObject(10, encodeEncryptedData(request.getEncAuthorizationData())));
+		if ( request.getEncAuthorizationData() != null )
+		{
+			sequence.add( new DERTaggedObject( 10, EncryptedDataEncoder.encodeSequence( request.getEncAuthorizationData() ) ) );
+		}
+		
 		// OPTIONAL
-		if (request.getAdditionalTickets() != null)
-			sequence.add(new DERTaggedObject(11, encodeAdditionalTickets(request.getAdditionalTickets())));
-
+		if ( request.getAdditionalTickets() != null )
+		{
+			sequence.add( new DERTaggedObject( 11, TicketEncoder.encodeSequence( request.getAdditionalTickets() ) ) );
+		}
+		
 		return sequence;
 	}
 }

Added: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KerberosTimeEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KerberosTimeEncoder.java?view=auto&rev=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KerberosTimeEncoder.java (added)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KerberosTimeEncoder.java Thu Feb  3 13:57:13 2005
@@ -0,0 +1,35 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.kerberos.io.encoder;
+
+import org.apache.asn1.der.DERGeneralizedTime;
+import org.apache.kerberos.messages.value.KerberosTime;
+
+
+public class KerberosTimeEncoder
+{
+	/**
+	 * KerberosTime ::=   GeneralizedTime
+	 *             -- Specifying UTC time zone (Z)
+	 */
+    protected static DERGeneralizedTime encode( KerberosTime time )
+    {
+    	return DERGeneralizedTime.valueOf( time.toDate() );
+    }
+}
+

Added: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/LastRequestEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/LastRequestEncoder.java?view=auto&rev=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/LastRequestEncoder.java (added)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/LastRequestEncoder.java Thu Feb  3 13:57:13 2005
@@ -0,0 +1,52 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.kerberos.io.encoder;
+
+import org.apache.asn1.der.DERGeneralizedTime;
+import org.apache.asn1.der.DERInteger;
+import org.apache.asn1.der.DERSequence;
+import org.apache.asn1.der.DERTaggedObject;
+import org.apache.kerberos.messages.value.LastRequest;
+import org.apache.kerberos.messages.value.LastRequestEntry;
+
+
+public class LastRequestEncoder
+{
+	/**
+	 * LastReq ::=   SEQUENCE OF SEQUENCE {
+	 * lr-type[0]               INTEGER,
+	 * lr-value[1]              KerberosTime
+	 * }
+	 */
+	protected static DERSequence encode( LastRequest lastReq )
+	{
+		LastRequestEntry[] entries = lastReq.getEntries();
+		DERSequence outerSequence = new DERSequence();
+		
+		for ( int ii = 0; ii < entries.length; ii++ )
+		{
+			DERSequence sequence = new DERSequence();
+			sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( entries[ii].getLastRequestType().getOrdinal() ) ) );
+			sequence.add( new DERTaggedObject( 1, DERGeneralizedTime.valueOf( entries[ii].getLastRequestValue().toDate() ) ) );
+			outerSequence.add( sequence );
+		}
+		
+		return outerSequence;
+	}
+}
+

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PreAuthenticationDataEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PreAuthenticationDataEncoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PreAuthenticationDataEncoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PreAuthenticationDataEncoder.java Thu Feb  3 13:57:13 2005
@@ -28,7 +28,7 @@
 import org.apache.kerberos.messages.value.PreAuthenticationData;
 
 
-public class PreAuthenticationDataEncoder extends KerberosMessageEncoder
+public class PreAuthenticationDataEncoder
 {
 	public byte[] encode( PreAuthenticationData preAuth ) throws IOException
 	{

Added: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PrincipalNameEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PrincipalNameEncoder.java?view=auto&rev=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PrincipalNameEncoder.java (added)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PrincipalNameEncoder.java Thu Feb  3 13:57:13 2005
@@ -0,0 +1,74 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.kerberos.io.encoder;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.security.auth.kerberos.KerberosPrincipal;
+
+import org.apache.asn1.der.DERGeneralString;
+import org.apache.asn1.der.DERInteger;
+import org.apache.asn1.der.DERSequence;
+import org.apache.asn1.der.DERTaggedObject;
+
+
+public class PrincipalNameEncoder
+{
+	private static final String COMPONENT_SEPARATOR = "/";
+	private static final String REALM_SEPARATOR     = "@";
+	
+	/**
+	 * PrincipalName ::=   SEQUENCE {
+	 *               name-type[0]     INTEGER,
+	 *               name-string[1]   SEQUENCE OF GeneralString
+	 * }
+	 */
+	protected static DERSequence encode( KerberosPrincipal principal )
+	{
+		DERSequence vector = new DERSequence();
+		
+		vector.add( new DERTaggedObject( 0, DERInteger.valueOf( principal.getNameType() ) ) );
+		vector.add( new DERTaggedObject( 1, encodeNameSequence( principal ) ) );
+		
+		return vector;
+	}
+	
+	private static DERSequence encodeNameSequence( KerberosPrincipal principal )
+	{
+		Iterator it = getNameStrings( principal ).iterator();
+		
+		DERSequence vector = new DERSequence();
+		
+		while ( it.hasNext() )
+		{
+			vector.add( DERGeneralString.valueOf( (String)it.next() ) );
+		}
+		
+		return vector;
+	}
+	
+	private static List getNameStrings( KerberosPrincipal principal )
+	{
+		String nameComponent = principal.getName().split( REALM_SEPARATOR )[0];
+		String[] components = nameComponent.split( COMPONENT_SEPARATOR );
+		return Arrays.asList( components );
+	}
+}
+

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PrivateMessageEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PrivateMessageEncoder.java?view=diff&r1=151238&r2=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PrivateMessageEncoder.java (original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PrivateMessageEncoder.java Thu Feb  3 13:57:13 2005
@@ -27,26 +27,28 @@
 import org.apache.asn1.der.DERTaggedObject;
 import org.apache.kerberos.messages.application.PrivateMessage;
 
-public class PrivateMessageEncoder extends KerberosMessageEncoder {
-	
-	public byte[] encode(PrivateMessage message) throws IOException {
+
+public class PrivateMessageEncoder
+{
+	public byte[] encode( PrivateMessage message ) throws IOException
+	{
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		ASN1OutputStream aos = new ASN1OutputStream(baos);
+		ASN1OutputStream aos = new ASN1OutputStream( baos );
 		
-		DERSequence privateMessageSequence = encodePrivateMessageSequence(message);
-		aos.writeObject( DERApplicationSpecific.valueOf(message.getMessageType().getOrdinal(), privateMessageSequence));
+		DERSequence privateMessageSequence = encodePrivateMessageSequence( message );
+		aos.writeObject( DERApplicationSpecific.valueOf( message.getMessageType().getOrdinal(), privateMessageSequence ) );
 		aos.close();
 		
 		return baos.toByteArray();
 	}
 	
-	private DERSequence encodePrivateMessageSequence(PrivateMessage message) {
-		
+	private DERSequence encodePrivateMessageSequence( PrivateMessage message )
+	{
 		DERSequence sequence = new DERSequence();
 		
-		sequence.add(new DERTaggedObject(0, DERInteger.valueOf( message.getProtocolVersionNumber() )));
-		sequence.add(new DERTaggedObject(1, DERInteger.valueOf( message.getMessageType().getOrdinal() )));
-		sequence.add(new DERTaggedObject(3, encodeEncryptedData( message.getEncryptedPart() )));
+		sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( message.getProtocolVersionNumber() ) ) );
+		sequence.add( new DERTaggedObject( 1, DERInteger.valueOf( message.getMessageType().getOrdinal() ) ) );
+		sequence.add( new DERTaggedObject( 3, EncryptedDataEncoder.encodeSequence( message.getEncryptedPart() ) ) );
 		
 		return sequence;
 	}

Added: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/TicketEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/TicketEncoder.java?view=auto&rev=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/TicketEncoder.java (added)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/TicketEncoder.java Thu Feb  3 13:57:13 2005
@@ -0,0 +1,75 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.kerberos.io.encoder;
+
+import org.apache.asn1.der.DERApplicationSpecific;
+import org.apache.asn1.der.DERGeneralString;
+import org.apache.asn1.der.DERInteger;
+import org.apache.asn1.der.DERSequence;
+import org.apache.asn1.der.DERTaggedObject;
+import org.apache.kerberos.messages.components.Ticket;
+
+
+public class TicketEncoder
+{
+	/**
+	 * Ticket ::=                    [APPLICATION 1] SEQUENCE {
+     *     tkt-vno[0]                   INTEGER,
+     *     realm[1]                     Realm,
+     *     sname[2]                     PrincipalName,
+     *     enc-part[3]                  EncryptedData
+     * }
+     */
+    protected static DERApplicationSpecific encode( Ticket ticket )
+    {
+		DERSequence vector = new DERSequence();
+		
+		vector.add( new DERTaggedObject( 0, DERInteger.valueOf( ticket.getTicketVersionNumber() ) ) );
+		vector.add( new DERTaggedObject( 1, DERGeneralString.valueOf( ticket.getRealm() ) ) );
+		vector.add( new DERTaggedObject( 2, PrincipalNameEncoder.encode( ticket.getServerPrincipal() ) ) );
+		vector.add( new DERTaggedObject( 3, EncryptedDataEncoder.encodeSequence( ticket.getEncPart() ) ) );
+		
+		DERApplicationSpecific ticketSequence = null;
+		
+		try
+		{
+			ticketSequence = DERApplicationSpecific.valueOf( 1, vector );
+		}
+		catch (Exception e)
+		{
+			e.printStackTrace();
+		}
+		
+		return ticketSequence;
+    }
+    
+	protected static DERSequence encodeSequence( Ticket[] tickets )
+	{
+		DERSequence outerVector = new DERSequence();
+
+		for ( int ii = 0; ii < tickets.length; ii++ )
+		{
+			DERSequence vector = new DERSequence();
+			vector.add( encode( tickets[ii] ) );
+			outerVector.add( vector );
+		}
+		
+		return outerVector;
+	}
+}
+

Added: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/TransitedEncodingEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/TransitedEncodingEncoder.java?view=auto&rev=151239
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/TransitedEncodingEncoder.java (added)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/TransitedEncodingEncoder.java Thu Feb  3 13:57:13 2005
@@ -0,0 +1,46 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.kerberos.io.encoder;
+
+import org.apache.asn1.der.DERInteger;
+import org.apache.asn1.der.DEROctetString;
+import org.apache.asn1.der.DERSequence;
+import org.apache.asn1.der.DERTaggedObject;
+import org.apache.kerberos.messages.value.TransitedEncoding;
+
+
+public class TransitedEncodingEncoder
+{
+	/**
+	 * TransitedEncoding ::=         SEQUENCE {
+     *     tr-type[0]  INTEGER, -- must be registered
+     *     contents[1]          OCTET STRING
+     * }
+     */
+	protected static DERSequence encode( TransitedEncoding te )
+	{
+		
+		DERSequence sequence = new DERSequence();
+		
+		sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( te.getType().getOrdinal() ) ) );
+		sequence.add( new DERTaggedObject( 1, new DEROctetString( te.getContents() ) ) );
+		
+		return sequence;
+	}
+}
+



Mime
View raw message