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 2015/10/27 11:16:00 UTC

svn commit: r1710759 - in /directory/shared/trunk/asn1/api/src: main/java/org/apache/directory/api/asn1/util/Oid.java test/java/org/apache/directory/api/asn1/util/OidTest.java

Author: elecharny
Date: Tue Oct 27 10:16:00 2015
New Revision: 1710759

URL: http://svn.apache.org/viewvc?rev=1710759&view=rev
Log:
o Fixed the Oid.fromBytes() method
o Added some checks in the tests

Modified:
    directory/shared/trunk/asn1/api/src/main/java/org/apache/directory/api/asn1/util/Oid.java
    directory/shared/trunk/asn1/api/src/test/java/org/apache/directory/api/asn1/util/OidTest.java

Modified: directory/shared/trunk/asn1/api/src/main/java/org/apache/directory/api/asn1/util/Oid.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/api/src/main/java/org/apache/directory/api/asn1/util/Oid.java?rev=1710759&r1=1710758&r2=1710759&view=diff
==============================================================================
--- directory/shared/trunk/asn1/api/src/main/java/org/apache/directory/api/asn1/util/Oid.java (original)
+++ directory/shared/trunk/asn1/api/src/main/java/org/apache/directory/api/asn1/util/Oid.java Tue Oct 27 10:16:00 2015
@@ -20,7 +20,6 @@
 package org.apache.directory.api.asn1.util;
 
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.math.BigInteger;
@@ -191,9 +190,12 @@ public final class Oid
             throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, Arrays.toString( oidBytes ) ) );
         }
 
-        StringBuilder builder = null;
+        StringBuilder builder = new StringBuilder();
         long value = 0;
