< prev index next >

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

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


 848      */
 849     public byte[] getEncoded() throws IOException {
 850         return getEncodedInternal().clone();
 851     }
 852 
 853     /*
 854      * Parses a Distinguished Name (DN) in printable representation.
 855      *
 856      * According to RFC 1779, RDNs in a DN are separated by comma.
 857      * The following examples show both methods of quoting a comma, so that it
 858      * is not considered a separator:
 859      *
 860      *     O="Sue, Grabbit and Runn" or
 861      *     O=Sue\, Grabbit and Runn
 862      *
 863      * This method can parse RFC 1779, 2253 or 4514 DNs and non-standard 5280
 864      * keywords. Additional keywords can be specified in the keyword/OID map.
 865      */
 866     private void parseDN(String input, Map<String, String> keywordMap)
 867         throws IOException {
 868         if (input == null || input.length() == 0) {
 869             names = new RDN[0];
 870             return;
 871         }
 872 
 873         List<RDN> dnVector = new ArrayList<>();
 874         int dnOffset = 0;
 875         int rdnEnd;
 876         String rdnString;
 877         int quoteCount = 0;
 878 
 879         String dnString = input;
 880 
 881         int searchOffset = 0;
 882         int nextComma = dnString.indexOf(',');
 883         int nextSemiColon = dnString.indexOf(';');
 884         while (nextComma >=0 || nextSemiColon >=0) {
 885 
 886             if (nextSemiColon < 0) {
 887                 rdnEnd = nextComma;
 888             } else if (nextComma < 0) {


 920 
 921             searchOffset = rdnEnd + 1;
 922             nextComma = dnString.indexOf(',', searchOffset);
 923             nextSemiColon = dnString.indexOf(';', searchOffset);
 924         }
 925 
 926         // Parse last or only RDN, and store it in vector
 927         rdnString = dnString.substring(dnOffset);
 928         RDN rdn = new RDN(rdnString, keywordMap);
 929         dnVector.add(rdn);
 930 
 931         /*
 932          * Store the vector elements as an array of RDNs
 933          * NOTE: It's only on output that little-endian ordering is used.
 934          */
 935         Collections.reverse(dnVector);
 936         names = dnVector.toArray(new RDN[dnVector.size()]);
 937     }
 938 
 939     private void parseRFC2253DN(String dnString) throws IOException {
 940         if (dnString.length() == 0) {
 941             names = new RDN[0];
 942             return;
 943          }
 944 
 945          List<RDN> dnVector = new ArrayList<>();
 946          int dnOffset = 0;
 947          String rdnString;
 948          int searchOffset = 0;
 949          int rdnEnd = dnString.indexOf(',');
 950          while (rdnEnd >=0) {
 951              /*
 952               * We have encountered an RDN delimiter (comma).
 953               * If the comma in the RDN under consideration is
 954               * preceded by a backslash (escape), it
 955               * is part of the RDN. Otherwise, it is used as a separator, to
 956               * delimit the RDN under consideration from any subsequent RDNs.
 957               */
 958              if (rdnEnd > 0 && !escaped(rdnEnd, searchOffset, dnString)) {
 959 
 960                  /*




 848      */
 849     public byte[] getEncoded() throws IOException {
 850         return getEncodedInternal().clone();
 851     }
 852 
 853     /*
 854      * Parses a Distinguished Name (DN) in printable representation.
 855      *
 856      * According to RFC 1779, RDNs in a DN are separated by comma.
 857      * The following examples show both methods of quoting a comma, so that it
 858      * is not considered a separator:
 859      *
 860      *     O="Sue, Grabbit and Runn" or
 861      *     O=Sue\, Grabbit and Runn
 862      *
 863      * This method can parse RFC 1779, 2253 or 4514 DNs and non-standard 5280
 864      * keywords. Additional keywords can be specified in the keyword/OID map.
 865      */
 866     private void parseDN(String input, Map<String, String> keywordMap)
 867         throws IOException {
 868         if (input == null || input.isEmpty()) {
 869             names = new RDN[0];
 870             return;
 871         }
 872 
 873         List<RDN> dnVector = new ArrayList<>();
 874         int dnOffset = 0;
 875         int rdnEnd;
 876         String rdnString;
 877         int quoteCount = 0;
 878 
 879         String dnString = input;
 880 
 881         int searchOffset = 0;
 882         int nextComma = dnString.indexOf(',');
 883         int nextSemiColon = dnString.indexOf(';');
 884         while (nextComma >=0 || nextSemiColon >=0) {
 885 
 886             if (nextSemiColon < 0) {
 887                 rdnEnd = nextComma;
 888             } else if (nextComma < 0) {


 920 
 921             searchOffset = rdnEnd + 1;
 922             nextComma = dnString.indexOf(',', searchOffset);
 923             nextSemiColon = dnString.indexOf(';', searchOffset);
 924         }
 925 
 926         // Parse last or only RDN, and store it in vector
 927         rdnString = dnString.substring(dnOffset);
 928         RDN rdn = new RDN(rdnString, keywordMap);
 929         dnVector.add(rdn);
 930 
 931         /*
 932          * Store the vector elements as an array of RDNs
 933          * NOTE: It's only on output that little-endian ordering is used.
 934          */
 935         Collections.reverse(dnVector);
 936         names = dnVector.toArray(new RDN[dnVector.size()]);
 937     }
 938 
 939     private void parseRFC2253DN(String dnString) throws IOException {
 940         if (dnString.isEmpty()) {
 941             names = new RDN[0];
 942             return;
 943          }
 944 
 945          List<RDN> dnVector = new ArrayList<>();
 946          int dnOffset = 0;
 947          String rdnString;
 948          int searchOffset = 0;
 949          int rdnEnd = dnString.indexOf(',');
 950          while (rdnEnd >=0) {
 951              /*
 952               * We have encountered an RDN delimiter (comma).
 953               * If the comma in the RDN under consideration is
 954               * preceded by a backslash (escape), it
 955               * is part of the RDN. Otherwise, it is used as a separator, to
 956               * delimit the RDN under consideration from any subsequent RDNs.
 957               */
 958              if (rdnEnd > 0 && !escaped(rdnEnd, searchOffset, dnString)) {
 959 
 960                  /*


< prev index next >