X509NameTokenizer.java
上传用户:lior1029
上传日期:2013-05-07
资源大小:209k
文件大小:2k
源码类别:

CA认证

开发平台:

Java

  1. package org.bouncycastle.asn1.x509;
  2. /**
  3.  * class for breaking up an X500 Name into it's component tokens, ala
  4.  * java.util.StringTokenizer. We need this class as some of the
  5.  * lightweight Java environment don't support classes like
  6.  * StringTokenizer.
  7.  */
  8. public class X509NameTokenizer
  9. {
  10.     private String          oid;
  11.     private int             index;
  12.     private StringBuffer    buf = new StringBuffer();
  13.     public X509NameTokenizer(
  14.         String oid)
  15.     {
  16.         this.oid = oid;
  17.         this.index = -1;
  18.     }
  19.     public boolean hasMoreTokens()
  20.     {
  21.         return (index != oid.length());
  22.     }
  23.     public String nextToken()
  24.     {
  25.         if (index == oid.length())
  26.         {
  27.             return null;
  28.         }
  29.         int     end = index + 1;
  30.         boolean quoted = false;
  31.         boolean escaped = false;
  32.         buf.setLength(0);
  33.         while (end != oid.length())
  34.         {
  35.             char    c = oid.charAt(end);
  36.             if (c == '"')
  37.             {
  38.                 if (!escaped)
  39.                 {
  40.                     quoted = !quoted;
  41.                 }
  42.                 else
  43.                 {
  44.                     buf.append(c);
  45.                 }
  46.                 escaped = false;
  47.             }
  48.             else
  49.             {
  50.                 if (escaped || quoted)
  51.                 {
  52.                     buf.append(c);
  53.                     escaped = false;
  54.                 }
  55.                 else if (c == '\')
  56.                 {
  57.                     escaped = true;
  58.                 }
  59.                 else if (c == ',')
  60.                 {
  61.                     break;
  62.                 }
  63.                 else
  64.                 {
  65.                     buf.append(c);
  66.                 }
  67.             }
  68.             end++;
  69.         }
  70.         index = end;
  71.         return buf.toString().trim();
  72.     }
  73. }