Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 46449 invoked from network); 18 Aug 2006 06:47:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 18 Aug 2006 06:47:04 -0000 Received: (qmail 94917 invoked by uid 500); 18 Aug 2006 06:47:04 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 94883 invoked by uid 500); 18 Aug 2006 06:47:04 -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 94872 invoked by uid 99); 18 Aug 2006 06:47:04 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Aug 2006 23:47:04 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Aug 2006 23:47:03 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id AA4BE1A981A; Thu, 17 Aug 2006 23:46:43 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r432500 - /directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java Date: Fri, 18 Aug 2006 06:46:43 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060818064643.AA4BE1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: elecharny Date: Thu Aug 17 23:46:42 2006 New Revision: 432500 URL: http://svn.apache.org/viewvc?rev=432500&view=rev Log: Added two utility methods to parse #xyxyxy values in a DN Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java?rev=432500&r1=432499&r2=432500&view=diff ============================================================================== --- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java (original) +++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java Thu Aug 17 23:46:42 2006 @@ -703,6 +703,22 @@ } /** + * Parse an hex pair ::= + * + * @param string + * The string which contains the data + * @param index + * Current position in the string + * @return The new position, -1 if the string does not contain an HexPair, + * -2 if the string contains an hex byte but not two. + */ + private static byte getHexPair( String string, int index ) + { + return (byte)((StringTools.HEX_VALUE[string.charAt( index )] << 4) | + (StringTools.HEX_VALUE[string.charAt( index + 1 )]) ); + } + + /** * Parse an hex string, which is a list of hex pairs ::= * ::= | e * @@ -797,6 +813,42 @@ while ( ( result = parseHexPair( string, pos.end ) ) >= 0 ) { + pos.end += TWO_CHARS; + } + + return ( ( result == BAD_HEX_PAIR ) ? PARSING_ERROR : PARSING_OK ); + } + + /** + * Parse an hex string, which is a list of hex pairs ::= + * ::= | e + * + * @param string The string which contains the data + * @param hex The result as a byte array + * @param Position Current position in the string + * @return Return the first position which is not an hex pair, or -1 if + * there is no hexpair at the beginning or if an hexpair is invalid + * (if we have only one hex instead of 2) + */ + public static int parseHexString( String string, byte[] hex, Position pos ) + { + int i = 0; + pos.end = pos.start; + int result = parseHexPair( string, pos.start ); + + if ( result < 0 ) + { + return PARSING_ERROR; + } + else + { + hex[i++] = getHexPair( string, pos.end ); + pos.end += TWO_CHARS; + } + + while ( ( result = parseHexPair( string, pos.end ) ) >= 0 ) + { + hex[i++] = getHexPair( string, pos.end ); pos.end += TWO_CHARS; }