directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r128424 - in incubator/directory: asn1/trunk/der/src/java/org/apache/asn1/der kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder
Date Thu, 27 Jan 2005 20:48:38 GMT
Author: erodriguez
Date: Thu Jan 27 12:48:36 2005
New Revision: 128424

URL: http://svn.apache.org/viewcvs?view=rev&rev=128424
Log:
Better output stream encapsulation.
Modified:
   incubator/directory/asn1/trunk/der/src/java/org/apache/asn1/der/ASN1OutputStream.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/KerberosMessageEncoder.java

Modified: incubator/directory/asn1/trunk/der/src/java/org/apache/asn1/der/ASN1OutputStream.java
Url: http://svn.apache.org/viewcvs/incubator/directory/asn1/trunk/der/src/java/org/apache/asn1/der/ASN1OutputStream.java?view=diff&rev=128424&p1=incubator/directory/asn1/trunk/der/src/java/org/apache/asn1/der/ASN1OutputStream.java&r1=128423&p2=incubator/directory/asn1/trunk/der/src/java/org/apache/asn1/der/ASN1OutputStream.java&r2=128424
==============================================================================
--- incubator/directory/asn1/trunk/der/src/java/org/apache/asn1/der/ASN1OutputStream.java
(original)
+++ incubator/directory/asn1/trunk/der/src/java/org/apache/asn1/der/ASN1OutputStream.java
Thu Jan 27 12:48:36 2005
@@ -20,6 +20,7 @@
 import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.nio.ByteBuffer;
 
 
 public class ASN1OutputStream extends FilterOutputStream
@@ -27,6 +28,27 @@
     public ASN1OutputStream( OutputStream os )
     {
         super( os );
+    }
+    
+    public ASN1OutputStream( ByteBuffer out )
+    {
+        super( newOutputStream( out ) );
+    }
+    
+	public static OutputStream newOutputStream( final ByteBuffer buf )
+	{
+        return new OutputStream()
+		{
+            public synchronized void write( int integer ) throws IOException
+			{
+                buf.put( (byte)integer );
+            }
+    
+            public synchronized void write( byte[] bytes, int off, int len ) throws IOException
+			{
+                buf.put( bytes, off, len );
+            }
+        };
     }
 
     private void writeLength( int length )

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&rev=128424&p1=incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ErrorMessageEncoder.java&r1=128423&p2=incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/ErrorMessageEncoder.java&r2=128424
==============================================================================
--- 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 Jan 27 12:48:36 2005
@@ -30,11 +30,12 @@
 import org.apache.asn1.der.DERTaggedObject;
 import org.apache.kerberos.messages.ErrorMessage;
 
+
 public class ErrorMessageEncoder extends KerberosMessageEncoder
 {
 	public void encode( ErrorMessage message, ByteBuffer out ) throws IOException
 	{
-		ASN1OutputStream aos = new ASN1OutputStream( newOutputStream( out ) );
+		ASN1OutputStream aos = new ASN1OutputStream( out );
 		
 		DERSequence errorReply = encodeErrorMessageSequence( message );
 		aos.writeObject( DERApplicationSpecific.valueOf( message.getMessageType().getOrdinal(),
errorReply ) );
@@ -42,8 +43,8 @@
 		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);
 		
@@ -55,8 +56,8 @@
 		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())));

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&rev=128424&p1=incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KdcReplyEncoder.java&r1=128423&p2=incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KdcReplyEncoder.java&r2=128424
==============================================================================
--- 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 Jan 27 12:48:36 2005
@@ -29,6 +29,7 @@
 import org.apache.kerberos.messages.KdcReply;
 import org.apache.kerberos.messages.value.PreAuthenticationData;
 
+
 public class KdcReplyEncoder extends KerberosMessageEncoder
 {
 	/*
@@ -37,7 +38,7 @@
 	 */
 	public void encode( KdcReply app, ByteBuffer out ) throws IOException
 	{
-		ASN1OutputStream aos = new ASN1OutputStream( newOutputStream( out ) );
+		ASN1OutputStream aos = new ASN1OutputStream( out );
 		
 		DERSequence kdcrep = encodeKdcReplySequence( app );
 		aos.writeObject( DERApplicationSpecific.valueOf( app.getMessageType().getOrdinal(), kdcrep
) );
@@ -55,8 +56,8 @@
 	              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())));
@@ -77,11 +78,12 @@
 	           padata-value[2]       OCTET STRING,
 	                         -- might be encoded AP-REQ
 	}*/
