directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r155351 - in incubator/directory/asn1/branches/rewrite/ber/src: java/org/apache/asn1/ber/Tag.java java/org/apache/asn1/ber/Tuple.java test/org/apache/asn1/ber/MultiByteTagTests.java test/org/apache/asn1/ber/TagTest.java test/org/apache/asn1/ber/TupleTest.java
Date Fri, 25 Feb 2005 17:51:58 GMT
Author: akarasulu
Date: Fri Feb 25 09:51:57 2005
New Revision: 155351

URL: http://svn.apache.org/viewcvs?view=rev&rev=155351
Log:
applying changes to trunk by Alan and Emmanuel

Modified:
    incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/ber/Tag.java
    incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/ber/Tuple.java
    incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/MultiByteTagTests.java
    incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/TagTest.java
    incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/TupleTest.java

Modified: incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/ber/Tag.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/ber/Tag.java?view=diff&r1=155350&r2=155351
==============================================================================
--- incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/ber/Tag.java (original)
+++ incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/ber/Tag.java Fri
Feb 25 09:51:57 2005
@@ -318,8 +318,7 @@
         // calculate tag value w/ long tag format
         for( int ii = 1 ; ii < octets.length; ii++ )
         {
-            int shift = ( ii - 1 ) * 7 ;
-            id |= ( octets[ii] & LONG_MASK ) << shift ;
+        	id = (id << 7) | (octets[ii] & LONG_MASK);
         }
 
         return id ;
@@ -407,8 +406,7 @@
         // calculate tag value w/ long tag format
         for( int ii = 1 ; ii < octets.size(); ii++ )
         {    
-            int shift = ( ii - 1 ) * 7 ;
-            id |= ( octets.get( ii ) & LONG_MASK ) << shift ;
+        	id = (id << 7) | (octets.get(ii) & LONG_MASK);
         }
         
         return id ;