-
+        int valStart = 0;
+        int valLength = 0;
+        boolean firstArc = true;
+        
         for ( int i = 0; i < oidBytes.length; i++ )
         {
             value |= oidBytes[i] & 0x7F;
@@ -202,114 +204,168 @@ public final class Oid
             {
                 // leading 1, so value continues
                 value = value << 7;
+                valLength++;
             }
             else
             {
-                // value completed
-                if ( builder == null )
+                valLength++;
+                
+                if ( valLength > 8 )
                 {
-                    builder = new StringBuilder();
-
-                    // first value special processing
-                    if ( value >= 80 )
+                    // Above 9 bytes, we won't be able to store the value in a long...
+                    // Compute the number of necessary bytes
+                    int nbBytes = valLength * 7 / 8;
+                    
+                    if ( valLength % 7 != 0 )
                     {
-                        // starts with 2
-                        builder.append( 2 );
-                        value = value - 80;
+                        nbBytes++;
                     }
-                    else
+                    
+                    byte[] result = new byte[nbBytes];
+                    
+                    // Now iterate on the incoming bytes
+                    int pos = nbBytes - 1;
+                    int valEnd = valStart + valLength - 1;
+                    int j = 0;
+                    
+                    while ( j < valLength - 8 )
                     {
-                        // starts with 0 or 1
-                        long one = value / 40;
-                        long two = value % 40;
-
-                        if ( ( one < 0 ) || ( one > 2 ) || ( two < 0 ) || ( ( one < 2 ) && ( two > 39 ) ) )
+                        result[pos--] = ( byte ) ( ( oidBytes[valEnd - j - 1] << 7 ) | ( oidBytes[valEnd - j] & 0x7F ) );
+                        result[pos--] = ( byte ) ( ( oidBytes[valEnd - j - 2] << 6 ) | ( ( oidBytes[valEnd - j - 1] & 0x7E ) >> 1 ) );
+                        result[pos--] = ( byte ) ( ( oidBytes[valEnd - j - 3] << 5 ) | ( ( oidBytes[valEnd - j - 2] & 0x7C ) >> 2 ) );
+                        result[pos--] = ( byte ) ( ( oidBytes[valEnd - j - 4] << 4 ) | ( ( oidBytes[valEnd - j - 3] & 0x78 ) >> 3 ) );
+                        result[pos--] = ( byte ) ( ( oidBytes[valEnd - j - 5] << 3 ) | ( ( oidBytes[valEnd - j - 4] & 0x70 ) >> 4 ) );
+                        result[pos--] = ( byte ) ( ( oidBytes[valEnd - j - 6] << 2 ) | ( ( oidBytes[valEnd - j - 5] & 0x60 ) >> 5 ) );
+                        result[pos--] = ( byte ) ( ( oidBytes[valEnd - j - 7] << 1 ) | ( ( oidBytes[valEnd - j - 6] & 0x40 ) >> 6 ) );
+                        j += 8;
+                    }
+                    
+                    switch ( valLength - j )
+                    {
+                        case 7 :
+                            result[pos--] = ( byte ) ( ( oidBytes[5] << 7 ) | ( oidBytes[6] & 0x7F ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[4] << 6 ) | ( ( oidBytes[5] & 0x7E ) >> 1 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[3] << 5 ) | ( ( oidBytes[4] & 0x7C ) >> 2 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[2] << 4 ) | ( ( oidBytes[3] & 0x78 ) >> 3 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[1] << 3 ) | ( ( oidBytes[2] & 0x70 ) >> 4 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[0] << 2 ) | ( ( oidBytes[1] & 0x60 ) >> 5 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[0] & 0x40 ) >> 6 );
+                            break;
+                            
+                        case 6 :
+                            result[pos--] = ( byte ) ( ( oidBytes[4] << 7 ) | ( oidBytes[5] & 0x7F ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[3] << 6 ) | ( ( oidBytes[4] & 0x7E ) >> 1 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[2] << 5 ) | ( ( oidBytes[3] & 0x7C ) >> 2 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[1] << 4 ) | ( ( oidBytes[2] & 0x78 ) >> 3 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[0] << 3 ) | ( ( oidBytes[1] & 0x70 ) >> 4 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[0] & 0x60 ) >> 5 );
+                            break;
+
+                        case 5 :
+                            result[pos--] = ( byte ) ( ( oidBytes[3] << 7 ) | ( oidBytes[4] & 0x7F ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[2] << 6 ) | ( ( oidBytes[3] & 0x7E ) >> 1 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[1] << 5 ) | ( ( oidBytes[2] & 0x7C ) >> 2 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[0] << 4 ) | ( ( oidBytes[1] & 0x78 ) >> 3 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[0] & 0x70 ) >> 4 );
+                            break;
+                            
+                        case 4 :
+                            result[pos--] = ( byte ) ( ( oidBytes[2] << 7 ) | ( oidBytes[3] & 0x7F ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[1] << 6 ) | ( ( oidBytes[2] & 0x7E ) >> 1 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[0] << 5 ) | ( ( oidBytes[1] & 0x7C ) >> 2 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[0] & 0x78 ) >> 3 );
+                            break;
+                            
+                        case 3 :
+                            result[pos--] = ( byte ) ( ( oidBytes[1] << 7 ) | ( oidBytes[2] & 0x7F ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[0] << 6 ) | ( ( oidBytes[1] & 0x7E ) >> 1 ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[0] & 0x7C ) >> 2 );
+                            break;
+
+                        case 2 :
+                            result[pos--] = ( byte ) ( ( oidBytes[0] << 7 ) | ( oidBytes[1] & 0x7F ) );
+                            result[pos--] = ( byte ) ( ( oidBytes[0] & 0x7E ) >> 1 );
+                            break;
+                            
+                        case 1 :
+                            result[pos--] = ( byte ) ( oidBytes[0] & 0x7F );
+                            break;
+                            
+                        default :
+                            // Exist to please checkstyle...
+                            break;
+                    }
+                    
+                    BigInteger bigInteger = null;
+                    
+                    if ( ( result[0] & 0x80 ) == 0x80 )
+                    {
+                        byte[] newResult = new byte[result.length + 1];
+                        System.arraycopy( result, 0, newResult, 1, result.length );
+                        result = newResult;
+                    }
+                    
+                    bigInteger = new BigInteger( result );
+                    
+                    if ( firstArc )
+                    {
+                        // This is a joint-iso-itu-t(2) arc
+                        bigInteger = bigInteger.subtract( JOINT_ISO_ITU_T );
+                        builder.append( '2' );
+                    }
+                    
+                    builder.append( '.' ).append( bigInteger.toString() );
+                }
+                else
+                {
+                    // value completed
+                    if ( firstArc )
+                    {
+                        // first value special processing
+                        if ( value >= 80 )
                         {
-                            throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID,
-                                Arrays.toString( oidBytes ) ) );
+                            // starts with 2
+                            builder.append( '2' );
+                            value = value - 80;
                         }
-
-                        if ( one < 2 )
+                        else
                         {
-                            builder.append( one );
-                            value = two;
+                            // starts with 0 or 1
+                            long one = value / 40;
+                            long two = value % 40;
+    
+                            if ( ( one < 0 ) || ( one > 2 ) || ( two < 0 ) || ( ( one < 2 ) && ( two > 39 ) ) )
+                            {
+                                throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID,
+                                    Arrays.toString( oidBytes ) ) );
+                            }
+    
+                            if ( one < 2 )
+                            {
+                                builder.append( one );
+                                value = two;
+                            }
                         }