-	private DERSequence encodePaData(PreAuthenticationData[] paData) {
-		
+	private DERSequence encodePaData(PreAuthenticationData[] paData)
+	{
 		DERSequence pa = new DERSequence();
 		
-		for (int i = 0; i < paData.length; i++) {
+		for (int i = 0; i < paData.length; i++)
+		{
 			DERSequence sequence = new DERSequence();
 
 			sequence.add(new DERTaggedObject(1, DERInteger.valueOf(paData[i].getDataType().getOrdinal())));

Modified: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KerberosMessageEncoder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KerberosMessageEncoder.java?view=diff&rev=128424&p1=incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KerberosMessageEncoder.java&r1=128423&p2=incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KerberosMessageEncoder.java&r2=128424
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KerberosMessageEncoder.java
(original)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/KerberosMessageEncoder.java
Thu Jan 27 12:48:36 2005
@@ -17,9 +17,6 @@
 
 package org.apache.kerberos.io.encoder;
 
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
@@ -54,29 +51,13 @@
 
 public abstract class KerberosMessageEncoder
 {
-	public static OutputStream newOutputStream( final ByteBuffer buf )
-	{
-        return new OutputStream()
-		{
-            public synchronized void write( int integer ) throws IOException
-			{
-                buf.put( (byte)integer );
-            }
-    
-            public synchronized void write( byte[] bytes, int off, int len ) throws IOException
-			{
-                buf.put( bytes, off, len );
-            }
-        };
-    }
-	
 	/*
 	PrincipalName ::=   SEQUENCE {
 	              name-type[0]     INTEGER,
 	              name-string[1]   SEQUENCE OF GeneralString
 	}*/
-	protected DERSequence encodePrincipalName(KerberosPrincipal principal) {
-		
+	protected DERSequence encodePrincipalName(KerberosPrincipal principal)
+	{
 		DERSequence vector = new DERSequence();
 		
 		vector.add(new DERTaggedObject(0, DERInteger.valueOf(principal.getNameType())));
@@ -85,7 +66,8 @@
 		return vector;
 	}
 	
-	protected DERSequence encodeNameSequence(KerberosPrincipal principal) {
+	protected DERSequence encodeNameSequence(KerberosPrincipal principal)
+	{
 		Iterator it = getNameStrings(principal).iterator();
 		
 		DERSequence vector = new DERSequence();
@@ -97,8 +79,8 @@
 		
 	}
 	
-	protected List getNameStrings(KerberosPrincipal principal) {
-		
+	protected List getNameStrings(KerberosPrincipal principal)
+	{
 		final String COMPONENT_SEPARATOR = "/";
 		final String REALM_SEPARATOR     = "@";
 		
@@ -114,8 +96,8 @@
         sname[2]                     PrincipalName,
         enc-part[3]                  EncryptedData
     }*/
-    protected DERApplicationSpecific encodeTicket(Ticket ticket) {
-    	
+    protected DERApplicationSpecific encodeTicket(Ticket ticket)
+    {
 		DERSequence vector = new DERSequence();
 		
 		vector.add(new DERTaggedObject(0, DERInteger.valueOf(ticket.getTicketVersionNumber())));
@@ -126,7 +108,9 @@
 		DERApplicationSpecific ticketSequence = null;
 		try {
 			ticketSequence = DERApplicationSpecific.valueOf( 1, vector );
-		} catch (Exception e) {
+		}
+		catch (Exception e)
+		{
 			e.printStackTrace();
 		}
 		return ticketSequence;
@@ -136,7 +120,8 @@
 	KerberosTime ::=   GeneralizedTime
 	            -- Specifying UTC time zone (Z)
 	*/
-    protected DERGeneralizedTime encodeKerberosTime(KerberosTime time) {
+    protected DERGeneralizedTime encodeKerberosTime(KerberosTime time)
+    {
     	return DERGeneralizedTime.valueOf( time.toDate() );
     }
 	
@@ -144,13 +129,15 @@
     etype[8]             SEQUENCE OF INTEGER, -- EncryptionEngine,
                 -- in preference order
     */
-	protected DERSequence encodeEncryptionType(EncryptionType[] eType) {
-		
+	protected DERSequence encodeEncryptionType(EncryptionType[] eType)
+	{
 		DERSequence outerVector = new DERSequence();
 		
-		for (int i = 0; i < eType.length; i++) {
+		for (int i = 0; i < eType.length; i++)
+		{
 			outerVector.add(DERInteger.valueOf(eType[i].getOrdinal()));
 		}
+		
 		return outerVector;
 	}
 	
@@ -159,12 +146,13 @@
 	                    addr-type[0]             INTEGER,
 	                    address[1]               OCTET STRING
 	}*/
-	protected DERSequence encodeHostAddresses(HostAddresses hosts) {
-		
+	protected DERSequence encodeHostAddresses(HostAddresses hosts)
+	{
 		HostAddress[] addresses = hosts.getAddresses();
 		DERSequence vector = new DERSequence();
 		
-		for (int i = 0; i < addresses.length; i++) {
+		for (int i = 0; i < addresses.length; i++)
+		{
 			vector.add(encodeHostAddress(addresses[i]));
 		}
 		
@@ -176,7 +164,8 @@
                         addr-type[0]             INTEGER,
                         address[1]               OCTET STRING
     }*/
-	protected DERSequence encodeHostAddress(HostAddress host) {
+	protected DERSequence encodeHostAddress(HostAddress host)
+	{
 		DERSequence vector = new DERSequence();
 		
 		vector.add(new DERTaggedObject(0, DERInteger.valueOf(host.getAddressType().getOrdinal())));
@@ -191,7 +180,8 @@
 	            kvno[1]      INTEGER OPTIONAL,
 	            cipher[2]    OCTET STRING -- ciphertext
 	}*/
-	protected DERSequence encodeEncryptedData(EncryptedData encPart) {
+	protected DERSequence encodeEncryptedData(EncryptedData encPart)
+	{
 		DERSequence vector = new DERSequence();
 		
 		vector.add(new DERTaggedObject(0, DERInteger.valueOf(encPart.getEncryptionType().getOrdinal())));
@@ -202,11 +192,13 @@
 		return vector;
 	}
 	
-	protected DERGeneralString encodeRealm(String realm) {
+	protected DERGeneralString encodeRealm(String realm)
+	{
 		return DERGeneralString.valueOf(realm.toString());
 	}
 	
-	protected DERSequence encodeEncryptionKey(EncryptionKey key) {
+	protected DERSequence encodeEncryptionKey(EncryptionKey key)
+	{
 		DERSequence vector = new DERSequence();
 		
 		vector.add(new DERTaggedObject(0, DERInteger.valueOf(key.getKeyType().getOrdinal())));
@@ -221,7 +213,8 @@
              checksum[1]    OCTET STRING
     }
 	*/
-	protected DERSequence encodeChecksum(Checksum checksum) {
+	protected DERSequence encodeChecksum(Checksum checksum)
+	{
 		DERSequence vector = new DERSequence();
 		
 		vector.add(new DERTaggedObject(0, DERInteger.valueOf(checksum.getChecksumType().getOrdinal())));
@@ -235,8 +228,8 @@
 	lr-type[0]               INTEGER,
 	lr-value[1]              KerberosTime
 	}*/
-	protected DERSequence encodeLastRequest(LastRequest lastReq) {
-
+	protected DERSequence encodeLastRequest(LastRequest lastReq)
+	{
 		LastRequestEntry[] entries = lastReq.getEntries();
 		DERSequence outerVector = new DERSequence();
 		for (int i = 0; i < entries.length; i++) {
@@ -255,7 +248,8 @@
 	    use-session-key(1),
 	    mutual-required(2)
 	}*/
-	protected DERBitString encodeApOptions(ApOptions options) {
+	protected DERBitString encodeApOptions(ApOptions options)
+	{
 		return new DERBitString(options.getBytes());
 	}
 	
@@ -274,7 +268,8 @@
 	      pre-authent(10),
 	      hw-authent(11)
 	}*/
-	protected DERBitString encodeTicketFlags(TicketFlags flags) {
+	protected DERBitString encodeTicketFlags(TicketFlags flags)
+	{
 		return new DERBitString(flags.getBytes());
 	}
 	
@@ -298,7 +293,8 @@
         renew(30),
         validate(31)
         }*/
-	protected DERBitString encodeKdcOptions(KdcOptions options) {
+	protected DERBitString encodeKdcOptions(KdcOptions options)
+	{
 		return new DERBitString(options.getBytes());
 	}
 	
@@ -307,7 +303,8 @@
         tr-type[0]  INTEGER, -- must be registered
         contents[1]          OCTET STRING
     }*/
-	protected DERSequence encodeTransitedEncoding(TransitedEncoding te) {
+	protected DERSequence encodeTransitedEncoding(TransitedEncoding te)
+	{
 		
 		DERSequence vector = new DERSequence();
 		
@@ -322,30 +319,34 @@
         ad-type[0]               INTEGER,
         ad-data[1]               OCTET STRING
     }*/
-	protected DERSequence encodeAuthorizationData(AuthorizationData data) {
-		
+	protected DERSequence encodeAuthorizationData(AuthorizationData data)
+	{
 		Iterator it = data.iterator();
 		DERSequence outerVector = new DERSequence();
 		
-		while (it.hasNext()) {
+		while (it.hasNext())
+		{
 			AuthorizationDataEntry entry = (AuthorizationDataEntry)it.next();
 			DERSequence vector = new DERSequence();
 			vector.add(new DERTaggedObject(0, DERInteger.valueOf(entry.getAuthorizationDataType().getOrdinal())));
 			vector.add(new DERTaggedObject(1, new DEROctetString(entry.getAuthorizationData())));
 			outerVector.add( vector );
 		}
+		
 		return outerVector;
 	}
 	
-	protected DERSequence encodeAdditionalTickets(Ticket[] tickets) {
-
+	protected DERSequence encodeAdditionalTickets(Ticket[] tickets)
+	{
 		DERSequence outerVector = new DERSequence();
 
-		for (int i = 0; i < tickets.length; i++) {
+		for (int i = 0; i < tickets.length; i++)
+		{
 			DERSequence vector = new DERSequence();
 			vector.add(encodeTicket(tickets[i]));
 			outerVector.add( vector );
 		}
+		
 		return outerVector;
 	}
 }

Mime
View raw message