Modified: incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/ber/Tuple.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/ber/Tuple.java?view=diff&r1=155350&r2=155351
==============================================================================
--- incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/ber/Tuple.java
(original)
+++ incubator/directory/asn1/branches/rewrite/ber/src/java/org/apache/asn1/ber/Tuple.java
Fri Feb 25 09:51:57 2005
@@ -540,111 +540,60 @@
      */
     public void setTag( ByteBuffer octets, int tagLength )
     {
-        int ii = octets.position();
-        octets.put( ( byte ) typeClass.getValue() ) ;
-        
-        if ( ! isPrimitive )
-        {
-            octets.put( ii, ( byte ) ( octets.get( ii ) | BIT_5 ) ) ;
-        }
-        
-        if ( tagLength == 1 )
-        {
-            octets.put( ii, ( byte ) ( octets.get( ii ) | id ) ) ;
-            return ;
-        }
-        
-        octets.put( ii, ( byte ) ( octets.get( ii ) | Tag.SHORT_MASK ) ) ;
-        
-        if ( tagLength >= 2 )
-        {
-            ii++;
-            octets.put( ( byte ) ( ( int ) 0x7f & id ) ) ;
-            
-            if ( tagLength > 2 )
-            {
-                octets.put( ii, ( byte ) ( octets.get( ii ) | BIT_7 ) ) ;
-            }
-        }
-        else
-        {
-            return ;
-        }
-        
-        /* 
-         * Take bits [8-14] (1 based bit indexing) inclusive in id and set the
-         * value for the second byte to this when shifted down 7 positions so
-         * we need the following mask:
-         * 
-         * 0011 1111 1000 0000 => 0x3f80
-         * 
-         */
-        if ( tagLength >= 3 )
-        {
-            ii++;
-            octets.put( ( byte ) ( ( ( int ) 0x3f80 & id ) >> 7 ) ) ;
-            
-            if ( tagLength > 3 )
-            {
-                octets.put( ii, ( byte ) ( octets.get( ii ) | BIT_7 ) ) ;
-            }
-        }
-        else
-        {
-            return ;
-        }
-        
-        /* 
-         * Take bits [15-21] (1 based bit indexing) inclusive in id and set the
-         * value for the second byte to this when shifted down 14 positions so
-         * we need the following mask:
-         * 
-         * 0001 1111 1100 0000 0000 0000 => 0x1fc000
-         * 
-         */
-        if ( tagLength >= 4 )
-        {
-            ii++;
-            octets.put( ( byte ) ( ( ( int ) 0x1fc000 & id ) >> 14 ) ) ;
-            
-            if ( tagLength > 4 )
-            {
-                octets.put( ii, ( byte ) ( octets.get( ii ) | BIT_7 ) ) ;
-            }
-        }
-        else
-        {
-            return ;
-        }
-        
-        /* 
-         * Take bits [22-28] (1 based bit indexing) inclusive in id and set the
-         * value for the second byte to this when shifted down 21 positions so
-         * we need the following mask:
-         * 
-         * 0000 1111 1110 0000 0000 0000 0000 0000 => 0x0fe00000
-         * 
-         */
-        if ( tagLength >= 5 )
-        {
-            ii++;
-            octets.put( ( byte ) ( ( ( int ) 0x0fe00000 & id ) >> 21 ) ) ;
-            
-            if ( tagLength > 5 )
-            {
-                octets.put( ii, ( byte ) ( octets.get( ii ) | BIT_7 ) ) ;
-            }
-        }
-        else
-        {
-            return ;
-        }
-        
         if ( tagLength >= 6 )
         {    
             throw new IllegalArgumentException( "cannot support id's as large "
                     + "as " + id + " unless we start using longs for the id" ) ;
         }
+
+        byte octet = ( byte ) typeClass.getValue() ;
+        int i = octets.position();
+        
+        if ( ! isPrimitive )
+        {
+            octet |= BIT_5;
+        }
+        
+		if ( id < 31 ) 
+		{
+            octets.put( ( byte ) ( octet | (id & Tag.SHORT_MASK ) ) ) ;
+            return;
+			
+		} 
+		else
+		{
+            octets.put( ( byte ) ( octet | Tag.SHORT_MASK ) ) ;
+            i++;
+		}
+
+		switch ( tagLength - 1) {
+        	case 5 :
+                octets.put( ( byte ) ( ( ( id >> 21 ) & Tag.LONG_MASK ) | BIT_7
) ) ;
+                i++;
+                // fallthrough
+
+        	case 4:
+                octets.put( ( byte ) ( ( ( id >> 21 ) & Tag.LONG_MASK ) | BIT_7
) ) ;
+                i++;
+                // fallthrough
+
+        	case 3 :
+                octets.put( ( byte ) ( ( ( id >> 14 ) & Tag.LONG_MASK ) | BIT_7
) ) ;
+                i++;
+                // fallthrough
+
+        	case 2 :
+                octets.put( ( byte ) ( ( ( id >> 7 ) & Tag.LONG_MASK ) | BIT_7
) ) ;
+                i++;
+                // fallthrough
+
+        	case 1 :
+                octets.put( ( byte ) ( id  & Tag.LONG_MASK ) ) ;
+                break;
+        }
+
+		//octets.f
+        return ;
     }
 
 

Modified: incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/MultiByteTagTests.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/MultiByteTagTests.java?view=diff&r1=155350&r2=155351
==============================================================================
--- incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/MultiByteTagTests.java
(original)
+++ incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/MultiByteTagTests.java
Fri Feb 25 09:51:57 2005
@@ -111,7 +111,7 @@
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
 
         tlv = decode( "00000001" ) ;
-        assertEquals( 128, tlv.id ) ;
+        assertEquals( 1, tlv.id ) ;
         assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
     }
 
@@ -146,7 +146,7 @@
         assertEquals( TypeClass.APPLICATION, tlv.typeClass ) ;
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
 
-        tlv = decode( "10000000" ) ;
+        tlv = decode( "10000001" ) ;
         assertEquals( 0, tlv.id ) ;
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
 
@@ -154,7 +154,7 @@
         assertEquals( 0, tlv.id ) ;
         assertEquals( BERDecoderState.TAG, decoder.getState() ) ;
 