+                        
+                        firstArc = false;
                     }
+    
+                    // normal processing
+                    builder.append( '.' ).append( value );
+                    value = 0;
                 }
-
-                // normal processing
-                builder.append( '.' ).append( value );
+                
+                valStart = i;
+                valLength = 0;
                 value = 0;
             }
         }
-
-        if ( builder == null )
-        {
-            throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, Arrays.toString( oidBytes ) ) );
-        }
-
+    
         return new Oid( builder.toString(), oidBytes );
     }
 
 
     /**
-     * Returns an OID object representing <code>oidString</code>.  
-     *  
-     * @param oidString The string representation of the OID
-     * @return A new Oid
-     * @throws DecoderException  When the OID is not valid
-     *
-    public static Oid fromStringLong( String oidString ) throws DecoderException
-    {
-        if ( ( oidString == null ) || oidString.isEmpty() )
-        {
-            throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, "" ) );
-        }
-
-        Queue<Long> segments = new LinkedList<Long>();
-
-        for ( String segment : oidString.split( "\\.", -1 ) )
-        {
-            try
-            {
-                segments.add( Long.parseLong( segment ) );
-            }
-            catch ( NumberFormatException nfe )
-            {
-                throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, oidString ), nfe );
-            }
-        }
-
-        // first segment special case
-        ByteBuffer buffer = new ByteBuffer();
-        Long segmentOne = segments.poll();
-
-        if ( ( segmentOne == null ) || ( segmentOne < 0 ) || ( segmentOne > 2 ) )
-        {
-            throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, oidString ) );
-        }
-
-        // second segment special case
-        Long segment = segments.poll();
-
-        if ( ( segment == null ) || ( segment < 0 ) || ( ( segmentOne < 2 ) && ( segment > 39 ) ) )
-        {
-            throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, oidString ) );
-        }
-
-        buffer.append( ( segmentOne * 40 ) + segment );
-
-        // the rest
-        while ( ( segment = segments.poll() ) != null )
-        {
-            buffer.append( segment );
-        }
-
-        return new Oid( oidString, buffer.toByteArray() );
-    }
-
-    
-    /**
      * Process state A
      * <pre>
      * (Start) --['0','1']--> (A)
@@ -713,81 +769,6 @@ public final class Oid
 
     
     /**
-     * Compute the number of bytes necessary to store a long
-     */
-    private int getNbBytes( long value )
-    {
-        if ( value > 0x00000000FFFFFFFFL )
-        {
-            if ( value > 0x0000FFFFFFFFFFFFL )
-            {
-                if ( value > 0x00FFFFFFFFFFFFFFL )
-                {
-                    return 8;
-                }
-                else
-                {
-                    return 7;
-                }
-            }
-            else
-            {
-                if ( value > 0x000000FFFFFFFFFFL )
-                {
-                    return 6;
-                }
-                else
-                {
-                    return 5;
-                }
-            }
-                
-        }
-        else
-        {
-            if ( value > 0x00000000000000FFFFL )
-            {
-                if ( value > 0x0000000000FFFFFFL )
-                {
-                    return 4;
-                }
-                else
-                {
-                    return 3;
-                }
-            }
-            else
-            {
-                if ( value > 0x00000000000000FFL )
-                {
-                    return 2;
-                }
-                else
-                {
-                    return 1;
-                }
-                
-            }
-        }
-    }
-    
-    
-    /**
-     * Get a bte[] that will hold the 
-     * TODO getBytes.
-     *
-     * @param value
-     * @return
-     */
-    private byte[] getBytes( long value )
-    {
-        int nbBytes = getNbBytes( value );
-        
-        return new byte[nbBytes];
-
-    }
-
-    /**
      * Convert a list of digits to a list of 7 bits bytes. We must start by the end, and we don't
      * know how many bytes we will need, except when we will be done with the conversion.
      */
