Home | History | Annotate | Download | only in x509
      1 package org.bouncycastle.asn1.x509;
      2 
      3 /**
      4  * class for breaking up an X500 Name into it's component tokens, ala
      5  * java.util.StringTokenizer. We need this class as some of the
      6  * lightweight Java environment don't support classes like
      7  * StringTokenizer.
      8  * @deprecated use X500NameTokenizer
      9  */
     10 public class X509NameTokenizer
     11 {
     12     private String          value;
     13     private int             index;
     14     private char separator;
     15     private StringBuffer    buf = new StringBuffer();
     16 
     17     public X509NameTokenizer(
     18         String  oid)
     19     {
     20         this(oid, ',');
     21     }
     22 
     23     public X509NameTokenizer(
     24         String  oid,
     25         char separator)
     26     {
     27         this.value = oid;
     28         this.index = -1;
     29         this.separator = separator;
     30     }
     31 
     32     public boolean hasMoreTokens()
     33     {
     34         return (index != value.length());
     35     }
     36 
     37     public String nextToken()
     38     {
     39         if (index == value.length())
     40         {
     41             return null;
     42         }
     43 
     44         int     end = index + 1;
     45         boolean quoted = false;
     46         boolean escaped = false;
     47 
     48         buf.setLength(0);
     49 
     50         while (end != value.length())
     51         {
     52             char    c = value.charAt(end);
     53 
     54             if (c == '"')
     55             {
     56                 if (!escaped)
     57                 {
     58                     quoted = !quoted;
     59                 }
     60                 buf.append(c);
     61                 escaped = false;
     62             }
     63             else
     64             {
     65                 if (escaped || quoted)
     66                 {
     67                     buf.append(c);
     68                     escaped = false;
     69                 }
     70                 else if (c == '\\')
     71                 {
     72                     buf.append(c);
     73                     escaped = true;
     74                 }
     75                 else if (c == separator)
     76                 {
     77                     break;
     78                 }
     79                 else
     80                 {
     81                     // BEGIN Android-added: Unknown reason
     82                     // This was previously marked with the comment "copied from a newer version
     83                     // of BouncyCastle", but I couldn't find any evidence that it ever was included
     84                     // in any version of BC
     85                     if (c == '#' && buf.charAt(buf.length() - 1) == '=')
     86                     {
     87                         buf.append('\\');
     88                     }
     89                     else if (c == '+' && separator != '+')
     90                     {
     91                         buf.append('\\');
     92                     }
     93                     // END Android-added: Unknown reason
     94                     buf.append(c);
     95                 }
     96             }
     97             end++;
     98         }
     99 
    100         index = end;
    101 
    102         return buf.toString();
    103     }
    104 }
    105