From 7bdcb41c0f62967ec42d552f6002577dfb7019ca Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Tue, 02 Nov 2010 15:45:49 +0000
Subject: [PATCH] Sync from OpenDS (matthew_swift) Remove Platform class as it is no longer needed. Remove all getter methods which return passwords as Strings. Replace all setter methods which accept passwords as Strings with methods which accept passwords as char arrays, as per Java API security recommendations.
---
sdk/src/org/opends/sdk/ByteString.java | 42 +++++++++++++++++++++++++++++++++++++++++-
1 files changed, 41 insertions(+), 1 deletions(-)
diff --git a/sdk/src/org/opends/sdk/ByteString.java b/sdk/src/org/opends/sdk/ByteString.java
index f3f2432..31e50ed 100755
--- a/sdk/src/org/opends/sdk/ByteString.java
+++ b/sdk/src/org/opends/sdk/ByteString.java
@@ -22,7 +22,7 @@
* CDDL HEADER END
*
*
- * Copyright 2009 Sun Microsystems, Inc.
+ * Copyright 2009-2010 Sun Microsystems, Inc.
*/
package org.opends.sdk;
@@ -30,6 +30,9 @@
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
import java.util.logging.Level;
import com.sun.opends.sdk.util.StaticUtils;
@@ -144,6 +147,26 @@
/**
+ * Returns a byte string containing the UTF-8 encoded bytes of the provided
+ * char array.
+ *
+ * @param chars
+ * The char array to use.
+ * @return A byte string containing the UTF-8 encoded bytes of the provided
+ * char array.
+ */
+ public static ByteString valueOf(final char[] chars)
+ {
+ Charset utf8 = Charset.forName("UTF-8");
+ ByteBuffer buffer = utf8.encode(CharBuffer.wrap(chars));
+ byte[] bytes = new byte[buffer.remaining()];
+ buffer.get(bytes);
+ return wrap(bytes);
+ }
+
+
+
+ /**
* Returns a byte string that wraps the provided byte array.
* <p>
* <b>NOTE:</b> this method takes ownership of the provided byte array and,
@@ -613,6 +636,23 @@
/**
+ * Returns the UTF-8 decoded char array representation of this byte sequence.
+ *
+ * @return The UTF-8 decoded char array representation of this byte sequence.
+ */
+ public char[] toCharArray()
+ {
+ Charset utf8 = Charset.forName("UTF-8");
+ CharBuffer charBuffer = utf8
+ .decode(ByteBuffer.wrap(buffer, offset, length));
+ char[] chars = new char[charBuffer.remaining()];
+ charBuffer.get(chars);
+ return chars;
+ }
+
+
+
+ /**
* Returns the integer value represented by the first four bytes of this byte
* string in big-endian order.
*
--
Gitblit v1.10.0