@@ -1099,8 +1080,6 @@ public final class Oid
         // The number of bytes in the resulting OID byte[]
         int nbBytes = 0;
         
-        boolean isJointIsoItuT = false;
-        
         for ( int i = 0; i < oidString.length(); i++ )
         {
             switch ( state )
@@ -1150,7 +1129,6 @@ public final class Oid
                     break;
                     
                 case STATE_F :
-                    isJointIsoItuT = true;
                     // (F) --['.']--> (G)
                     state = processStateF( oidString, i );
                     
@@ -1302,6 +1280,7 @@ public final class Oid
                 System.arraycopy( buffer, 0, bytes, 0, bufPos );
                 
                 return new Oid( oidString, bytes );
+                
             default :
                 // This should never happen...
                 throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, "Wrong OID" ) );
@@ -1409,61 +1388,4 @@ public final class Oid
     {
         outputStream.write( oidBytes );
     }
-
-    /**
-     * 
-     * Internal helper class for converting a long value to a properly encoded byte[]
-     */
-    private static final class ByteBuffer
-    {
-        /** The Buffer the OID will be written in */
-        private ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-
-
-        /**
-         * Writes a Long into a ByteBuffer
-         * 
-         * @param value The long value to write
-         * @return A ByteBufffer containing the converted Long
-         */
-        public ByteBuffer append( long value )
-        {
-            write( value, false );
-            
-            return this;
-        }
-
-
-        /**
-         * Write a long into the buffe, and a flag indicating that there are more 
-         * to write
-         *
-         * @param value The value to write
-         * @param hasMore The flag indicati,ng there is more to write into the buffer
-         */
-        private void write( long value, boolean hasMore )
-        {
-            long remaining = value >> 7;
-        
-            if ( remaining > 0 )
-            {
-                write( remaining, true );
-            }
-            
-            buffer.write( hasMore
-                ? ( byte ) ( ( 0x7F & value ) | 0x80 )
-                : ( byte ) ( 0x7F & value ) );
-        }
-
-
-        /**
-         * Convert the Buffer to a byte[]
-         * 
-         * @return The byte[] containing the Long
-         */
-        public byte[] toByteArray()
-        {
-            return buffer.toByteArray();
-        }
-    }
 }

Modified: directory/shared/trunk/asn1/api/src/test/java/org/apache/directory/api/asn1/util/OidTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/api/src/test/java/org/apache/directory/api/asn1/util/OidTest.java?rev=1710759&r1=1710758&r2=1710759&view=diff
==============================================================================
--- directory/shared/trunk/asn1/api/src/test/java/org/apache/directory/api/asn1/util/OidTest.java (original)
+++ directory/shared/trunk/asn1/api/src/test/java/org/apache/directory/api/asn1/util/OidTest.java Tue Oct 27 10:16:00 2015
@@ -29,38 +29,15 @@ import java.util.Arrays;
 
 import org.apache.directory.api.asn1.DecoderException;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
