de.bb.security
Class Asn1

java.lang.Object
  |
  +--de.bb.security.Asn1

public class Asn1
extends java.lang.Object

Some helpfull static functions to handle ASN.1 with BER/DER


Field Summary
static byte BIT_STRING
           
static byte IA5String
           
static byte INTEGER
           
static byte[] newSeq
           
static byte[] newSet
           
static byte[] nul
           
static byte NULL
           
static byte OBJECT_IDENTIFIER
           
static byte OCTET_STRING
           
static byte PrintableString
           
static byte SEQUENCE
           
static byte SET
           
static byte T61String
           
static byte UTCTime
           
 
Constructor Summary
Asn1()
           
 
Method Summary
static byte[] addTo(byte[] b, byte[] a)
          Add an ASN.1 element to a sequence or a set.
static byte[] copy(byte[] b)
          Get a copy of the current object
static byte[] copy(byte[] b, int off)
          Get a copy of the current object
protected static boolean equals(byte[] a, int ai, byte[] b, int bi, int len)
           
static byte[] getData(byte[] b)
          Get the content of the current object
static byte[] getData(byte[] b, int off)
          Get the content of the current object
static int getInt(byte[] b, int[] s)
          Get an Integer from a sequence.
static int getLen(byte[] b)
          Get the total length of an object incl. header
static int getLen(byte[] b, int off)
          Get the total length of an object incl. header
static byte[] getSeq(byte[] b, int[] s, int off)
          Get some ASN.1 data from a sequence.
static byte[] makeASN1(byte[] b, int typ)
          Creates a new byte array containing an ASN.1 element.
static byte[] makeASN1(int i, int typ)
          creates a new byte array containing an ASN.1 element
static byte[] makeASN1(java.lang.String s, int typ)
          Creates a new byte array containing an ASN.1 element.
static byte[] nullEncode(byte[] b)
           
static int searchSequence(byte[] b, byte[] what)
          search the sequence containing the searched element
static int searchSequence(byte[] b, int[] off, byte[] what, int end)
          search the sequence containing the searched element
static int searchSequence(byte[] b, int off, byte[] what)
          search the sequence containing the searched element
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTEGER

public static final byte INTEGER

BIT_STRING

public static final byte BIT_STRING

OCTET_STRING

public static final byte OCTET_STRING

NULL

public static final byte NULL

OBJECT_IDENTIFIER

public static final byte OBJECT_IDENTIFIER

SEQUENCE

public static final byte SEQUENCE

SET

public static final byte SET

PrintableString

public static final byte PrintableString

T61String

public static final byte T61String

IA5String

public static final byte IA5String

UTCTime

public static final byte UTCTime

newSeq

public static final byte[] newSeq

newSet

public static final byte[] newSet

nul

public static final byte[] nul
Constructor Detail

Asn1

public Asn1()
Method Detail

makeASN1

public static byte[] makeASN1(java.lang.String s,
                              int typ)
Creates a new byte array containing an ASN.1 element.
Parameters:
s - the content of the new ASN.1 element.
typ - the kind of the new ASN.1 element.
Returns:
a new allocated byte array containing an ASN.1 element.

makeASN1

public static byte[] makeASN1(int i,
                              int typ)
creates a new byte array containing an ASN.1 element
Parameters:
i - the value of the new ASN.1 element
typ - the kind of the new ASN.1 element
Returns:
a new allocated byte array containing an ASN.1 element

makeASN1

public static byte[] makeASN1(byte[] b,
                              int typ)
Creates a new byte array containing an ASN.1 element.
Parameters:
b - the bytes of the new ASN.1 element.
typ - the kind of the new ASN.1 element.
Returns:
a new allocated byte array containing an ASN.1 element.

addTo

public static byte[] addTo(byte[] b,
                           byte[] a)
Add an ASN.1 element to a sequence or a set.
Parameters:
b - the bytes of the sequence or set.
a - the bytes which are added.
Returns:
a new allocated byte array containing the merged ASN.1 element.

getLen

public static int getLen(byte[] b)
Get the total length of an object incl. header
Parameters:
b - the bytes of the object.
Returns:
the total length of the object incl. header

getLen

public static int getLen(byte[] b,
                         int off)
Get the total length of an object incl. header
Parameters:
b - the bytes of the object.
off - - offset into the byte array
Returns:
the total length of the object incl. header

getData

public static byte[] getData(byte[] b)
Get the content of the current object
Parameters:
b - the bytes of the object.
Returns:
a new byte array containing the content of the current object

getData

public static byte[] getData(byte[] b,
                             int off)
Get the content of the current object
Parameters:
b - the bytes of the object.
off - - offset into the byte array
Returns:
a new byte array containing the content of the current object

copy

public static byte[] copy(byte[] b)
Get a copy of the current object
Parameters:
b - the bytes of the object.
Returns:
a new byte array containing the copy of the current object

copy

public static byte[] copy(byte[] b,
                          int off)
Get a copy of the current object
Parameters:
b - the bytes of the object.
off - - offset into the byte array
Returns:
a new byte array containing the copy of the current object

getSeq

public static final byte[] getSeq(byte[] b,
                                  int[] s,
                                  int off)
Get some ASN.1 data from a sequence. The path contains the types of the elements When 0x80 is or'd to the type, it means, that the given element is entered some examples path = 0x10: the first sequence is searched and return with header it IS the complete sequence path = 0x90: the first sequence is searched and its content is returned it IS the competet content of the sequence WITHOUT header path = 0x10, 0x90, 0x84: 0x10, search first sequence, do not enter 0x90, search next sequence, ENTER that sequence 0x84, search bitstring, return its content!
Parameters:
b - the sequence which is searched.
s - the path to the searched element.
off - an offset into b.
Returns:
a new allocated byte array which represent the searched element, or null when not found.

getInt

public static final int getInt(byte[] b,
                               int[] s)
Get an Integer from a sequence.
Parameters:
b - the sequence which is searched.
s - the path to the searched element.
Returns:
the value or zero when not found.

searchSequence

public static final int searchSequence(byte[] b,
                                       byte[] what)
search the sequence containing the searched element
Parameters:
b - a byte array containing the sequence
what - the element which is searched

searchSequence

public static final int searchSequence(byte[] b,
                                       int off,
                                       byte[] what)
search the sequence containing the searched element
Parameters:
b - a byte array containing the sequence
what - the element which is searched

searchSequence

public static final int searchSequence(byte[] b,
                                       int[] off,
                                       byte[] what,
                                       int end)
search the sequence containing the searched element
Parameters:
b - - a byte array containing the sequence
off - - an offest into the byte array
what - - the element which is searched
end - - end of range in b to use

nullEncode

public static byte[] nullEncode(byte[] b)

equals

protected static final boolean equals(byte[] a,
                                      int ai,
                                      byte[] b,
                                      int bi,
                                      int len)