sdsi
Class SDSIObject

java.lang.Object
  |
  +--sdsi.SDSIObject
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Acl, Acl.AclEntry, Cert, KeyHolder, Name, ObjectHash, Op, SDSIPrincipal, SDSIPrivateKey, SDSISecretKey, SDSISignature, Sequence, Tag, Threshold

public abstract class SDSIObject
extends java.lang.Object
implements java.io.Serializable

Class to represent SDSI objects. The many subclasses are useful for providing specific functionality inherent to individual types of objects.

Author:
Alexander Morcos, Sameer Ajmani
See Also:
Serialized Form

Field Summary
protected  Hash _hash
           
protected  boolean _modified
           
protected  SexpList srep
           
 
Constructor Summary
(package private) SDSIObject()
           
  SDSIObject(SexpList s)
          Creates a new SDSIObject from a SexpList.
 
Method Summary
 boolean equals(java.lang.Object object)
           
abstract  java.lang.String getAbbreviation()
          Returns a single or double letter abbreviation this SDSIObject.
 Hash getHash()
           
 byte[] getHash(java.security.MessageDigest md)
          Returns the hash of this SDSIObject.
 SexpList getSrep()
          Returns the S-Expression of this SDSIObject in canonical form as a SexpList
 java.lang.String getType()
          Returns a short string that represents the type of this SDSIObject.
 int hashCode()
           
static SDSIObject principalParse(SexpList l, SDSIPrincipal p)
          Generates the SDSI object that is represented by the SexpList in the argument.
static SDSIObject readFrom(java.io.InputStream is)
          Reads a SDSIObject from an input stream, assumes creating principal is null.
static SDSIObject readFrom(java.io.InputStream is, SDSIPrincipal p)
          Reads a SDSIObject from an input stream
 boolean sameAs(java.lang.Object object)
           
 void sign(java.security.Signature s)
          Updates a signature with the canonical representation of this SDSIObject.
 java.lang.String toReadableString(int width)
          Returns a string representing this SDSIObject encoded as an S-Expression.
abstract  java.lang.String toShortString()
          Returns a short descriptive string representing this SDSIObject.
 java.lang.String toString()
          Returns a string of this SDSIObject represented in canonical form.
 void writeCanonical(java.io.OutputStream os)
          Writes this SDSIObject to an output stream in canonical form
 void writeReadable(java.io.OutputStream os)
          Writes this SDSIObject to an output stream in readable form
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

srep

protected SexpList srep

_hash

protected transient Hash _hash

_modified

protected transient boolean _modified
Constructor Detail

SDSIObject

SDSIObject()

SDSIObject

public SDSIObject(SexpList s)
Creates a new SDSIObject from a SexpList.

Parameters:
s - the SexpList that represents the SDSIObject.
Method Detail

getHash

public Hash getHash()
             throws java.security.NoSuchAlgorithmException
java.security.NoSuchAlgorithmException

sameAs

public boolean sameAs(java.lang.Object object)

equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

readFrom

public static SDSIObject readFrom(java.io.InputStream is,
                                  SDSIPrincipal p)
                           throws java.io.IOException,
                                  SDSIException
Reads a SDSIObject from an input stream

Parameters:
is - the input stream to read from
p - the "creating principal" of the object
Returns:
the parsed SDSIObject
Throws:
java.io.IOException - error reading from stream
SDSIException - error parsing object

readFrom

public static SDSIObject readFrom(java.io.InputStream is)
                           throws java.io.IOException,
                                  SDSIException
Reads a SDSIObject from an input stream, assumes creating principal is null.

Parameters:
is - the input stream to read from
Returns:
the parsed SDSIObject
Throws:
java.io.IOException - error reading from stream
SDSIException - error parsing object

writeReadable

public void writeReadable(java.io.OutputStream os)
                   throws java.io.IOException
Writes this SDSIObject to an output stream in readable form

Parameters:
os - the output stream to write to
Throws:
java.io.IOException - error writing to stream

writeCanonical

public void writeCanonical(java.io.OutputStream os)
                    throws java.io.IOException
Writes this SDSIObject to an output stream in canonical form

Parameters:
os - the output stream to write to
Throws:
java.io.IOException - error writing to stream

principalParse

public static SDSIObject principalParse(SexpList l,
                                        SDSIPrincipal p)
                                 throws SexpParseException
Generates the SDSI object that is represented by the SexpList in the argument. Parses the SexpList in the argument and returns the appropriate subclass of SDSIObject that has been initialized by the SexpList. Is capable of parsing Acl's, KeyHolder's, and Name's that may require a creating princpal to be known.

Parameters:
l - the SexpLIst to be parsed.
p - the SDSIPrincipal that should be treated as having created the object
Returns:
the SDSI objecet represented
Throws:
SexpParseException - if the SexpList cannot be succesfully parsed into a SDSIObject

toShortString

public abstract java.lang.String toShortString()
Returns a short descriptive string representing this SDSIObject.

Returns:
a short string description of this SDSIObject.

getAbbreviation

public abstract java.lang.String getAbbreviation()
Returns a single or double letter abbreviation this SDSIObject.

Returns:
an abbreviated description of this SDSIObject.

toString

public java.lang.String toString()
Returns a string of this SDSIObject represented in canonical form.

Overrides:
toString in class java.lang.Object
Returns:
a string containing the canonical form of this SDSIObject.

toReadableString

public java.lang.String toReadableString(int width)
Returns a string representing this SDSIObject encoded as an S-Expression. The String contains only printable characters, is nicely formatted, and is a valid S-Expression.

Parameters:
width - the maximum width of any line in the string.
Returns:
a nicely formatted string containing the S-Expression of this SDSIObject.

getHash

public byte[] getHash(java.security.MessageDigest md)
Returns the hash of this SDSIObject. Hashes the canonical representation of this SDSIObject and returns the resulting byte array.

Parameters:
md - the MessageDigest to use for the hash, it will be reset.
Returns:
the hash of the canonical representation of this SDSIObject as a byte array.

sign

public void sign(java.security.Signature s)
          throws java.security.SignatureException
Updates a signature with the canonical representation of this SDSIObject.

Parameters:
s - the signature to update.
Throws:
java.security.SignatureException - if the argument is not a properly initialized Signature object.

getType

public java.lang.String getType()
Returns a short string that represents the type of this SDSIObject.

Returns:
a string represent the type of SDSIObject we're dealing with.

getSrep

public SexpList getSrep()
Returns the S-Expression of this SDSIObject in canonical form as a SexpList

Returns:
the SexpList that encodes this SDSIObject in canonical form.