ASN1C C# Runtime Library  7.2
Static Public Member Functions | List of all members
Asn1Util Class Reference

Static Public Member Functions

static System.String BCDToString (byte[] bcd)
 
static void CloseRuntime ()
 
static byte [] DecodeBase64Array (char[] srcArray)
 
static string EncodeBase64Array (byte[] srcArray)
 
static byte [] GetAddressBytes (string ipaddress)
 
static int GetBytesCount (long val)
 
static int GetUlongBytesCount (long val)
 
static bool IsLimited ()
 
static byte [] StringToBCD (System.String str)
 
static byte [] StringToTBCD (System.String str)
 
static String StripWhitespace (String value)
 
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)
 
static System.String ToHexString (byte[] b, int offset, int nbytes)
 
static System.String ToHexString (byte[] b, int offset, int nbytes, bool spaces)
 
static int URShift (int number, int bits)
 
static int URShift (int number, long bits)
 
static long URShift (long number, int bits)
 
static long URShift (long number, long 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

◆ BCDToString()

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
bcdthe source BCD string
Returns
the ASCII string.

References Asn1Util.URShift().

◆ CloseRuntime()

static void CloseRuntime ( )
static

Signal that you are finished with the ASN1C runtime and release internal resources. Do not use the runtime classes, on any thread, after calling this.

This may be called from any thread.

◆ DecodeBase64Array()

static byte [] DecodeBase64Array ( char []  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
srcArrayBase64 byte array to be translated
Returns
decoded byte array

Referenced by Asn1OctetString.DecodeXER().

◆ EncodeBase64Array()

static string EncodeBase64Array ( byte []  srcArray)
static

Translates the specified byte array to Base64 string.

Parameters
srcArraybyte array to be translated
Returns
Base64 encoded string

◆ GetAddressBytes()

static byte [] GetAddressBytes ( string  ipaddress)
static

Converts an IPaddress to byte array

Parameters
ipaddressString representation of IP Address
Returns
The byte array(size 4) represenation of IP address

References Tokenizer.HasMoreTokens(), and Tokenizer.NextToken().

◆ GetBytesCount()

static int GetBytesCount ( long  val)
static

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

Parameters
valsinged long value.
Returns
the number of bytes.

Referenced by Asn1Real.Encode(), Asn1BerOutputStream.EncodeLength(), and Asn1Real.NormalizedRealValueToString().

◆ GetUlongBytesCount()

static int GetUlongBytesCount ( long  val)
static

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

Parameters
valunsinged long value.
Returns
the number of bytes.

Referenced by Asn1Real.Encode(), and Asn1Real.NormalizedRealValueToString().

◆ IsLimited()

static bool IsLimited ( )
static

Indicates whether the run-time is limited or unlimited.

Returns
true if limited, false if unlimited

◆ StringToBCD()

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
strthe source ASCII string
Returns
the BCD string as a byte array.
Exceptions
Asn1ValueParseExceptionIf invalid characters are in the source string.

◆ StringToTBCD()

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
strthe source ASCII string
Returns
the TBCD string as a byte array.
Exceptions
Asn1ValueParseExceptionIf invalid characters are in the source string.

◆ StripWhitespace()

static String StripWhitespace ( String  value)
static

Return the given string with all whitespace characters removed. Here, "whitespace characters" means those characters defined by X.680 12.1.6 as whitespace: HT, LF, VT, FF, CR, SPACE.

Returns
value, with all whitespace removed; if the input string has no whitespace, it is returned itself.

Referenced by Asn1OID_IRI.Encode().

◆ TBCDToString()

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
bcdthe source TBCD string
Returns
the ASCII string.

References Asn1Util.URShift().

◆ ToArray()

static void ToArray ( System.Collections.ICollection  c,
System.Object []  objects 
)
static

Obtains an array containing all the elements of the collection.

Parameters
cThe Collection instance, which contains the elements.
objectsThe array into which the elements of the collection will be stored.
Returns
The array containing all the elements of the collection.

◆ ToByteArray()

static byte [] ToByteArray ( System.String  sourceString)
static

Converts a string to an array of bytes

Parameters
sourceStringThe string to be converted
Returns
The new array of bytes

Referenced by Asn1CerOutputStream.EncodeCharString(), and Asn1BerOutputStream.EncodeCharString().

◆ ToCharArray()

static char [] ToCharArray ( byte []  byteArray)
static

Converts an array of bytes to an array of chars

Parameters
byteArrayThe array of bytes to convert
Returns
The new array of chars

Referenced by Asn1XmlAnyElem.XsdAnySaxHandler.EndElement(), and Asn1OpenType.SaxHandler.EndElement().

◆ ToHexString() [1/3]

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
bbyte value
Returns
Hex String value

Referenced by Asn1BerMessageDumpHandler.Contents(), Asn1DecodeBitBuffer.DecodeBitsToLong(), Asn1DecodeBitBuffer.DecodeBitsToOctetArray(), Asn1OpenType.Encode(), Asn1PerBitFieldPrinter.Print(), Diag.Prtln(), Asn1DecodeBuffer.Read(), Asn1BerMessageDumpHandler.StartElement(), Asn1BitString.ToHexString(), and Asn1OctetString.ToString().

◆ ToHexString() [2/3]

static System.String ToHexString ( byte []  b,
int  offset,
int  nbytes 
)
static

Convert a array of bytes into a hex string.

Parameters
bbyte array to be converted to hex string
offsetstart position in byte array
nbytesno. of bytes to be converted
Returns
Hex String value

◆ ToHexString() [3/3]

static System.String ToHexString ( byte []  b,
int  offset,
int  nbytes,
bool  spaces 
)
static

Convert a array of bytes into a hex string.

Parameters
bbyte array to be converted to hex string
offsetstart position in byte array
nbytesno. of bytes to be converted
spacesPass true if each byte's hex digits should be followed by a space character.
Returns
Hex String value

◆ URShift() [1/4]

static int URShift ( int  number,
int  bits 
)
static

◆ URShift() [2/4]

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
numberNumber to operate on
bitsAmmount of bits to shift
Returns
The resulting number from the shift operation

◆ URShift() [3/4]

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
numberNumber to operate on
bitsAmmount of bits to shift
Returns
The resulting number from the shift operation

◆ URShift() [4/4]

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
numberNumber to operate on
bitsAmmount of bits to shift
Returns
The resulting number from the shift operation

◆ WriteStackTrace()

static void WriteStackTrace ( System.Exception  throwable,
System.IO.TextWriter  stream 
)
static

Writes the exception stack trace to the received stream

Parameters
throwableException to obtain information from
streamOutput sream used to write to

Referenced by Asn1XmlEncodeBuffer.Copy(), Asn1XerEncodeBuffer.Copy(), Asn1UTF8String.Encode(), Asn1XerOutputStream.Write(), and Asn1XmlOutputStream.Write().