-        tlv = decode( "00000001" ) ;
+        tlv = decode( "00000000" ) ;
         assertEquals( BIT_13, tlv.id ) ;
         assertEquals( BERDecoderState.LENGTH, decoder.getState() ) ;
     }

Modified: incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/TagTest.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/TagTest.java?view=diff&r1=155350&r2=155351
==============================================================================
--- incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/TagTest.java
(original)
+++ incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/TagTest.java
Fri Feb 25 09:51:57 2005
@@ -203,8 +203,8 @@
 
         for ( int ii = 128 ; ii < 20000; ii++ )
         {
-            octets[1] = ( byte ) ( ii & Tag.LONG_MASK ) ;
-            octets[2] = ( byte ) ( ( ii >> 7 ) & Tag.LONG_MASK ) ;
+            octets[1] = (byte)((ii >> 7) & Tag.LONG_MASK);
+            octets[2] = (byte)(ii & Tag.LONG_MASK);
 
             if ( ii < 16384 )
             {
@@ -224,9 +224,9 @@
 
         for ( int ii = 16384 ; ii < 2100000 ; ii++ )
         {
-            octets[1] = ( byte ) ( ii & Tag.LONG_MASK ) ;
-            octets[2] = ( byte ) ( ( ii >> 7 ) & Tag.LONG_MASK ) ;
-            octets[3] = ( byte ) ( ( ii >> 14 ) & Tag.LONG_MASK ) ;
+            octets[1] = (byte)((ii >> 14) & Tag.LONG_MASK);
+            octets[2] = (byte)((ii >> 7) & Tag.LONG_MASK);
+            octets[3] = (byte)(ii & Tag.LONG_MASK);
 
             if ( ii < 2097152 )
             {

Modified: incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/TupleTest.java
URL: http://svn.apache.org/viewcvs/incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/TupleTest.java?view=diff&r1=155350&r2=155351
==============================================================================
--- incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/TupleTest.java
(original)
+++ incubator/directory/asn1/branches/rewrite/ber/src/test/org/apache/asn1/ber/TupleTest.java
Fri Feb 25 09:51:57 2005
@@ -401,8 +401,8 @@
         encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
         assertEquals(
                 "00000000" +
-                "00000001" +
-                "10000000" +
+                "00000000" +
+                "10000001" +
                 "01111111"
                 , toAsciiString( encoded ) ) ;
 
@@ -412,8 +412,8 @@
         encoded = t.toEncodedBuffer( list ) ;
         assertEquals(
                 "01111111" +
-                "00000001" +
-                "10000000" +
+                "00000000" +
+                "10000001" +
                 "01111111"
                 , toAsciiString( encoded ) ) ;
 
@@ -424,8 +424,8 @@
         assertEquals(
                 "10000000" +
                 "10000001" +
-                "00000001" +
-                "10000000" +
+                "00000000" +
+                "10000001" +
                 "01111111"
                 , toAsciiString( encoded ) ) ;
 
@@ -436,8 +436,8 @@
         assertEquals(
                 "11111111" +
                 "10000001" +
-                "00000001" +
-                "10000000" +
+                "00000000" +
+                "10000001" +
                 "01111111"
                 , toAsciiString( encoded ) ) ;
 
@@ -449,8 +449,8 @@
                 "00000000" +
                 "00000001" +
                 "10000010" +
-                "00000001" +
-                "10000000" +
+                "00000000" +
+                "10000001" +
                 "01111111"
                 , toAsciiString( encoded ) ) ;
     }
@@ -494,8 +494,8 @@
         encoded = t.toEncodedBuffer( Collections.EMPTY_LIST ) ;
         assertEquals(
                 "00000000" +
-                "00000001" +
-                "10000000" +
+                "00000000" +
+                "10000001" +
                 "01011111"
                 , toAsciiString( encoded ) ) ;
 
@@ -507,8 +507,8 @@
         assertEquals(
                 "00000000" +
                 "00000001" +
-                "00000001" +
-                "10000000" +
+                "00000000" +
+                "10000001" +
                 "01011111"
                 , toAsciiString( encoded ) ) ;
 
@@ -519,8 +519,8 @@
         encoded = t.toEncodedBuffer( list ) ;
         assertEquals( BinaryCodec.toAsciiString( data ) +
                 "01111111" +
-                "00000001" +
-                "10000000" +
+                "00000000" +
+                "10000001" +
                 "01011111"
                 , toAsciiString( encoded ) ) ;
 
@@ -532,8 +532,8 @@
         assertEquals( BinaryCodec.toAsciiString( data ) +
                 "10000000" +
                 "10000001" +
-                "00000001" +
-                "10000000" +
+                "00000000" +
+                "10000001" +
                 "01011111"
                 , toAsciiString( encoded ) ) ;
 
@@ -545,8 +545,8 @@
         assertEquals( BinaryCodec.toAsciiString( data ) +
                 "11111111" +
                 "10000001" +
-                "00000001" +
-                "10000000" +
+                "00000000" +
+                "10000001" +
                 "01011111"
                 , toAsciiString( encoded ) ) ;
 
@@ -559,8 +559,8 @@
                 "00000000" +
                 "00000001" +
                 "10000010" +
-                "00000001" +
-                "10000000" +
+                "00000000" +
+                "10000001" +
                 "01011111"
                 , toAsciiString( encoded ) ) ;
     }
