You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2006/08/21 01:01:51 UTC
svn commit: r433076 -
/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
Author: akarasulu
Date: Sun Aug 20 16:01:50 2006
New Revision: 433076
URL: http://svn.apache.org/viewvc?rev=433076&view=rev
Log:
applying patches for DIRSERVER-631
Modified:
directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java?rev=433076&r1=433075&r2=433076&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java Sun Aug 20 16:01:50 2006
@@ -703,6 +703,22 @@
}
/**
+ * Parse an hex pair <hexpair> ::= <hex> <hex>
+ *
+ * @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 <hexstring> ::=
* <hexpair> <hexpairs> <hexpairs> ::= <hexpair> <hexpairs> | 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 <hexstring> ::=
+ * <hexpair> <hexpairs> <hexpairs> ::= <hexpair> <hexpairs> | 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;
}