From 3bd757820d295d1bf98c2dccbae18421f8b47a0b Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 15 Jun 2011 21:54:27 +0000
Subject: [PATCH] Fix OPENDJ-202: All bind request APIs should take byte or char arrays for passwords

---
 opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/StaticUtils.java |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/StaticUtils.java b/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/StaticUtils.java
index e993cbf..734c62e 100644
--- a/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/StaticUtils.java
+++ b/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/StaticUtils.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2009-2010 Sun Microsystems, Inc.
+ *      Portions copyright 2011 ForgeRock AS
  */
 
 package com.forgerock.opendj.util;
@@ -33,6 +34,9 @@
 import static org.forgerock.opendj.ldap.CoreMessages.ERR_HEX_DECODE_INVALID_LENGTH;
 
 import java.lang.reflect.InvocationTargetException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
 import java.text.ParseException;
 import java.util.*;
 import java.util.concurrent.Executors;
@@ -68,6 +72,11 @@
    */
   public static final String EOL = System.getProperty("line.separator");
 
+  /**
+   * A zero-length byte array.
+   */
+  public static final byte[] EMPTY_BYTES = new byte[0];
+
   // The name of the time zone for universal coordinated time (UTC).
   private static final String TIME_ZONE_UTC = "UTC";
 
@@ -1363,6 +1372,26 @@
 
   /**
    * Construct a byte array containing the UTF-8 encoding of the provided
+   * character array.
+   *
+   * @param chars
+   *          The character array to convert to a UTF-8 byte array.
+   * @return A byte array containing the UTF-8 encoding of the provided
+   *         character array.
+   */
+  public static byte[] getBytes(final char[] chars)
+  {
+    final Charset utf8 = Charset.forName("UTF-8");
+    final ByteBuffer buffer = utf8.encode(CharBuffer.wrap(chars));
+    final byte[] bytes = new byte[buffer.remaining()];
+    buffer.get(bytes);
+    return bytes;
+  }
+
+
+
+  /**
+   * Construct a byte array containing the UTF-8 encoding of the provided
    * string. This is significantly faster than calling
    * {@link String#getBytes(String)} for ASCII strings.
    *
@@ -2247,6 +2276,20 @@
 
 
   /**
+   * Returns a copy of the provided byte array.
+   *
+   * @param bytes
+   *          The byte array to be copied.
+   * @return A copy of the provided byte array.
+   */
+  public static byte[] copyOfBytes(final byte[] bytes)
+  {
+    return Arrays.copyOf(bytes, bytes.length);
+  }
+
+
+
+  /**
    * Retrieves the printable ASCII representation of the provided byte.
    *
    * @param b

--
Gitblit v1.10.0