1 package jsdsi;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import jsdsi.sexp.Sexp;
7 import jsdsi.sexp.SexpList;
8 import jsdsi.sexp.SexpUtil;
9
10 /***
11 * A SDSI name certificate: associates a string (a local name) with a
12 * Subject in the issuer's local namespace.
13 *
14 * @author Sameer Ajmani
15 * @author Sean Radford
16 * @version $Revision: 1.4.2.1 $
17 */
18 public class NameCert extends Cert {
19
20 private static final long serialVersionUID = -8560074033459222359L;
21
22 /***
23 * Name-string of this name certificate.
24 */
25 private transient final String name;
26
27 /***
28 * Creates a new name certificate from a given principal, subject,
29 * validity, display hint, comment, and (local) name.
30 *
31 * @param i issuer (principal).
32 * @param s subject.
33 * @param v validity
34 * @param d display hint.
35 * @param c comment.
36 * @param n name-string.
37 */
38 public NameCert(Principal i,
39 Subject s,
40 Validity v,
41 String d,
42 String c,
43 String n) {
44 super(i, s, v, d, c);
45 assert(n != null) : "null name";
46 name = n;
47 }
48
49 /***
50 * Returns the name-string of this name certificate.
51 *
52 * @return the name-string of this name certificate.
53 */
54 public String getName() {
55 return name;
56 }
57
58 /***
59 * Returns the full name, that is the <code>Name</code> that is created
60 * with this issuer and the name-string.
61 *
62 * @return a new <code>Name</code> created from this issuer and
63 * name-string.
64 */
65 public Name getFullName() {
66 return new Name(getIssuer(), new String[] { getName()});
67 }
68
69 /***
70 * @see java.lang.Object#equals(Object)
71 */
72 public boolean equals(Object o) {
73 return (o instanceof NameCert)
74 && name.equals(((NameCert) o).name)
75 && super.equals(o);
76 }
77
78 /***
79 * @return true iff this is at least as strong as c
80 */
81 public boolean implies(Cert c) {
82 return (c instanceof NameCert)
83 && name.equals(((NameCert)c).name)
84 && super.implies(c);
85 }
86
87 /***
88 * @see java.lang.Object#hashCode()
89 */
90 public int hashCode() {
91 return name.hashCode() ^ super.hashCode();
92 }
93
94 // TODO: move code common with AuthCert into Cert
95 public SexpList toSexp() {
96 List l = new ArrayList(5);
97
98 // display-hint
99 String display = this.getDisplay();
100 if (display!=null && display.equals("")==false) {
101 l.add( SexpUtil.toSexpDisplayHint(display) );
102 }
103
104 // issuer block
105 Sexp[] is = new Sexp[1];
106 Sexp[] ns = new Sexp[2];
107 ns[0] = getIssuer().toSexp();
108 ns[1] = SexpUtil.toSexp(getName());
109 is[0] = SexpUtil.toSexp("name", ns);
110 l.add(SexpUtil.toSexp("issuer", is));
111
112 // subject block
113 Sexp[] ss = new Sexp[1];
114 // FIXME: can we eliminate these downcasts?
115 if (getSubject() instanceof Name) {
116 // tell name about issuer
117 ss[0] = ((Name) getSubject()).toSexp(getIssuer());
118 } else if (getSubject() instanceof Threshold) {
119 // tell nested names about issuer
120 ss[0] = ((Threshold) getSubject()).toSexp(getIssuer());
121 } else {
122 ss[0] = getSubject().toSexp();
123 }
124 l.add(SexpUtil.toSexp("subject", ss));
125
126 if (getValidity() != null) {
127 l.add(getValidity().toSexp());
128 }
129 if (getComment() != null) {
130 l.add(SexpUtil.toSexpComment(getComment()));
131 }
132 return SexpUtil.toSexp("cert", l);
133 }
134 }
This page was automatically generated by Maven