< prev index next >

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

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


  55     private static final String alphaDigits =
  56         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  57 
  58     /**
  59      * Create the DNSName object from the passed encoded Der value.
  60      *
  61      * @param derValue the encoded DER DNSName.
  62      * @exception IOException on error.
  63      */
  64     public DNSName(DerValue derValue) throws IOException {
  65         name = derValue.getIA5String();
  66     }
  67 
  68     /**
  69      * Create the DNSName object with the specified name.
  70      *
  71      * @param name the DNSName.
  72      * @throws IOException if the name is not a valid DNSName subjectAltName
  73      */
  74     public DNSName(String name) throws IOException {
  75         if (name == null || name.length() == 0)
  76             throw new IOException("DNSName must not be null or empty");
  77         if (name.contains(" "))
  78             throw new IOException("DNSName with blank components is not permitted");
  79         if (name.startsWith(".") || name.endsWith("."))
  80             throw new IOException("DNSName may not begin or end with a .");
  81         /*
  82          * Name will consist of label components separated by "."
  83          * startIndex is the index of the first character of a component
  84          * endIndex is the index of the last character of a component plus 1
  85         */
  86         for (int endIndex,startIndex = 0; startIndex < name.length(); startIndex = endIndex+1) {
  87             endIndex = name.indexOf('.', startIndex);
  88             if (endIndex < 0) {
  89                 endIndex = name.length();
  90             }
  91             if (endIndex - startIndex < 1)
  92                 throw new IOException("DNSName with empty components are not permitted");
  93 
  94             // RFC 1123: DNSName components must begin with a letter or digit
  95             if (alphaDigits.indexOf(name.charAt(startIndex)) < 0)




  55     private static final String alphaDigits =
  56         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  57 
  58     /**
  59      * Create the DNSName object from the passed encoded Der value.
  60      *
  61      * @param derValue the encoded DER DNSName.
  62      * @exception IOException on error.
  63      */
  64     public DNSName(DerValue derValue) throws IOException {
  65         name = derValue.getIA5String();
  66     }
  67 
  68     /**
  69      * Create the DNSName object with the specified name.
  70      *
  71      * @param name the DNSName.
  72      * @throws IOException if the name is not a valid DNSName subjectAltName
  73      */
  74     public DNSName(String name) throws IOException {
  75         if (name == null || name.isEmpty())
  76             throw new IOException("DNSName must not be null or empty");
  77         if (name.contains(" "))
  78             throw new IOException("DNSName with blank components is not permitted");
  79         if (name.startsWith(".") || name.endsWith("."))
  80             throw new IOException("DNSName may not begin or end with a .");
  81         /*
  82          * Name will consist of label components separated by "."
  83          * startIndex is the index of the first character of a component
  84          * endIndex is the index of the last character of a component plus 1
  85         */
  86         for (int endIndex,startIndex = 0; startIndex < name.length(); startIndex = endIndex+1) {
  87             endIndex = name.indexOf('.', startIndex);
  88             if (endIndex < 0) {
  89                 endIndex = name.length();
  90             }
  91             if (endIndex - startIndex < 1)
  92                 throw new IOException("DNSName with empty components are not permitted");
  93 
  94             // RFC 1123: DNSName components must begin with a letter or digit
  95             if (alphaDigits.indexOf(name.charAt(startIndex)) < 0)


< prev index next >