Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / gnu / java / security / x509 / X509CRLSelectorImpl.java
blob0ada5501689aa15aaa743f7d16365cb7c23bba8f
1 /* X509CRLSelectorImpl.java -- implementation of an X509CRLSelector.
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.java.security.x509;
41 import java.io.IOException;
43 import java.security.Principal;
44 import java.security.cert.CRL;
45 import java.security.cert.CRLSelector;
46 import java.security.cert.X509CRL;
48 import java.util.Collection;
49 import java.util.Collections;
50 import java.util.HashSet;
51 import java.util.Iterator;
52 import java.util.Set;
54 import javax.security.auth.x500.X500Principal;
56 /**
57 * Sun's implementation of X509CRLSelector sucks. This one tries to work
58 * better.
60 public class X509CRLSelectorImpl implements CRLSelector
63 // Fields.
64 // -------------------------------------------------------------------------
66 private Set issuerNames;
68 // Constructor.
69 // -------------------------------------------------------------------------
71 public X509CRLSelectorImpl()
73 issuerNames = new HashSet();
76 // Instance methods.
77 // -------------------------------------------------------------------------
79 public void addIssuerName(byte[] issuerName) throws IOException
81 issuerNames.add(new X500DistinguishedName(issuerName));
84 public void addIssuerName(String issuerName)
86 issuerNames.add(new X500DistinguishedName(issuerName));
89 public void addIssuerName(Principal issuerName) throws IOException
91 if (issuerName instanceof X500DistinguishedName)
92 issuerNames.add(issuerName);
93 else if (issuerName instanceof X500Principal)
94 issuerNames.add(new X500DistinguishedName(((X500Principal) issuerName).getEncoded()));
95 else
96 issuerNames.add(new X500DistinguishedName(issuerName.getName()));
99 public Collection getIssuerNames()
101 return Collections.unmodifiableSet(issuerNames);
104 public Object clone()
106 X509CRLSelectorImpl copy = new X509CRLSelectorImpl();
107 copy.issuerNames.addAll(issuerNames);
108 return copy;
111 public boolean match(CRL crl)
113 if (!(crl instanceof X509CRL))
114 return false;
117 Principal p = ((X509CRL) crl).getIssuerDN();
118 X500DistinguishedName thisName = null;
119 if (p instanceof X500DistinguishedName)
120 thisName = (X500DistinguishedName) p;
121 else if (p instanceof X500Principal)
122 thisName = new X500DistinguishedName(((X500Principal) p).getEncoded());
123 else
124 thisName = new X500DistinguishedName(p.getName());
125 for (Iterator it = issuerNames.iterator(); it.hasNext(); )
127 X500DistinguishedName name = (X500DistinguishedName) it.next();
128 if (thisName.equals(name))
129 return true;
132 catch (Exception x)
135 return false;