< prev index next >

src/share/classes/sun/security/x509/DNSName.java

Print this page
rev 1267 : 6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
Reviewed-by: mullan, weijun
rev 1268 : 8074068: Cleanup in src/share/classes/sun/security/x509/
Reviewed-by: mullan, ahgross, coffeys

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -24,10 +24,11 @@
  */
 
 package sun.security.x509;
 
 import java.io.IOException;
+import java.util.Locale;
 
 import sun.security.util.*;
 
 /**
  * This class implements the DNSName as required by the GeneralNames

@@ -196,12 +197,13 @@
         if (inputName == null)
             constraintType = NAME_DIFF_TYPE;
         else if (inputName.getType() != NAME_DNS)
             constraintType = NAME_DIFF_TYPE;
         else {
-            String inName = (((DNSName)inputName).getName()).toLowerCase();
-            String thisName = name.toLowerCase();
+            String inName =
+                (((DNSName)inputName).getName()).toLowerCase(Locale.ENGLISH);
+            String thisName = name.toLowerCase(Locale.ENGLISH);
             if (inName.equals(thisName))
                 constraintType = NAME_MATCH;
             else if (thisName.endsWith(inName)) {
                 int inNdx = thisName.lastIndexOf(inName);
                 if (thisName.charAt(inNdx-1) == '.' )

@@ -228,17 +230,17 @@
      *
      * @returns distance of name from root
      * @throws UnsupportedOperationException if not supported for this name type
      */
     public int subtreeDepth() throws UnsupportedOperationException {
-        String subtree=name;
-        int i=1;
+        // subtree depth is always at least 1
+        int sum = 1;
 
-        /* count dots */
-        for (; subtree.lastIndexOf('.') >= 0; i++) {
-            subtree=subtree.substring(0,subtree.lastIndexOf('.'));
+        // count dots
+        for (int i = name.indexOf('.'); i >= 0; i = name.indexOf('.', i + 1)) {
+            ++sum;
         }
 
-        return i;
+        return sum;
     }
 
 }
< prev index next >