View Javadoc
1 2 package jsdsi; 3 4 import java.io.IOException; 5 import java.io.ObjectStreamException; 6 import java.io.Serializable; 7 8 /*** 9 * A SPKI authorization: a tag and a propagate flag. 10 * 11 * @see AuthCert 12 * @author Sameer Ajmani 13 * @author Sean Radford 14 * @version $Revision: 1.2.6.2 $ $Date: 2005/11/08 03:12:52 $ 15 */ 16 public class Auth implements Serializable { 17 static final Auth NULL_AUTH = new Auth(Tag.NULL_TAG, false); 18 19 /*** 20 * The tag that holds the authorization. 21 */ 22 private final Tag tag; 23 24 /*** 25 * The propagate/delegation bit. 26 */ 27 private final boolean propagate; 28 29 /*** 30 * Creates a new <code>Auth</code> for a given <code>Tag</code> and 31 * propagation bit. 32 * 33 * @param t tag 34 * @param p propagation bit 35 */ 36 public Auth(Tag t, boolean p) { 37 assert (t != null) : "null tag"; 38 tag = t; 39 propagate = p; 40 } 41 42 /*** 43 * @return this.tag 44 */ 45 public Tag getTag() { 46 return tag; 47 } 48 49 /*** 50 * @return this.propagate 51 */ 52 public boolean getPropagate() { 53 return propagate; 54 } 55 56 /*** 57 * @see java.lang.Object#equals(Object) 58 */ 59 public boolean equals(Object o) { 60 if (o instanceof Auth) { 61 Auth a = (Auth) o; 62 return tag.equals(a.tag) && propagate == a.propagate; 63 } 64 return false; 65 } 66 67 /*** 68 * @return true iff this is valid whenever a is valid 69 */ 70 public boolean implies(Auth a) { 71 return (propagate || !a.propagate) && tag.implies(a.tag); 72 // The above says (this => a) when (a.prop => this.prop): 73 // if a has propagate, then this must also propagate 74 // if a doesn't propagate, then this can propagate or not 75 } 76 77 /*** 78 * @see java.lang.Object#hashCode() 79 */ 80 public int hashCode() { 81 return tag.hashCode() ^ (propagate ? 1 : 0); 82 } 83 84 /*** 85 * Writes <code>this</code> Auth to the given 86 * <code>java.io.ObjectOutputStream</code>. 87 * 88 * @see java.io.Serializable 89 * @param out the output stream 90 * @throws IOException 91 */ 92 private void writeObject(java.io.ObjectOutputStream out) 93 throws IOException { 94 if (this.tag.equals(Tag.NULL_TAG)) { 95 out.writeBoolean(false); 96 } else { 97 out.writeBoolean(true); 98 out.writeObject(this.tag); 99 } 100 out.writeBoolean(this.propagate); 101 } 102 103 /*** 104 * Reads an Auth from the given <code>java.io.ObjectInputStream</code>. 105 * @see java.io.Serializable 106 * @param in the input stream 107 * @throws IOException 108 * @throws ClassNotFoundException 109 */ 110 private void readObject(java.io.ObjectInputStream in) throws IOException, 111 ClassNotFoundException { 112 Tag tag = null; 113 if (in.readBoolean()) { 114 tag = (Tag) in.readObject(); 115 } else { 116 tag = Tag.NULL_TAG; 117 } 118 _replacement = new Auth(tag, in.readBoolean()); 119 } 120 121 protected transient Auth _replacement; 122 123 /*** 124 * Returns the Auth object which is the replacement after serialization. 125 * @see java.io.Serializable 126 * @return the replacement 127 * @throws ObjectStreamException 128 */ 129 protected Object readResolve() throws ObjectStreamException { 130 if (_replacement != null) { 131 return _replacement; 132 } else { 133 return this; 134 } 135 } 136 137 }

This page was automatically generated by Maven