ASN1C C# Runtime Library  7.8
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 int HexToByte (char c)
 
static bool IsLimited ()
 
static string [] PLMNidentityToString (byte[] plmnIdentity)
 
static byte [] StringToBCD (System.String str)
 
static byte [] StringToPLMNidentity (string mcc, string mnc)
 
static byte [] StringToTBCD (System.String str)
 
static String StripWhitespace (String value)
 
static char TbcdBinToChar (byte tbcdDigit)
 
static byte TbcdCharToBin (char digit)
 
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 char ToHexChar (int nibble)
 
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 returned string will consist of characters in [0..9] and [A-E]. All half-bytes in the input shall be less than 0xF, except that in the final byte, the low half-byte may be 0xF, to act as filler for a string of odd length.

Parameters
bcdthe source BCD string
Returns
the ASCII string.

References Asn1Util.URShift().

Referenced by Asn1BCDString.ToString().

◆ 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(), and Asn1OctetString.DecodeXML().

◆ 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().

◆ HexToByte()

static int HexToByte ( char  c)
static

Return the value of a single hexadecimal character. /p>

Parameters
cThe hex character (0-9,A-F,a-f)
Returns
Value of hex character, 0-15.
Exceptions
Asn1ExceptionThrown if character is not a valid hexadecimal character.

◆ IsLimited()

static bool IsLimited ( )
static

Indicates whether the run-time is limited or unlimited.

Returns
true if limited, false if unlimited

◆ PLMNidentityToString()

static string [] PLMNidentityToString ( byte []  plmnIdentity)
static

Translates a PLMNidentity string (i.e., byte array) to ASCII strings for the MCC and the MNC. Refer to the description of PLMNidentity in StringToPLMNIdentity().

Parameters
plmnIdentityThe source PLMNidentity string (byte array)
Returns
Array of 2 strings where element 0 is the MCC and element 1 is the MNC.

◆ StringToBCD()

static byte [] StringToBCD ( System.String  str)
static

Translates an ASCII string to a BCD string. The ASCII string must contain only the following characters: [0..9A-Ea-e]. 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.

◆ StringToPLMNidentity()

static byte [] StringToPLMNidentity ( string  mcc,
string  mnc 
)
static

Translates ASCII Strings for MCC and MNC to a PLMNidentity. The PLMNidentity format is described in (for example) 3GPP TS 25.413. Each nibble represents a digit from 0 through 9 inclusive. The first 3 nibbles are the digits of the MCC. If the MNC is 2 digits long, the fourth nibble is a filler of 0xf. Otherwise, the fourth nibble is the first digit of the MNC. Then the remaining 2 nibbles are the remaining digits of the MNC.

An ASCII string of "123" for the MCC and "45" for the MNC would be encoded as 0x21F354.

Parameters
mccThe source ASCII string for the MCC.
mncThe source ASCII string for the MNC.
Returns
The PLMNidentity string as a byte array.

◆ StringToTBCD()

static byte [] StringToTBCD ( System.String  str)
static

Translates an ASCII string to a TBCD string. The TBCD encoding format is as described in 3GPP 29.002:

  • the characters used are [0-9*#abc].
  • each nibble represents a digit, and the upper nibble represents the digit which follows the digit represented in the lower nibble.
  • 0xF is used as filler in the final high nibble when the input string has and odd length. The string "12345" would be encoded 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().

◆ TbcdBinToChar()

static char TbcdBinToChar ( byte  tbcdDigit)
static

This function converts a TBCD binary character into its ASCII equivalent. /p>

Parameters
tbcdDigitTBCD digit
Returns
the converted character

◆ TbcdCharToBin()

static byte TbcdCharToBin ( char  digit)
static

This function converts a TBCD character ('0'-'9',"*#abc") into its binary equivalent. /p>

Parameters
digitTBCD digit character ('0'-'9',"*#abc")
Returns
binary representation of given char

◆ TBCDToString()

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

Translates a TBCD string to an ASCII string. Refer to the description of TBCD in stringToTBCD.

Parameters
bcdthe source TBCD string
Returns
the ASCII string.

References Asn1Util.URShift().

Referenced by Asn1TBCDString.ToString().

◆ 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().

◆ ToHexChar()

static char ToHexChar ( int  nibble)
static

Convert a value from 0x0 to 0xF to the corresponding hex char. Lowercase letters are used for the hex characters. /p>

◆ 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().