You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/09/24 17:27:31 UTC

svn commit: r291312 - /directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/util/IntegerDecoder.java

Author: elecharny
Date: Sat Sep 24 08:27:28 2005
New Revision: 291312

URL: http://svn.apache.org/viewcvs?rev=291312&view=rev
Log:
fixed the decoding to be able to handle negative values

Modified:
    directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/util/IntegerDecoder.java

Modified: directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/util/IntegerDecoder.java
URL: http://svn.apache.org/viewcvs/directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/util/IntegerDecoder.java?rev=291312&r1=291311&r2=291312&view=diff
==============================================================================
--- directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/util/IntegerDecoder.java (original)
+++ directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/util/IntegerDecoder.java Sat Sep 24 08:27:28 2005
@@ -27,6 +27,8 @@
  */
 public class IntegerDecoder
 {
+    private static final int[] MASK = new int[]{ 0x000000FF, 0x0000FFFF, 0x00FFFFFF, 0xFFFFFFFF};
+    
     //~ Methods ------------------------------------------------------------------------------------
 
     /**
@@ -58,9 +60,13 @@
             result = ( result << 8 ) | ( bytes[i] & 0x00FF );
         }
 
-        if ( ( result >= min ) && ( result <= max ) )
+        if ( ( bytes[0] & 0x80 ) == 0x80 )
         {
+            result = - ( ( ( ~ result ) + 1 ) & MASK[bytes.length - 1] );
+        }
 
+        if ( ( result >= min ) && ( result <= max ) )
+        {
             return result;
         }
         else