org.apache.asn1.ber.primitives
Class PrimitiveUtils

java.lang.Object
  extended by org.apache.asn1.ber.primitives.PrimitiveUtils

public class PrimitiveUtils
extends java.lang.Object

Utilities for decoding and encoding primitive constructs.

Version:
$Rev: 157644 $
Author:
Apache Directory Project

Field Summary
private static byte[] FALSE_ARRAY
           
private static int FOUR_BYTE_MAX
           
private static int FOUR_BYTE_MIN
           
private static int ONE_BYTE_MAX
           
private static int ONE_BYTE_MIN
           
private static int THREE_BYTE_MAX
           
private static int THREE_BYTE_MIN
           
private static byte[] TRUE_ARRAY
           
private static int TWO_BYTE_MAX
           
private static int TWO_BYTE_MIN
           
 
Constructor Summary
PrimitiveUtils()
           
 
Method Summary
static boolean berDecodeBoolean(byte value)
           
static int decodeInt(byte[] bites, int offset, int length)
          Decodes a BER encoded ASN.1 INTEGER into a Java primitive int.
static boolean derCerDecodeBoolean(byte value)
           
static byte[] encodeBoolean(boolean bool)
          Encodes a boolean as a byte[] with one byte following the stricter CER and DER requirements where true must be a value of 0xFF and false is 0x00.
static byte encodeBooleanAsByte(boolean bool)
          Encodes a boolean as a byte following the stricter CER and DER requirements where true must be a value of 0xFF and false is 0x00.
static byte[] encodeInt(int source)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONE_BYTE_MAX

private static final int ONE_BYTE_MAX
See Also:
Constant Field Values

ONE_BYTE_MIN

private static final int ONE_BYTE_MIN
See Also:
Constant Field Values

TWO_BYTE_MAX

private static final int TWO_BYTE_MAX
See Also:
Constant Field Values

TWO_BYTE_MIN

private static final int TWO_BYTE_MIN
See Also:
Constant Field Values

THREE_BYTE_MAX

private static final int THREE_BYTE_MAX
See Also:
Constant Field Values

THREE_BYTE_MIN

private static final int THREE_BYTE_MIN
See Also:
Constant Field Values

FOUR_BYTE_MAX

private static final int FOUR_BYTE_MAX
See Also:
Constant Field Values

FOUR_BYTE_MIN

private static final int FOUR_BYTE_MIN
See Also:
Constant Field Values

TRUE_ARRAY

private static final byte[] TRUE_ARRAY

FALSE_ARRAY

private static final byte[] FALSE_ARRAY
Constructor Detail

PrimitiveUtils

public PrimitiveUtils()
Method Detail

berDecodeBoolean

public static boolean berDecodeBoolean(byte value)

encodeBooleanAsByte

public static byte encodeBooleanAsByte(boolean bool)
Encodes a boolean as a byte following the stricter CER and DER requirements where true must be a value of 0xFF and false is 0x00.

Parameters:
bool - the boolean to encode
Returns:
0xFF if bool is true, 0x00 if the bool is false

encodeBoolean

public static byte[] encodeBoolean(boolean bool)
Encodes a boolean as a byte[] with one byte following the stricter CER and DER requirements where true must be a value of 0xFF and false is 0x00. Although there is alway one byte returned we return a byte [] as a convenience since most of the time a byte[] is expected after encoding a primitive type.

Parameters:
bool - the boolean to encode
Returns:
a byte array of length 1 where the single byte is 0xFF if bool is true, 0x00 if the bool is false

derCerDecodeBoolean

public static boolean derCerDecodeBoolean(byte value)

encodeInt

public static byte[] encodeInt(int source)

decodeInt

public static int decodeInt(byte[] bites,
                            int offset,
                            int length)
Decodes a BER encoded ASN.1 INTEGER into a Java primitive int.

Parameters:
bites - the bytes containing the encoded ASN.1 INTEGER
offset - the offset from zero where the bytes begin
length - the length of the bytes to read from the offset
Returns:
the decoded primitive int or zero if the length is 0
Throws:
java.lang.IllegalArgumentException - if the length is not within range [0-4]
java.lang.IndexOutOfBoundsException - if offset is less than 0 or it is greater than bites.length - length


Copyright © 2004-2009 . All Rights Reserved.