directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r291312 - /directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/util/IntegerDecoder.java
Date Sat, 24 Sep 2005 15:27:31 GMT
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



Mime
View raw message