1 package jsdsi;
2
3 import java.net.URI;
4 import java.util.ArrayList;
5 import java.util.Iterator;
6 import java.util.List;
7
8 import jsdsi.sexp.Sexp;
9 import jsdsi.sexp.SexpList;
10 import jsdsi.sexp.SexpParseException;
11 import jsdsi.sexp.SexpUtil;
12
13 /***
14 * Verifies whether a certificate is valid by contacting an online
15 * principal or its agent.
16 *
17 * @author Sameer Ajmani
18 * @author Sean Radford
19 * @version $Revision: 1.4.2.1 $ $Date: 2005/11/08 03:12:52 $
20 */
21 public abstract class OnlineTest extends Obj {
22
23 private static final long serialVersionUID = -2569498341322684308L;
24
25 /***
26 * Principal of this online test.
27 */
28 private transient final Principal principal;
29
30 /***
31 * URIs of this online test's principal (may be <code>null</code>).
32 */
33 private transient final URI[] uris; // may be null
34
35 /***
36 * Creates a new <code>OnlineTest</code> from a given principal and
37 * array of URIs.
38 *
39 * @param p principal for the new online test.
40 * @param u array of URIs for the new online test.
41 */
42 public OnlineTest(Principal p, URI[] u) {
43 assert(p != null) : "null principal";
44 principal = p;
45 uris = u;
46 }
47
48 /***
49 * @return the principal of this online test.
50 */
51 public Principal getPrincipal() {
52 return principal;
53 }
54
55 /***
56 * @return an array of URIs from this online test.
57 */
58 public URI[] getURIs() {
59 return uris;
60 }
61
62 /***
63 * @see java.lang.Object#equals(Object)
64 */
65 public boolean equals(Object o) {
66 if (o instanceof OnlineTest) {
67 OnlineTest t = (OnlineTest) o;
68 return principal.equals(t.principal) && Util.equals(uris, t.uris);
69 }
70 return false;
71 }
72
73 /***
74 * @see java.lang.Object#hashCode()
75 */
76 public int hashCode() {
77 return principal.hashCode() ^ Util.hashCode(uris);
78 }
79
80 abstract String getSexpType();
81 abstract Sexp[] getSexpParts();
82
83 public final SexpList toSexp() {
84 List l = new ArrayList();
85 l.add(SexpUtil.toSexp(getSexpType()));
86 l.add(SexpUtil.toSexp(getURIs()));
87 l.add(getPrincipal().toSexp());
88 Sexp[] parts = getSexpParts();
89 for (int i = 0; i < parts.length; i++) {
90 l.add(parts[i]);
91 }
92 return SexpUtil.toSexp("online", l);
93 }
94
95 static OnlineTest parseOnlineTest(SexpList l) throws SexpParseException {
96 Iterator obody = SexpUtil.getBody(l);
97 String type = SexpUtil.getNextString(obody, "online test type");
98 URI[] uris = SexpUtil.parseURIs(
99 SexpUtil.getNextList(obody,
100 "uri",
101 "online test uris"));
102 Principal principal = Principal.parsePrincipal(
103 SexpUtil.getNextList(obody,
104 "online test principal"));
105 if (type.equals("crl")) {
106 return Revocation.parseRevocation(principal, uris, obody);
107 }
108 if (type.equals("reval")) {
109 return Revalidation.parseRevalidation(principal, uris, obody);
110 }
111 if (type.equals("one-time")) {
112 return OneTime.parseOneTime(principal, uris, obody);
113 }
114 throw new SexpParseException("unrecognized online test type: " + type);
115 }
116 }
This page was automatically generated by Maven