Asn1Util Class Reference

List of all members.

Static Public Member Functions

static System.String BCDToString (byte[] bcd)
static byte[] DecodeBase64Array (byte[] srcArray)
static byte[] EncodeBase64Array (byte[] srcArray)
static byte[] GetAddressBytes (string ipaddress)
static int GetBytesCount (long val)
static int GetUlongBytesCount (long val)
static byte[] StringToBCD (System.String str)
static byte[] StringToTBCD (System.String str)
static System.String TBCDToString (byte[] bcd)
static void ToArray (System.Collections.ICollection c, System.Object[] objects)
static byte[] ToByteArray (System.String sourceString)
static char[] ToCharArray (byte[] byteArray)
static System.String ToHexString (byte[] b, int offset, int nbytes)
static System.String ToHexString (byte b)
static long URShift (long number, long bits)
static long URShift (long number, int bits)
static int URShift (int number, long bits)
static int URShift (int number, int bits)
static void WriteStackTrace (System.Exception throwable, System.IO.TextWriter stream)

Detailed Description

This class contains some general purpose static utility functions.


Member Function Documentation

static System.String BCDToString ( byte[]  bcd  )  [static]

Translates a BCD string to an ASCII string. The 0xF half-byte is assumed as end of string indicator.

Parameters:
bcd the source BCD string
Returns:
the ASCII string.
static byte [] DecodeBase64Array ( byte[]  srcArray  )  [static]

Translates the specified Base64 array into byte array. The resulting array could be converted to the String by new String (byte[]) constructor.

Parameters:
srcArray Base64 byte array to be translated
Returns:
decoded byte array
static byte [] EncodeBase64Array ( byte[]  srcArray  )  [static]

Translates the specified byte array to Base64 byte array. The resulting array could be converted to the String by new String (byte[]) constructor.

Parameters:
srcArray byte array to be translated
Returns:
Base64 encoded byte array
static byte [] GetAddressBytes ( string  ipaddress  )  [static]

Converts an IPaddress to byte array

Parameters:
ipaddress String representation of IP Address
Returns:
The byte array(size 4) represenation of IP address
static int GetBytesCount ( long  val  )  [static]

Calculate the number of bytes necessary to represent a signed long value.

Parameters:
val singed long value.
Returns:
the number of bytes.
static int GetUlongBytesCount ( long  val  )  [static]

Calculate the number of bytes necessary to represent an unsigned long value.

Parameters:
val unsinged long value.
Returns:
the number of bytes.
static byte [] StringToBCD ( System.String  str  )  [static]

Translates an ASCII string to a BCD string. The ASCII string must contain only characters in the range [0..9] & ([A..F] | [a..f]). If the length of the source string is not even, the unused part of the last byte will be set to 0xF.

Parameters:
str the source ASCII string
Returns:
the BCD string as a byte array.
Exceptions:
Asn1ValueParseException If invalid characters are in the source string.
static byte [] StringToTBCD ( System.String  str  )  [static]

Translates an ASCII string to a TBCD string. The ASCII string must contain only characters in the range [0..9] & ([A..F] | [a..f]). If the length of the source string is not even, the unused part of the last byte will be set to 0xF. TBCD strings differ from BCD strings in that the least significant nibble is set in the upper four bits; so the string "12345" would be translated "0x2143f5".

Parameters:
str the source ASCII string
Returns:
the TBCD string as a byte array.
Exceptions:
Asn1ValueParseException If invalid characters are in the source string.
static System.String TBCDToString ( byte[]  bcd  )  [static]

Translates a TBCD string to an ASCII string. The 0xF half-byte is assumed as end of string indicator.

Parameters:
bcd the source TBCD string
Returns:
the ASCII string.
static void ToArray ( System.Collections.ICollection  c,
System.Object[]  objects 
) [static]

Obtains an array containing all the elements of the collection.

Parameters:
c The Collection instance, which contains the elements.
objects The array into which the elements of the collection will be stored.
Returns:
The array containing all the elements of the collection.
static byte [] ToByteArray ( System.String  sourceString  )  [static]

Converts a string to an array of bytes

Parameters:
sourceString The string to be converted
Returns:
The new array of bytes
static char [] ToCharArray ( byte[]  byteArray  )  [static]

Converts an array of bytes to an array of chars

Parameters:
byteArray The array of bytes to convert
Returns:
The new array of chars
static System.String ToHexString ( byte[]  b,
int  offset,
int  nbytes 
) [static]

Convert a array of bytes into a hex string.

Parameters:
b byte array to be converted to hex string
offset start position in byte array
nbytes no. of bytes to be converted
Returns:
Hex String value
static System.String ToHexString ( byte  b  )  [static]

Convert a byte value to a hex string. Unlike the C# built-in function, this will:

a. not sign extend the byte value out to 32 bits if the MSB is set, and b. put a zero padding byte in front if less than 0xf

In other words, a character string of length 2 is always returned.

Parameters:
b byte value
Returns:
Hex String value
static long URShift ( long  number,
long  bits 
) [static]

Performs an unsigned bitwise right shift with the specified number The low-order bits of number are discarded, the remaining bits are shifted right, and the high-order empty bit positions are set to zero.

Parameters:
number Number to operate on
bits Ammount of bits to shift
Returns:
The resulting number from the shift operation
static long URShift ( long  number,
int  bits 
) [static]

Performs an unsigned bitwise right shift with the specified number The low-order bits of number are discarded, the remaining bits are shifted right, and the high-order empty bit positions are set to zero.

Parameters:
number Number to operate on
bits Ammount of bits to shift
Returns:
The resulting number from the shift operation
static int URShift ( int  number,
long  bits 
) [static]

Performs an unsigned bitwise right shift with the specified number The low-order bits of number are discarded, the remaining bits are shifted right, and the high-order empty bit positions are set to zero.

Parameters:
number Number to operate on
bits Ammount of bits to shift
Returns:
The resulting number from the shift operation
static int URShift ( int  number,
int  bits 
) [static]

Performs an unsigned bitwise right shift with the specified number. The low-order bits of number are discarded, the remaining bits are shifted right, and the high-order empty bit positions are set to zero.

Parameters:
number Number to operate on
bits Ammount of bits to shift
Returns:
The resulting number from the shift operation
static void WriteStackTrace ( System.Exception  throwable,
System.IO.TextWriter  stream 
) [static]

Writes the exception stack trace to the received stream

Parameters:
throwable Exception to obtain information from
stream Output sream used to write to