home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / sun / security / x509 / X500Name.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  5.7 KB  |  231 lines

  1. package sun.security.x509;
  2.  
  3. import java.io.IOException;
  4. import java.security.Principal;
  5. import sun.security.util.DerInputStream;
  6. import sun.security.util.DerOutputStream;
  7. import sun.security.util.DerValue;
  8. import sun.security.util.ObjectIdentifier;
  9.  
  10. public class X500Name implements Principal {
  11.    // $FF: renamed from: dn java.lang.String
  12.    private String field_0;
  13.    private RDN[] names;
  14.    private static final int[] commonName_data = new int[]{2, 5, 4, 3};
  15.    private static final int[] countryName_data = new int[]{2, 5, 4, 6};
  16.    private static final int[] localityName_data = new int[]{2, 5, 4, 7};
  17.    private static final int[] stateName_data = new int[]{2, 5, 4, 8};
  18.    private static final int[] streetAddress_data = new int[]{2, 5, 4, 9};
  19.    private static final int[] orgName_data = new int[]{2, 5, 4, 10};
  20.    private static final int[] orgUnitName_data = new int[]{2, 5, 4, 11};
  21.    private static final int[] title_data = new int[]{2, 5, 4, 12};
  22.    public static final ObjectIdentifier commonName_oid;
  23.    public static final ObjectIdentifier countryName_oid;
  24.    public static final ObjectIdentifier localityName_oid;
  25.    public static final ObjectIdentifier orgName_oid;
  26.    public static final ObjectIdentifier orgUnitName_oid;
  27.    public static final ObjectIdentifier stateName_oid;
  28.    public static final ObjectIdentifier streetAddress_oid;
  29.    public static final ObjectIdentifier title_oid;
  30.    private static final int[] ipAddress_data;
  31.    public static final ObjectIdentifier ipAddress_oid;
  32.  
  33.    private X500Name(String var1) {
  34.       this.parseDN(var1);
  35.    }
  36.  
  37.    public X500Name(String var1, String var2, String var3, String var4) throws IOException {
  38.       this.names = new RDN[4];
  39.       this.names[3] = new RDN(1);
  40.       this.names[3].assertion[0] = new AVA(commonName_oid, new DerValue(var1));
  41.       this.names[2] = new RDN(1);
  42.       this.names[2].assertion[0] = new AVA(orgUnitName_oid, new DerValue(var2));
  43.       this.names[1] = new RDN(1);
  44.       this.names[1].assertion[0] = new AVA(orgName_oid, new DerValue(var3));
  45.       this.names[0] = new RDN(1);
  46.       this.names[0].assertion[0] = new AVA(countryName_oid, new DerValue(var4));
  47.    }
  48.  
  49.    public X500Name(String var1, String var2, String var3, String var4, String var5, String var6) throws IOException {
  50.       this.names = new RDN[6];
  51.       this.names[5] = new RDN(1);
  52.       this.names[5].assertion[0] = new AVA(commonName_oid, new DerValue(var1));
  53.       this.names[4] = new RDN(1);
  54.       this.names[4].assertion[0] = new AVA(orgUnitName_oid, new DerValue(var2));
  55.       this.names[3] = new RDN(1);
  56.       this.names[3].assertion[0] = new AVA(orgName_oid, new DerValue(var3));
  57.       this.names[2] = new RDN(1);
  58.       this.names[2].assertion[0] = new AVA(localityName_oid, new DerValue(var4));
  59.       this.names[1] = new RDN(1);
  60.       this.names[1].assertion[0] = new AVA(stateName_oid, new DerValue(var5));
  61.       this.names[0] = new RDN(1);
  62.       this.names[0].assertion[0] = new AVA(countryName_oid, new DerValue(var6));
  63.    }
  64.  
  65.    public X500Name(DerValue var1) throws IOException {
  66.       this(var1.toDerInputStream());
  67.    }
  68.  
  69.    public X500Name(DerInputStream var1) throws IOException {
  70.       this.parseDER(var1);
  71.    }
  72.  
  73.    public boolean equals(X500Name var1) {
  74.       if (this == var1) {
  75.          return true;
  76.       } else {
  77.          if (this.field_0 == null) {
  78.             this.generateDN();
  79.          }
  80.  
  81.          if (this.names.length != var1.names.length) {
  82.             return false;
  83.          } else {
  84.             for(int var2 = 0; var2 < this.names.length; ++var2) {
  85.                if (!this.names[var2].equals(var1.names[var2])) {
  86.                   return false;
  87.                }
  88.             }
  89.  
  90.             return true;
  91.          }
  92.       }
  93.    }
  94.  
  95.    private String getString(DerValue var1) throws IOException {
  96.       String var2 = var1.getAsString();
  97.       if (var2 == null) {
  98.          throw new IOException("not a DER string encoding, " + var1.tag);
  99.       } else {
  100.          return var2;
  101.       }
  102.    }
  103.  
  104.    public String getCountry() throws IOException {
  105.       DerValue var1 = this.findAttribute(countryName_oid);
  106.       return this.getString(var1);
  107.    }
  108.  
  109.    public String getOrganization() throws IOException {
  110.       DerValue var1 = this.findAttribute(orgName_oid);
  111.       return this.getString(var1);
  112.    }
  113.  
  114.    public String getOrganizationalUnit() throws IOException {
  115.       DerValue var1 = this.findAttribute(orgUnitName_oid);
  116.       return this.getString(var1);
  117.    }
  118.  
  119.    public String getCommonName() throws IOException {
  120.       DerValue var1 = this.findAttribute(commonName_oid);
  121.       return this.getString(var1);
  122.    }
  123.  
  124.    public String getLocality() throws IOException {
  125.       DerValue var1 = this.findAttribute(localityName_oid);
  126.       return this.getString(var1);
  127.    }
  128.  
  129.    public String getState() throws IOException {
  130.       DerValue var1 = this.findAttribute(stateName_oid);
  131.       return this.getString(var1);
  132.    }
  133.  
  134.    public String toString() {
  135.       if (this.field_0 == null) {
  136.          this.generateDN();
  137.       }
  138.  
  139.       return this.field_0;
  140.    }
  141.  
  142.    public String getName() {
  143.       return this.toString();
  144.    }
  145.  
  146.    private DerValue findAttribute(ObjectIdentifier var1) {
  147.       DerValue var3 = null;
  148.  
  149.       for(int var2 = 0; var2 < this.names.length; ++var2) {
  150.          var3 = this.names[var2].findAttribute(var1);
  151.          if (var3 != null) {
  152.             break;
  153.          }
  154.       }
  155.  
  156.       return var3;
  157.    }
  158.  
  159.    private void parseDER(DerInputStream var1) throws IOException {
  160.       DerValue[] var2 = var1.getSequence(5);
  161.       this.names = new RDN[var2.length];
  162.  
  163.       for(int var3 = 0; var3 < var2.length; ++var3) {
  164.          this.names[var3] = new RDN(var2[var3]);
  165.       }
  166.  
  167.    }
  168.  
  169.    public void emit(DerOutputStream var1) throws IOException {
  170.       DerOutputStream var2 = new DerOutputStream();
  171.  
  172.       for(int var3 = 0; var3 < this.names.length; ++var3) {
  173.          this.names[var3].emit(var2);
  174.       }
  175.  
  176.       var1.write((byte)48, var2);
  177.    }
  178.  
  179.    private void parseDN(String var1) {
  180.    }
  181.  
  182.    private void generateDN() {
  183.       String var2 = null;
  184.  
  185.       for(int var1 = this.names.length - 1; var1 >= 0; --var1) {
  186.          if (var2 == null) {
  187.             var2 = this.names[var1].toString();
  188.          } else {
  189.             var2 = var2 + ", " + this.names[var1].toString();
  190.          }
  191.       }
  192.  
  193.       this.field_0 = var2;
  194.    }
  195.  
  196.    static ObjectIdentifier intern(ObjectIdentifier var0) {
  197.       if (var0.equals(commonName_oid)) {
  198.          return commonName_oid;
  199.       } else if (var0.equals(countryName_oid)) {
  200.          return countryName_oid;
  201.       } else if (var0.equals(localityName_oid)) {
  202.          return localityName_oid;
  203.       } else if (var0.equals(stateName_oid)) {
  204.          return stateName_oid;
  205.       } else if (var0.equals(streetAddress_oid)) {
  206.          return streetAddress_oid;
  207.       } else if (var0.equals(orgName_oid)) {
  208.          return orgName_oid;
  209.       } else if (var0.equals(orgUnitName_oid)) {
  210.          return orgUnitName_oid;
  211.       } else if (var0.equals(title_oid)) {
  212.          return title_oid;
  213.       } else {
  214.          return var0.equals(ipAddress_oid) ? ipAddress_oid : var0;
  215.       }
  216.    }
  217.  
  218.    static {
  219.       commonName_oid = new ObjectIdentifier(commonName_data);
  220.       countryName_oid = new ObjectIdentifier(countryName_data);
  221.       localityName_oid = new ObjectIdentifier(localityName_data);
  222.       orgName_oid = new ObjectIdentifier(orgName_data);
  223.       orgUnitName_oid = new ObjectIdentifier(orgUnitName_data);
  224.       stateName_oid = new ObjectIdentifier(stateName_data);
  225.       streetAddress_oid = new ObjectIdentifier(streetAddress_data);
  226.       title_oid = new ObjectIdentifier(title_data);
  227.       ipAddress_data = new int[]{1, 3, 6, 1, 4, 1, 42, 2, 11, 2, 1};
  228.       ipAddress_oid = new ObjectIdentifier(ipAddress_data);
  229.    }
  230. }
  231.