⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x500distinguishedname.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* X500DistinguishedName.java -- X.500 distinguished name.   Copyright (C) 2004  Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package gnu.java.security.x509;import gnu.java.security.OID;import gnu.java.security.der.DER;import gnu.java.security.der.DERReader;import gnu.java.security.der.DERValue;import java.io.EOFException;import java.io.IOException;import java.io.InputStream;import java.io.Reader;import java.io.StringReader;import java.security.Principal;import java.util.ArrayList;import java.util.Collections;import java.util.HashSet;import java.util.Iterator;import java.util.LinkedHashMap;import java.util.LinkedList;import java.util.List;import java.util.Map;import java.util.Set;public class X500DistinguishedName implements Principal{  // Constants and fields.  // -------------------------------------------------------------------------  public static final OID CN         = new OID("2.5.4.3");  public static final OID C          = new OID("2.5.4.6");  public static final OID L          = new OID("2.5.4.7");  public static final OID ST         = new OID("2.5.4.8");  public static final OID STREET     = new OID("2.5.4.9");  public static final OID O          = new OID("2.5.4.10");  public static final OID OU         = new OID("2.5.4.11");  public static final OID T          = new OID("2.5.4.12");  public static final OID DNQ        = new OID("2.5.4.46");  public static final OID NAME       = new OID("2.5.4.41");  public static final OID GIVENNAME  = new OID("2.5.4.42");  public static final OID INITIALS   = new OID("2.5.4.43");  public static final OID GENERATION = new OID("2.5.4.44");  public static final OID EMAIL      = new OID("1.2.840.113549.1.9.1");  public static final OID DC         = new OID("0.9.2342.19200300.100.1.25");  public static final OID UID        = new OID("0.9.2342.19200300.100.1.1");  private List components;  private Map currentRdn;  private boolean fixed;  private String stringRep;  private byte[] encoded;  // Constructors.  // -------------------------------------------------------------------------  public X500DistinguishedName()  {    components = new LinkedList();    currentRdn = new LinkedHashMap();    components.add(currentRdn);  }  public X500DistinguishedName(String name)  {    this();    try      {        parseString(name);      }    catch (IOException ioe)      {        throw new IllegalArgumentException(ioe.toString());      }  }  public X500DistinguishedName(byte[] encoded) throws IOException  {    this();    parseDer(new DERReader(encoded));  }  public X500DistinguishedName(InputStream encoded) throws IOException  {    this();    parseDer(new DERReader(encoded));  }  // Instance methods.  // -------------------------------------------------------------------------  public String getName()  {    return toString();  }  public void newRelativeDistinguishedName()  {    if (fixed || currentRdn.isEmpty()) return;    currentRdn = new LinkedHashMap();    components.add(currentRdn);  }  public int size()  {    return components.size();  }  public int countComponents()  {    int count = 0;    for (Iterator it = components.iterator(); it.hasNext(); )      {        count += ((Map) it.next()).size();      }    return count;  }  public boolean containsComponent(OID oid, String value)  {    for (Iterator it = components.iterator(); it.hasNext(); )      {        Map rdn = (Map) it.next();        String s = (String) rdn.get(oid);        if (s == null)          continue;        if (compressWS(value).equalsIgnoreCase(compressWS(s)))          return true;      }    return false;  }  public String getComponent(OID oid)  {    for (Iterator it = components.iterator(); it.hasNext(); )      {        Map rdn = (Map) it.next();        if (rdn.containsKey(oid))          return (String) rdn.get(oid);      }    return null;  }  public String getComponent(OID oid, int rdn)  {    if (rdn >= size())      return null;    return (String) ((Map) components.get(rdn)).get(oid);  }  public void putComponent(OID oid, String value)  {    currentRdn.put(oid, value);  }  public void putComponent(String name, String value)  {    name = name.trim().toLowerCase();    if (name.equals("cn"))      putComponent(CN, value);    else if (name.equals("c"))      putComponent(C, value);    else if (name.equals("l"))      putComponent(L, value);    else if (name.equals("street"))      putComponent(STREET, value);    else if (name.equals("st"))      putComponent(ST, value);    else if (name.equals("t"))      putComponent(T, value);    else if (name.equals("dnq"))      putComponent(DNQ, value);    else if (name.equals("name"))      putComponent(NAME, value);    else if (name.equals("givenname"))      putComponent(GIVENNAME, value);    else if (name.equals("initials"))      putComponent(INITIALS, value);    else if (name.equals("generation"))      putComponent(GENERATION, value);    else if (name.equals("email"))      putComponent(EMAIL, value);    else if (name.equals("dc"))      putComponent(DC, value);    else if (name.equals("uid"))      putComponent(UID, value);    else      putComponent(new OID(name), value);  }  public void setUnmodifiable()  {    if (fixed) return;    fixed = true;    List newComps = new ArrayList(components.size());    for (Iterator it = components.iterator(); it.hasNext(); )      {        Map rdn = (Map) it.next();        rdn = Collections.unmodifiableMap(rdn);        newComps.add(rdn);      }    components = Collections.unmodifiableList(newComps);    currentRdn = Collections.EMPTY_MAP;  }  public int hashCode()  {    int sum = 0;    for (Iterator it = components.iterator(); it.hasNext(); )      {        Map m = (Map) it.next();        for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); )          {            Map.Entry e = (Map.Entry) it2.next();            sum += e.getKey().hashCode();            sum += e.getValue().hashCode();          }      }    return sum;  }  public boolean equals(Object o)  {    if (!(o instanceof X500DistinguishedName))      return false;    if (size() != ((X500DistinguishedName) o).size())      return false;    for (int i = 0; i < size(); i++)      {        Map m = (Map) components.get(i);        for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); )          {            Map.Entry e = (Map.Entry) it2.next();            OID oid = (OID) e.getKey();            String v1 = (String) e.getValue();            String v2 = ((X500DistinguishedName) o).getComponent(oid, i);            if (!compressWS(v1).equalsIgnoreCase(compressWS(v2)))              return false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -