From 61be60eef8694b2c28386faf6dd2d7c4e842addd Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Thu, 16 Jun 2011 18:00:52 +0000
Subject: [PATCH] Fix OPENDJ-198: RFC 4512 compliance for ldap-toolkit

---
 opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/ASCIICharProp.java |   31 ++++++++++++++++++++++++-------
 1 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/ASCIICharProp.java b/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/ASCIICharProp.java
index 8eb5039..30b471d 100644
--- a/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/ASCIICharProp.java
+++ b/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/ASCIICharProp.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2009 Sun Microsystems, Inc.
+ *      Portions copyright 2011 ForgeRock AS
  */
 
 package com.forgerock.opendj.util;
@@ -56,6 +57,8 @@
 
   private final boolean isKeyChar;
 
+  private final boolean isCompatKeyChar;
+
   private final boolean isHexChar;
 
   private final int hexValue;
@@ -137,6 +140,7 @@
       this.isDigit = false;
       this.isLetter = true;
       this.isKeyChar = true;
+      this.isCompatKeyChar = true;
       this.decimalValue = -1;
       if (c >= 'a' && c <= 'f')
       {
@@ -158,6 +162,7 @@
       this.isDigit = false;
       this.isLetter = true;
       this.isKeyChar = true;
+      this.isCompatKeyChar = true;
       this.decimalValue = -1;
       if (c >= 'A' && c <= 'F')
       {
@@ -179,6 +184,7 @@
       this.isDigit = true;
       this.isLetter = false;
       this.isKeyChar = true;
+      this.isCompatKeyChar = true;
       this.isHexChar = true;
       this.hexValue = c - 48;
       this.decimalValue = c - 48;
@@ -192,6 +198,7 @@
       this.isDigit = false;
       this.isLetter = false;
       this.isKeyChar = c == '-';
+      this.isCompatKeyChar = (c == '-') || (c == '.') || (c == '_');
       this.isHexChar = false;
       this.hexValue = -1;
       this.decimalValue = -1;
@@ -301,16 +308,26 @@
 
 
   /**
-   * Indicates whether or not the char value associated with this {@code
-   * ASCIICharProp} is a {@code keychar} as defined in RFC 4512. A {@code
-   * keychar} is a letter, a digit, or a hyphen.
+   * Indicates whether or not the char value associated with this
+   * {@code ASCIICharProp} is a {@code keychar} as defined in RFC 4512. A
+   * {@code keychar} is a letter, a digit, or a hyphen. When
+   * {@code allowCompatChars} is {@code true} the following illegal characters
+   * will be permitted:
    *
-   * @return {@code true} if the char value associated with this {@code
-   *         ASCIICharProp} is a {@code keychar}.
+   * <pre>
+   * USCORE  = %x5F ; underscore ("_")
+   * DOT     = %x2E ; period (".")
+   * </pre>
+   *
+   * @param allowCompatChars
+   *          {@code true} if certain illegal characters should be allowed for
+   *          compatibility reasons.
+   * @return {@code true} if the char value associated with this
+   *         {@code ASCIICharProp} is a {@code keychar}.
    */
-  public boolean isKeyChar()
+  public boolean isKeyChar(final boolean allowCompatChars)
   {
-    return isKeyChar;
+    return allowCompatChars ? isCompatKeyChar : isKeyChar;
   }
 
 

--
Gitblit v1.10.0