1 package jsdsi;
2
3 import java.util.Iterator;
4
5 import jsdsi.sexp.Sexp;
6 import jsdsi.sexp.SexpList;
7 import jsdsi.sexp.SexpParseException;
8 import jsdsi.sexp.SexpUtil;
9
10 /***
11 * A hash operation that instructs a verifier to hash an object for
12 * later reference.
13 *
14 * @author Sameer Ajmani
15 * @author Sean Radford
16 * @version $Revision: 1.3.2.1 $ $Date: 2005/11/08 03:12:52 $
17 */
18 public class HashOp extends Op {
19
20 private static final long serialVersionUID = 731956766278526069L;
21
22 /***
23 * The hash algorithm used in this hash op.
24 */
25 private transient final String algo;
26
27 /***
28 * Creates a new <code>HashOp</code> for a given hash algorithm.
29 *
30 * @param a name of the hash algorithm for this hash op.
31 */
32 public HashOp(String a) {
33 assert(a != null) : "null algo";
34 algo = a;
35 }
36
37 /***
38 * @return the name of the hash algorithm used.
39 */
40 public String getAlgorithm() {
41 return algo;
42 }
43
44 /***
45 * @see java.lang.Object#equals(Object)
46 */
47 public boolean equals(Object o) {
48 return (o instanceof HashOp) && algo.equals(((HashOp) o).algo);
49 }
50
51 /***
52 * @see java.lang.Object#hashCode()
53 */
54 public int hashCode() {
55 return algo.hashCode();
56 }
57
58 /***
59 * @return the <code>SexpList</code> representing this
60 * <code>HashOp</code>.
61 */
62 public SexpList toSexp() {
63 Sexp[] ss = new Sexp[2];
64 ss[0] = SexpUtil.toSexp("hash");
65 ss[1] = SexpUtil.toSexp(getAlgorithm());
66 return SexpUtil.toSexp("do", ss);
67 }
68
69 /***
70 * Parses a <code>HashOp</code> where the parameters are stored
71 * in a given <code>Iterator</code>.
72 *
73 * @param obody the <code>Iterator</code> that holds the parameters
74 * of the <code>HashOp</code>-
75 * @return a <code>HashOp</code> constructed from the parameters
76 * stores in <code>obody</code>.
77 * @throws SexpParseException
78 */
79 static HashOp parseHashOp(Iterator obody) throws SexpParseException {
80 String algo = SexpUtil.getNextString(obody, "hash algo");
81 SexpUtil.checkDone(obody, "op hash");
82 return new HashOp(algo);
83 }
84 }
This page was automatically generated by Maven