@@ -609,7 +609,7 @@
         t = new Tuple( 128, 0 ) ;
         t.setTag( bites, 3 ) ;
         binary = toAsciiString( bites ) ;
-        assertEquals( "00000001" + "10000000" + "01111111", binary ) ;
+        assertEquals( "00000000" + "10000001" + "01111111", binary ) ;
 
         bites = ByteBuffer.allocate( 3 ) ;
         t = new Tuple( BIT_13 - 1, 0 ) ;
@@ -623,9 +623,9 @@
         t = new Tuple( BIT_13, 0 ) ;
         t.setTag( bites, 4 ) ;
         binary = toAsciiString( bites ) ;
-        assertEquals( "00000001" +
+        assertEquals( "00000000" +
                       "10000000" +
-                      "10000000" + 
+                      "10000001" + 
                       "01111111", binary ) ;
 
         bites = ByteBuffer.allocate( 4 ) ;
@@ -650,10 +650,10 @@
         t = new Tuple( BIT_20, 0 ) ;
         t.setTag( bites, 5 ) ;
         binary = toAsciiString( bites ) ;
-        assertEquals( "00000001" +
+        assertEquals( "00000000" +
                       "10000000" +
                       "10000000" +
-                      "10000000" + 
+                      "10000001" + 
                       "01111111", binary ) ;
 
         bites = ByteBuffer.allocate( 5 ) ;
@@ -727,7 +727,7 @@
         t = new Tuple( 128, 0 ) ;
         t.setTag( bites, 3 ) ;
         binary = toAsciiString( bites ) ;
-        assertEquals( "00000001" + "10000000" + "01111111", binary ) ;
+        assertEquals( "00000000" + "10000001" + "01111111", binary ) ;
 
         bites = ByteBuffer.allocate( 3 ) ;
         t = new Tuple( BIT_13 - 1, 0 ) ;
@@ -741,9 +741,9 @@
         t = new Tuple( BIT_13, 0 ) ;
         t.setTag( bites, 4 ) ;
         binary = toAsciiString( bites ) ;
-        assertEquals( "00000001" +
+        assertEquals( "00000000" +
                       "10000000" +
-                      "10000000" + 
+                      "10000001" + 
                       "01111111", binary ) ;
 
         bites = ByteBuffer.allocate( 4 ) ;
@@ -768,10 +768,10 @@
         t = new Tuple( BIT_20, 0 ) ;
         t.setTag( bites, 5 ) ;
         binary = toAsciiString( bites ) ;
-        assertEquals( "00000001" +
+        assertEquals( "00000000" +
                       "10000000" +
                       "10000000" +
-                      "10000000" + 
+                      "10000001" + 
                       "01111111", binary ) ;
 
         bites = ByteBuffer.allocate( 5 ) ;



Mime
View raw message