From cd8bc0e0de73b3fefedd6d0aad5c9c5fd810c1e3 Mon Sep 17 00:00:00 2001
From: abobrov <abobrov@localhost>
Date: Wed, 31 Dec 2008 13:55:37 +0000
Subject: [PATCH] - [Issue 3694]  ASN.1 package does incorrect BER encoding/decoding for negative integers.

---
 opendj-sdk/opends/src/server/org/opends/server/protocols/asn1/ASN1Long.java |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/protocols/asn1/ASN1Long.java b/opendj-sdk/opends/src/server/org/opends/server/protocols/asn1/ASN1Long.java
index 5577c47..6bfc595 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/protocols/asn1/ASN1Long.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/protocols/asn1/ASN1Long.java
@@ -159,6 +159,7 @@
    * @throws  ASN1Exception  If the provided array is null or is not between one
    *                         and four bytes in length.
    */
+  @Override
   public void setValue(byte[] value)
          throws ASN1Exception
   {
@@ -214,6 +215,12 @@
     }
 
     long longValue = 0;
+
+    if (value[0] < 0)
+    {
+      longValue = 0xFFFFFFFFFFFFFFFFL;
+    }
+
     for (byte b : value)
     {
       longValue = (longValue << 8) | (b & 0xFF);
@@ -304,6 +311,12 @@
     System.arraycopy(encodedElement, valueStartPos, value, 0, length);
 
     long longValue = 0;
+
+    if (value[0] < 0)
+    {
+      longValue = 0xFFFFFFFFFFFFFFFFL;
+    }
+
     for (byte b : value)
     {
       longValue = (longValue << 8) | (b & 0xFF);
@@ -320,6 +333,7 @@
    *
    * @param  buffer  The buffer to which the information should be appended.
    */
+  @Override
   public void toString(StringBuilder buffer)
   {
     buffer.append("ASN1Long(type=");
@@ -340,6 +354,7 @@
    * @param  indent  The number of spaces that should be used to indent the
    *                 resulting string representation.
    */
+  @Override
   public void toString(StringBuilder buffer, int indent)
   {
     StringBuilder indentBuf = new StringBuilder(indent);

--
Gitblit v1.10.0