+/**
+ * A test class for the Oid class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
 public class OidTest
 {
-    private static final Logger LOGGER = LoggerFactory.getLogger( OidTest.class );
-
-
-    @Test
-    public void speed()
-    {
-        byte[] bytes = new byte[]
-            { 0x2A, ( byte ) 0x86, 0x48, ( byte ) 0x86, ( byte ) 0xF7, 0x12, 0x01, 0x02, 0x02 };
-        String string = new String( "1.2.840.113554.1.2.2" );
-
-        long start = System.nanoTime();
-        for ( int i = 0; i < 1000; i++ )
-        {
-            Arrays.equals( bytes, bytes );
-        }
-        LOGGER.debug( "byte[]: {}", ( System.nanoTime() - start ) );
-
-        start = System.nanoTime();
-        for ( int i = 0; i < 1000; i++ )
-        {
-            string.equals( string );
-        }
-        LOGGER.debug( "String: {}", ( System.nanoTime() - start ) );
-    }
-
-
     @Test
     public void fromBytes() throws DecoderException
     {
@@ -90,22 +67,170 @@ public class OidTest
 
 
     @Test
+    public void fromBytesLongValues() throws DecoderException
+    {
+        // 2.0 -> expected 0x02
+        assertEquals( "2.0", Oid.fromBytes( new byte[] { 0x50 } ).toString() );
+        
+        // 2.40 -> expected 0x78
+        assertEquals( "2.40", Oid.fromBytes( new byte[] { 0x78 } ).toString() );
+        
+        // 2.48 -> expected 0x81 0x00
+        assertEquals( "2.48", Oid.fromBytes( new byte[] { (byte)0x81, 0x00 } ).toString() );
+        
+        // The second arc is below and equal to 16304 : 0x4000 - 0x50
+        assertEquals( "2.16303", Oid.fromBytes( new byte[] { (byte)0xFF, 0x7F } ).toString() );
+        assertEquals( "2.16304", Oid.fromBytes( new byte[] { (byte)0x81, (byte)0x80, 0x00 } ).toString() );
+        
+        // The second arc is below and equal to 2097072 : 0x200000 - 0x50
+        assertEquals( "2.2097071", Oid.fromBytes( new byte[] { (byte)0xFF, (byte)0xFF, 0x7F } ).toString() );
+        assertEquals( "2.2097072", Oid.fromBytes( new byte[] { (byte)0x81, (byte)0x80, (byte)0x80, 0x00 } ).toString() );
+
+        // The second arc is below and equal to 268435376 : 0x10000000 - 0x50
+        assertEquals( "2.268435375", Oid.fromBytes( new byte[] { (byte)0xFF, (byte)0xFF, (byte)0xFF, 0x7F } ).toString() );
+        assertEquals( "2.268435376", 
+            Oid.fromBytes( new byte[] 
+                { 
+                    (byte)0x81, (byte)0x80, (byte)0x80, (byte)0x80, 
+                    0x00 
+                } ).toString() );
+        
+        // The second arc is below and equal to 34359738288 : 0x800000000 - 0x50
+        Oid oid = Oid.fromBytes( new byte[] 
+            { 
+                (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, 0x7F 
+            } );
+        assertEquals( "2.34359738287", oid.toString() );
+        Oid oid1 = Oid.fromString( oid.toString() );
+        assertEquals( oid, oid1 );
+        
+        oid = Oid.fromBytes( new byte[] 
+            { 
+                (byte)0x81, (byte)0x80, (byte)0x80, (byte)0x80, 
+                (byte)0x80, 0x00 
+            } );
+        assertEquals( "2.34359738288", oid.toString() );
+        oid1 = Oid.fromString( oid.toString() );
+        assertEquals( oid, oid1 );
+
+        // The second arc is below and equal to 4398046511024 : 0x40000000000 - 0x50
+        oid = Oid.fromBytes( new byte[] 
+            { 
+                (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, 
+                (byte)0xFF, 0x7F 
+            } );
+        assertEquals( "2.4398046511023", oid.toString() );
+        oid1 = Oid.fromString( oid.toString() );
+        assertEquals( oid, oid1 );
+        
+        oid = Oid.fromBytes( new byte[] 
+            { 
+                (byte)0x81, (byte)0x80, (byte)0x80, (byte)0x80, 
+                (byte)0x80, (byte)0x80, 0x00 
+            } ); 
+        assertEquals( "2.4398046511024", oid.toString() );
+        oid1 = Oid.fromString( oid.toString() );
+        assertEquals( oid, oid1 );
+
+        // The second arc is below and equal to 562949953421232 : 0x2000000000000 - 0x50
+        oid = Oid.fromBytes( new byte[] 
+            { 
+                (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, 
+                (byte)0xFF, (byte)0xFF, 0x7F 
+            } ); 
+        assertEquals( "2.562949953421231", oid.toString() );
+        oid1 = Oid.fromString( oid.toString() );
+        assertEquals( oid, oid1 );
+
+        oid = Oid.fromBytes( new byte[] 
+            { 
+                (byte)0x81, (byte)0x80, (byte)0x80, (byte)0x80, 
+                (byte)0x80, (byte)0x80, (byte)0x80, 0x00 
+            } ); 
+        assertEquals( "2.562949953421232", oid.toString() );
+        oid1 = Oid.fromString( oid.toString() );
+        assertEquals( oid, oid1 );
+
+        // The second arc is below and equal to 72057594037927856 : 0x100000000000000 - 0x50
+        oid = Oid.fromBytes( new byte[] 
+            { 
+                (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, 
+                (byte)0xFF, (byte)0xFF, (byte)0xFF, 0x7F 
+            } ); 
+        assertEquals( "2.72057594037927855", oid.toString() );
+        oid1 = Oid.fromString( oid.toString() );
+        assertEquals( oid, oid1 );
+
+        oid = Oid.fromBytes( new byte[] 
+            { 
+                (byte)0x81, (byte)0x80, (byte)0x80, (byte)0x80, 
+                (byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, 
+                0x00 
+            } ); 
+        assertEquals( "2.72057594037927856", oid.toString() );
+        oid1 = Oid.fromString( oid.toString() );
+        assertEquals( oid, oid1 );
+
+        // The second arc is below and equal to 9223372036854775728 : 0x8000000000000000 - 0x50
+        oid = Oid.fromBytes( new byte[] 
+            { 
+                (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, 
+                (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, 
+                0x7F 
+            } ); 
+        assertEquals( "2.9223372036854775727", oid.toString() );
+        oid1 = Oid.fromString( oid.toString() );
+        assertEquals( oid, oid1 );
+
+        oid = Oid.fromBytes( new byte[] 
+            { 
+                (byte)0x81, (byte)0x80, (byte)0x80, (byte)0x80, 
+                (byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, 
+                (byte)0x80, 0x00 
+            } ); 
+        assertEquals( "2.9223372036854775728", oid.toString() );
+        oid1 = Oid.fromString( oid.toString() );
+        assertEquals( oid, oid1 );
+
+        // Check for 9999999999999999999 which is higher than Long.MAX_VALUE
+        oid = Oid.fromBytes( new byte[] 
+            { 
+                (byte)0x81, (byte)0x8A, (byte)0xE3, (byte)0xC8, 
+                (byte)0xE0, (byte)0xC8, (byte)0xCF, (byte)0xA0, 
+                (byte)0x80, 0x4F 
+            } );
+        assertEquals( "2.9999999999999999999", oid.toString() ) ;
+        oid1 = Oid.fromString( oid.toString() );
+        assertEquals( oid, oid1 );
+
+        // A bigger one
+        oid = Oid.fromBytes( new byte[] 
+            { 
+                (byte)0xFA, (byte)0xBE, (byte)0xB7, (byte)0xA2, 
+                (byte)0x8E, (byte)0xF4, (byte)0xC0, (byte)0xC7, 
+                (byte)0xCB, (byte)0x9F, (byte)0xA0, (byte)0xC5, 
+                (byte)0xEA, (byte)0xDA, (byte)0x92, (byte)0x9D, 
+                (byte)0x9E, 0x0C
+            } ); 
+        assertEquals( "2.81407072025111374527560065493494091452", oid.toString() );
+        oid1 = Oid.fromString( oid.toString() );
+        assertEquals( oid, oid1 );
+    }
+
+
+    @Test
     public void test2dot123456() throws DecoderException
     {
         String expectedString = "2.123456";
         byte[] expectedBytes = new byte[]
             { ( byte ) 0x87, ( byte ) 0xC5, 0x10 };
 
-        LOGGER.debug( "b_to_b: " + Arrays.toString( Oid.fromBytes( expectedBytes ).toBytes() ) );
         assertTrue( Arrays.equals( expectedBytes, Oid.fromBytes( expectedBytes ).toBytes() ) );
 
-        LOGGER.debug( "s_to_b: " + Arrays.toString( Oid.fromString( expectedString ).toBytes() ) );
         assertTrue( Arrays.equals( expectedBytes, Oid.fromString( expectedString ).toBytes() ) );
 
-        LOGGER.debug( "b_to_s: " + Oid.fromBytes( expectedBytes ).toString() );
         assertEquals( expectedString, Oid.fromBytes( expectedBytes ).toString() );
 
-        LOGGER.debug( "s_to_s: " + Oid.fromString( expectedString ).toString() );
         assertEquals( expectedString, Oid.fromString( expectedString ).toString() );
     }
 
@@ -432,12 +557,16 @@ public class OidTest
         byte[] oidBytes = oid.toBytes();
         assertEquals( 1, oidBytes.length );
         assertEquals( 80, oidBytes[0] );
+        Oid oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
         
         // 2.40 -> expected 0x78
         oid = Oid.fromString( "2.40" );
         oidBytes = oid.toBytes();
         assertEquals( 1, oidBytes.length );
         assertEquals( 0x78, oidBytes[0] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
         
         // 2.48 -> expected 0x80
         oid = Oid.fromString( "2.48" );
@@ -445,6 +574,8 @@ public class OidTest
         assertEquals( 2, oidBytes.length );
         assertEquals( (byte)0x81, oidBytes[0] );
         assertEquals( 0x00, oidBytes[1] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
         
         // The second arc is below and equal to 16304 : 0x4000 - 0x50
         oid = Oid.fromString( "2.16303" );
@@ -452,6 +583,8 @@ public class OidTest
         assertEquals( 2, oidBytes.length );
         assertEquals( (byte)0xFF, oidBytes[0] );
         assertEquals( 0x7F, oidBytes[1] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
 
         oid = Oid.fromString( "2.16304" );
         oidBytes = oid.toBytes();
@@ -459,6 +592,8 @@ public class OidTest
         assertEquals( (byte)0x81, oidBytes[0] );
         assertEquals( (byte)0x80, oidBytes[1] );
         assertEquals( 0x00, oidBytes[2] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
         
         // The second arc is below and equal to 2097072 : 0x200000 - 0x50
         oid = Oid.fromString( "2.2097071" );
@@ -467,6 +602,8 @@ public class OidTest
         assertEquals( (byte)0xFF, oidBytes[0] );
         assertEquals( (byte)0xFF, oidBytes[1] );
         assertEquals( 0x7F, oidBytes[2] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
 
         oid = Oid.fromString( "2.2097072" );
         oidBytes = oid.toBytes();
@@ -475,7 +612,9 @@ public class OidTest
         assertEquals( (byte)0x80, oidBytes[1] );
         assertEquals( (byte)0x80, oidBytes[2] );
         assertEquals( 0x00, oidBytes[3] );
-        
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
+
         // The second arc is below and equal to 268435376 : 0x10000000 - 0x50
         oid = Oid.fromString( "2.268435375" );
         oidBytes = oid.toBytes();
@@ -484,6 +623,8 @@ public class OidTest
         assertEquals( (byte)0xFF, oidBytes[1] );
         assertEquals( (byte)0xFF, oidBytes[2] );
         assertEquals( 0x7F, oidBytes[3] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
 
         oid = Oid.fromString( "2.268435376" );
         oidBytes = oid.toBytes();
@@ -493,7 +634,9 @@ public class OidTest
         assertEquals( (byte)0x80, oidBytes[2] );
         assertEquals( (byte)0x80, oidBytes[3] );
         assertEquals( 0x00, oidBytes[4] );
-        
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
+
         // The second arc is below and equal to 34359738288 : 0x800000000 - 0x50
         oid = Oid.fromString( "2.34359738287" );
         oidBytes = oid.toBytes();
@@ -503,6 +646,8 @@ public class OidTest
         assertEquals( (byte)0xFF, oidBytes[2] );
         assertEquals( (byte)0xFF, oidBytes[3] );
         assertEquals( 0x7F, oidBytes[4] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
 
         oid = Oid.fromString( "2.34359738288" );
         oidBytes = oid.toBytes();
@@ -513,6 +658,8 @@ public class OidTest
         assertEquals( (byte)0x80, oidBytes[3] );
         assertEquals( (byte)0x80, oidBytes[4] );
         assertEquals( 0x00, oidBytes[5] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
 
         // The second arc is below and equal to 4398046511024 : 0x40000000000 - 0x50
         oid = Oid.fromString( "2.4398046511023" );
@@ -524,6 +671,8 @@ public class OidTest
         assertEquals( (byte)0xFF, oidBytes[3] );
         assertEquals( (byte)0xFF, oidBytes[4] );
         assertEquals( 0x7F, oidBytes[5] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
 
         oid = Oid.fromString( "2.4398046511024" );
         oidBytes = oid.toBytes();
@@ -535,6 +684,8 @@ public class OidTest
         assertEquals( (byte)0x80, oidBytes[4] );
         assertEquals( (byte)0x80, oidBytes[5] );
         assertEquals( 0x00, oidBytes[6] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
 
         // The second arc is below and equal to 562949953421232 : 0x2000000000000 - 0x50
         oid = Oid.fromString( "2.562949953421231" );
@@ -547,6 +698,8 @@ public class OidTest
         assertEquals( (byte)0xFF, oidBytes[4] );
         assertEquals( (byte)0xFF, oidBytes[5] );
         assertEquals( 0x7F, oidBytes[6] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
 
         oid = Oid.fromString( "2.562949953421232" );
         oidBytes = oid.toBytes();
@@ -559,6 +712,8 @@ public class OidTest
         assertEquals( (byte)0x80, oidBytes[5] );
         assertEquals( (byte)0x80, oidBytes[6] );
         assertEquals( 0x00, oidBytes[7] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
 
         // The second arc is below and equal to 72057594037927856 : 0x100000000000000 - 0x50
         oid = Oid.fromString( "2.72057594037927855" );
@@ -572,6 +727,8 @@ public class OidTest
         assertEquals( (byte)0xFF, oidBytes[5] );
         assertEquals( (byte)0xFF, oidBytes[6] );
         assertEquals( 0x7F, oidBytes[7] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
 
         oid = Oid.fromString( "2.72057594037927856" );
         oidBytes = oid.toBytes();
@@ -585,6 +742,8 @@ public class OidTest
         assertEquals( (byte)0x80, oidBytes[6] );
         assertEquals( (byte)0x80, oidBytes[7] );
         assertEquals( 0x00, oidBytes[8] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
 
         // The second arc is below and equal to 9223372036854775728 : 0x8000000000000000 - 0x50
         oid = Oid.fromString( "2.9223372036854775727" );
@@ -600,6 +759,8 @@ public class OidTest
         assertEquals( (byte)0xFF, oidBytes[6] );
         assertEquals( (byte)0xFF, oidBytes[7] );
         assertEquals( 0x7F, oidBytes[8] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
 
         oid = Oid.fromString( "2.9223372036854775728" );
         oidBytes = oid.toBytes();
@@ -614,6 +775,8 @@ public class OidTest
         assertEquals( (byte)0x80, oidBytes[7] );
         assertEquals( (byte)0x80, oidBytes[8] );
         assertEquals( 0x00, oidBytes[9] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
 
         // Check for 9999999999999999999 which is higher than Long.MAX_VALUE
         oid = Oid.fromString( "2.9999999999999999999" );
@@ -629,6 +792,8 @@ public class OidTest
         assertEquals( (byte)0xA0, oidBytes[7] );
         assertEquals( (byte)0x80, oidBytes[8] );
         assertEquals( (byte)0x4F, oidBytes[9] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
 
         // A bigger one
         oid = Oid.fromString( "2.81407072025111374527560065493494091452" );
@@ -652,6 +817,8 @@ public class OidTest
         assertEquals( (byte)0x9D, oidBytes[15] );
         assertEquals( (byte)0x9E, oidBytes[16] );
         assertEquals( (byte)0x0C, oidBytes[17] );
+        oid1 = Oid.fromBytes( oidBytes );
+        assertEquals( oid, oid1 );
     }
 
 
@@ -663,6 +830,8 @@ public class OidTest
     public void testOidNode2() throws DecoderException
     {
         Oid oid = Oid.fromString( "2.12345" );
+        Oid oid2 = Oid.fromBytes( oid.toBytes() );
+        assertEquals( oid, oid2 );
     }