Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 88481 invoked from network); 9 May 2005 21:20:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 May 2005 21:20:49 -0000 Received: (qmail 42478 invoked by uid 500); 9 May 2005 21:24:02 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 42082 invoked by uid 500); 9 May 2005 21:23:56 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 41960 invoked by uid 99); 9 May 2005 21:23:54 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 09 May 2005 14:23:50 -0700 Received: (qmail 88302 invoked by uid 65534); 9 May 2005 21:20:28 -0000 Message-ID: <20050509212028.88301.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r169360 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/primitives/OID.java Date: Mon, 09 May 2005 21:20:27 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: elecharny Date: Mon May 9 14:20:26 2005 New Revision: 169360 URL: http://svn.apache.org/viewcvs?rev=3D169360&view=3Drev Log: - Added a getOIDLength() method - implemented the getOID() method that send back a bytes[] representing the= OID Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/primiti= ves/OID.java Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/p= rimitives/OID.java URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/s= rc/java/org/apache/asn1/primitives/OID.java?rev=3D169360&r1=3D169359&r2=3D1= 69360&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/primiti= ves/OID.java (original) +++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/primiti= ves/OID.java Mon May 9 14:20:26 2005 @@ -231,6 +231,10 @@ =20 int pos =3D 0; int intPos =3D 0; + =20 + // This flag is used to forbid a second value above 39 if the=20 + // first value is 0 or 1 (itu_t or iso arcs) + boolean ituOrIso =3D false; =20 // The first value switch ( bytes[pos] ) @@ -238,6 +242,9 @@ =20 case '0' : // itu-t case '1' : // iso + ituOrIso =3D true; + // fallthrough + =20 case '2' : // joint-iso-itu-t oidValues[intPos++] =3D bytes[pos++] - '0'; break; @@ -269,6 +276,15 @@ throw new DecoderException( "Invalid OID : " + oid ); } =20 + if (ituOrIso && value > 39) + { + throw new DecoderException( "Invalid OID : " + oid ); + } + else + { + ituOrIso =3D false; + } + =20 nbInts++; dotSeen =3D true; oidValues[intPos++] =3D value; @@ -278,6 +294,7 @@ { dotSeen =3D false; value =3D ( ( value * 10 ) + bytes[i] ) - '0'; + =20 } else { @@ -303,11 +320,150 @@ * Get an array of bytes from the OID * @return An array of int representing the OID */ - public byte[] getOID() + public int getOIDLength() { + int value =3D oidValues[0] * 40 + oidValues[1]; + int firstValues =3D value; + int nbBytes =3D 0; + + if (value < 128) + { + nbBytes +=3D 1; + }=20 + else if (value < 16384) + { + nbBytes +=3D 2; + } + else if (value < 2097152) + { + nbBytes +=3D 3; + } + else if (value < 268435456) + { + nbBytes +=3D 4; + } + else=20 + { + nbBytes +=3D 5; + } + + for (int i =3D 2; i < oidValues.length; i++ ) + { + value =3D oidValues[i]; + =20 + if (value < 128) + { + nbBytes +=3D 1; + }=20 + else if (value < 16384) + { + nbBytes +=3D 2; + } + else if (value < 2097152) + { + nbBytes +=3D 3; + } + else if (value < 268435456) + { + nbBytes +=3D 4; + } + else=20 + { + nbBytes +=3D 5; + } + } + =20 + return nbBytes; + } =20 - //byte[] bytes =3D new byte[oidValues] - return null; + /** + * Get an array of bytes from the OID + * @return An array of int representing the OID + */ + public byte[] getOID() + { + int value =3D oidValues[0] * 40 + oidValues[1]; + int firstValues =3D value; + =20 + byte[] bytes =3D new byte[getOIDLength()]; + int pos =3D 0; + int posInt =3D 0; + =20 + if (oidValues[0] < 2) + { + bytes[pos++] =3D (byte)(oidValues[0] * 40 + oidValues[1]); + }=20 + else + { + if (firstValues < 128) + { + bytes[pos++] =3D (byte)(firstValues); + }=20 + else if (firstValues < 16384) + { + bytes[pos++] =3D (byte)( ( firstValues >> 7 ) | 0x0080 ); + bytes[pos++] =3D (byte)( firstValues & 0x007F); + } + else if (value < 2097152) + { + bytes[pos++] =3D (byte)( ( firstValues >> 14 ) | 0x0080); + bytes[pos++] =3D (byte)( ( ( firstValues >> 7 ) & 0x007F) = | 0x0080); + bytes[pos++] =3D (byte)( firstValues & 0x007F); + } + else if (value < 268435456) + { + bytes[pos++] =3D (byte)( ( firstValues >> 21 ) | 0x0080); + bytes[pos++] =3D (byte)( ( ( firstValues >> 14 ) & 0x007F)= | 0x0080); + bytes[pos++] =3D (byte)( ( ( firstValues >> 7 ) & 0x007F) = | 0x0080); + bytes[pos++] =3D (byte)( firstValues & 0x007F); + } + else=20 + { + bytes[pos++] =3D (byte)( ( firstValues >> 28 ) | 0x0080); + bytes[pos++] =3D (byte)( ( ( firstValues >> 21 ) & 0x007F)= | 0x0080); + bytes[pos++] =3D (byte)( ( ( firstValues >> 14 ) & 0x007F)= | 0x0080); + bytes[pos++] =3D (byte)( ( ( firstValues >> 7 ) & 0x007F) = | 0x0080); + bytes[pos++] =3D (byte)( firstValues & 0x007F); + } + } + =20 + for (int i =3D 2; i < oidValues.length; i++ ) + { + value =3D oidValues[i]; + =20 + if (value < 128) + { + bytes[pos++] =3D (byte)(value); + }=20 + else if (value < 16384) + { + bytes[pos++] =3D (byte)( ( value >> 7 ) | 0x0080 ); + bytes[pos++] =3D (byte)( value & 0x007F); + } + else if (value < 2097152) + { + bytes[pos++] =3D (byte)( ( value >> 14 ) | 0x0080); + bytes[pos++] =3D (byte)( ( ( value >> 7 ) & 0x007F) | 0x00= 80); + bytes[pos++] =3D (byte)( value & 0x007F); + } + else if (value < 268435456) + { + bytes[pos++] =3D (byte)( ( value >> 21 ) | 0x0080); + bytes[pos++] =3D (byte)( ( ( value >> 14 ) & 0x007F) | 0x0= 080); + bytes[pos++] =3D (byte)( ( ( value >> 7 ) & 0x007F) | 0x00= 80); + bytes[pos++] =3D (byte)( value & 0x007F); + } + else=20 + { + bytes[pos++] =3D (byte)( ( value >> 28 ) | 0x0080); + bytes[pos++] =3D (byte)( ( ( value >> 21 ) & 0x007F) | 0x0= 080); + bytes[pos++] =3D (byte)( ( ( value >> 14 ) & 0x007F) | 0x0= 080); + bytes[pos++] =3D (byte)( ( ( value >> 7 ) & 0x007F) | 0x00= 80); + bytes[pos++] =3D (byte)( value & 0x007F); + } + } + =20 + return bytes; } =20 /**