XCMS Toolkit

schemajic.encoder
Class TagEncoder

java.lang.Object
  extended by schemajic.encoder.TagEncoder

public class TagEncoder
extends java.lang.Object

Supports ASN.1 tagged type encodings.

Version:
1.00 - 2006/02/10
Author:
support@phillipgriffin.com

Constructor Summary
TagEncoder()
          Constructor for TagEncoder.
 
Method Summary
 int calculateEncodedLength(Tag tag)
          Determine the encoded length of a given tag.
 int calculateEncodedLength(TagList tags)
          Calculate the total length in bytes of the tags in a TagList and check that tag values are in the expected range.
 void encode(TagList tags, int pc, java.io.OutputStream out)
          Encodes a list of tags to an output stream.
protected  void encodeLongTag(int tag, int tClass, int tPC, java.io.OutputStream out)
          Throws a RuntimeException when a long tag is detected, since this tag format is not supported.
protected  void encodeShortTag(int tag, java.io.OutputStream out)
          Write out an ASN.1 tag.
 void encodeTags(TagList tags, int pc, java.io.OutputStream out)
          Encode a list of ASN.1 tags.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TagEncoder

public TagEncoder()
Constructor for TagEncoder.

Method Detail

encode

public void encode(TagList tags,
                   int pc,
                   java.io.OutputStream out)
            throws EncodingException
Encodes a list of tags to an output stream.

Parameters:
tags - a list of ASN.1 tags
pc - counter
out - output stream target of encoding
Throws:
EncodingException

calculateEncodedLength

public int calculateEncodedLength(TagList tags)
                           throws java.lang.RuntimeException
Calculate the total length in bytes of the tags in a TagList and check that tag values are in the expected range.

Note that the tags need not be recognized, since the ASN.1 standards evolve and a new tag may from time to time be assigned after a using application has been deployed.

Parameters:
tags - a list of ASN.1 tags
Returns:
integer length of encoding
Throws:
java.lang.RuntimeException

calculateEncodedLength

public int calculateEncodedLength(Tag tag)
                           throws java.lang.RuntimeException
Determine the encoded length of a given tag.

Note that only one-byte tags are supported at this time.

Parameters:
tag - a tag whose length is to be measured
Returns:
the length of the tag is one as expected
Throws:
java.lang.RuntimeException

encodeTags

public void encodeTags(TagList tags,
                       int pc,
                       java.io.OutputStream out)
                throws java.io.IOException
Encode a list of ASN.1 tags.

Parameters:
tags - a list of ASN.1 tags
pc - counter
out - output stream target of encoding
Throws:
java.io.IOException

encodeShortTag

protected void encodeShortTag(int tag,
                              java.io.OutputStream out)
                       throws java.io.IOException
Write out an ASN.1 tag. Since a 'tag number' is < 31, it may be encoded in a single octet.

Parameters:
tag - a single ASN.1 tag
out - output stream target of encoding
Throws:
java.io.IOException

encodeLongTag

protected void encodeLongTag(int tag,
                             int tClass,
                             int tPC,
                             java.io.OutputStream out)
                      throws java.lang.RuntimeException
Throws a RuntimeException when a long tag is detected, since this tag format is not supported. This method then is a placeholder for future support.

A 'tag number' was > 30, and therefore must be encoded in multiple octets, each with 7 significant bits.

Convert an array of 8-bit bytes, with bit 8 being significant, to an array of 8-bit bytes with bit 7 being significant. Bit 8 will always be 1 unless the byte is the last in the array, where bit 8 will be 0.

 Example 1:

 11111111 11111111

 100000011 11111111 01111111

 Example 2:

 10000001 10000001

 10000001 10000001 00000001

 { 1 2 840 113549 }

 06 06 2a 86 48 86 f7 0d

 06062a864886f70d
 

Throws:
java.lang.RuntimeException

XCMS Toolkit


Copyright © 2005-2006 GRIFFIN Consulting. All Rights Reserved.