directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r151204 - in incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io: decoder/EncryptedTimestampDecoder.java encoder/EncryptedDataEncoder.java
Date Thu, 03 Feb 2005 18:49:09 GMT
Author: erodriguez
Date: Thu Feb  3 10:49:07 2005
New Revision: 151204

URL: http://svn.apache.org/viewcvs?view=rev&rev=151204
Log:
More codec work.

Added:
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedDataEncoder.java
Modified:
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/EncryptedTimestampDecoder.java

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/EncryptedTimestampDecoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/EncryptedTimestampDecoder.java?view=diff&r1=151203&r2=151204
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/EncryptedTimestampDecoder.java
(original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/decoder/EncryptedTimestampDecoder.java
Thu Feb  3 10:49:07 2005
@@ -44,7 +44,11 @@
 	{
 		ASN1InputStream ais = new ASN1InputStream( encodedEncryptedTimestamp );
 		
-		DERSequence sequence = (DERSequence) ais.readObject();
+		Object obj = ais.readObject();
+		
+		System.out.println( "Class to be cast to " + obj );
+		
+		DERSequence sequence = (DERSequence) obj;
 		
 		return decodeEncryptedTimestamp( sequence );
 	}

Added: 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=auto&rev=151204
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedDataEncoder.java
(added)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedDataEncoder.java
Thu Feb  3 10:49:07 2005
@@ -0,0 +1,67 @@
+/*
+ *   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.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.asn1.der.ASN1OutputStream;
+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.EncryptedData;
+
+
+public class EncryptedDataEncoder
+{
+	public byte[] encode( EncryptedData encryptedData ) throws IOException
+	{
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ASN1OutputStream aos = new ASN1OutputStream( baos );
+		
+		aos.writeObject( encodeEncryptedData( encryptedData ) );
+		aos.close();
+
+		return baos.toByteArray();
+	}
+	
+	/**
+	 * EncryptedData ::=   SEQUENCE {
+	 *             etype[0]     INTEGER, -- EncryptionEngine
+	 *             kvno[1]      INTEGER OPTIONAL,
+	 *             cipher[2]    OCTET STRING -- ciphertext
+	 * }
+	 */
+	protected DERSequence encodeEncryptedData( EncryptedData encryptedData )
+	{
+		DERSequence sequence = new DERSequence();
+		
+		sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( encryptedData.getEncryptionType().getOrdinal()
) ) );
+		
+		if ( encryptedData.getKeyVersion() > 0 )
+		{
+			sequence.add( new DERTaggedObject( 1, DERInteger.valueOf( encryptedData.getKeyVersion()
) ) );
+		}
+		
+		sequence.add( new DERTaggedObject( 2, new DEROctetString( encryptedData.getCipherText()
) ) );
+		
+		return sequence;
+	}
+}
+



Mime
View raw message