Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

cryptix.openpgp.packet
Class PGPPacket  view PGPPacket download PGPPacket.java

java.lang.Object
  extended bycryptix.openpgp.packet.PGPPacket
Direct Known Subclasses:
PGPContainerPacket, PGPDummyPacket, PGPIDPacket, PGPKeyPacket, PGPLiteralDataPacket, PGPOnePassSignaturePacket, PGPSessionKeyPacket, PGPSignaturePacket

public abstract class PGPPacket
extends java.lang.Object

Superclass of all packets

Version:
$Revision: 1.3 $

Field Summary
private  int packetid
          the packet id, 256 means not set
 
Constructor Summary
PGPPacket()
           
 
Method Summary
abstract  void decodeBody(cryptix.openpgp.io.PGPPacketDataInputStream in, cryptix.openpgp.algorithm.PGPAlgorithmFactory factory)
          Decode the packet body,
 void encode(java.io.OutputStream out)
          Encode the packet.
abstract  void encodeBody(cryptix.openpgp.io.PGPPacketDataOutputStream out)
          Encode the packet body.
abstract  boolean equals(java.lang.Object ssp)
          Compare this packet to another one.
 int getForceLengthType()
          Return the forced length type for old style packets.
 byte getPacketID()
          Returns the packet type of this packet.
 int hashCode()
          Returns the hashcode for this object.
 boolean isLazy()
          Returns if this packet has lazy decoding.
 void setPacketID(byte id)
          Set the packet type of this packet.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

packetid

private int packetid
the packet id, 256 means not set

Constructor Detail

PGPPacket

public PGPPacket()
Method Detail

setPacketID

public void setPacketID(byte id)
Set the packet type of this packet.

See the OpenPGP specification for a list of the possible values.


getPacketID

public byte getPacketID()
Returns the packet type of this packet.

See the OpenPGP specification for a list of the possible values.


equals

public abstract boolean equals(java.lang.Object ssp)
Compare this packet to another one.


hashCode

public int hashCode()
Returns the hashcode for this object.

While this method is correct, it only uses the packetid and is thus far from optimal. Therefore subclasses should override this method if better Hashtable performance is needed.


decodeBody

public abstract void decodeBody(cryptix.openpgp.io.PGPPacketDataInputStream in,
                                cryptix.openpgp.algorithm.PGPAlgorithmFactory factory)
                         throws java.io.IOException,
                                cryptix.openpgp.PGPFatalDataFormatException,
                                cryptix.openpgp.PGPDataFormatException
Decode the packet body,

Implementations of this method should not try to read the type and length information as that is being taken care of by PGPPacketFactory and PGPPacketDataInputStream. It should only concern itself with the information in the packet itself.

If invalid data is detected the implementation should throw either PGPDataFormatException or PGPFatalDataFormatException. The implementation does not have to take precautions to read all the remaining data in the packet in case of a PGPDataFormatException, the caller will take care of that.


isLazy

public boolean isLazy()
Returns if this packet has lazy decoding.

Lazy decoding basically means that part of the inputstream has not been decoded yet after calling the decode method. This means that no more packets may be read from the inputstream until this packet has been read completely (using methods specific to that packet.

This mainly serves two purposes: it allows for streaming large packets and it allows a caller to pass in some more information necessairy for processing (for example a session key for decrypting).

This method returns false by default, which means that the packet is read entirely by a call to the decode method. Subclasses that do implement lazy decoding should override this method to return true.


getForceLengthType

public int getForceLengthType()
Return the forced length type for old style packets.

This is needed for PGP 2.x compatibility which requires some packets to have a suboptimal length: e.g. a signature packet that would be fine with a 1 byte length (type 0), must have a 2 byte length (type 1) or otherwise PGP 2.6 will complain.

Note that the default implementation just returns -1, meaning that no length is forced.


encode

public void encode(java.io.OutputStream out)
            throws java.io.IOException
Encode the packet.

This method simply constructs a PGPPacketDataOutputStream with the right PacketID, calls encodeBody en closes the PGPPacketDataOutputStream


encodeBody

public abstract void encodeBody(cryptix.openpgp.io.PGPPacketDataOutputStream out)
                         throws java.io.IOException
Encode the packet body.

Implementations of this method should not try to write the type and length information as that is being taken care of by the encode method and PGPPacketDataOutputStream. It should only write the data in the packet itself.