AXL RADIUS Server API V3

com.theorem.radserver3.radutil
Class Util

Object
  extended byUtil

public class Util
extends Object

RADIUS utilities class.


Constructor Summary
Util()
           
 
Method Summary
static boolean cmp(byte[] a, byte[] b)
          Compare two byte arrays.
static boolean cmp(byte[] a, int startA, byte[] b, int startB, int length)
          Compare two byte arrays over a region.
static String dump(byte[] buf, int start, int length)
          Display a block of bytes sixteen bytes per row.
static String dumpStack(Throwable t)
          Return the stack trace as a string.
static byte[] hexToArray(String hexString)
          Return an array of bytes from a hex string.
static String[] splitUserName(String name, char prefix, char realm)
          Split the User-Name into prefix, name, and realm.
static String toASCII(byte[] b)
          Convert a byte array to a string using ASCII encoding.
static byte[] toASCII(String s)
          Convert a string to bytes encoded using ASCII, the TACACS+ protocol standard encoding.
static String toHexString(byte[] buf)
          Convert a byte buffer to a hex string.
static String toHexString(byte[] buf, int start, int length)
          Convert a byte buffer to a hex string.
static String toUTF8(byte[] b)
          Convert a byte array to a string using UTF8 encoding.
static byte[] toUTF8(char[] c)
          Convert a char array to a UTF8 byte array.
static byte[] toUTF8(String s)
          Convert a string to bytes encoded using UTF8, the RADIUS protocol standard encoding.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

cmp

public static boolean cmp(byte[] a,
                          byte[] b)
Compare two byte arrays.

Parameters:
a - array a
b - array b
Returns:
true if they're the same.

cmp

public static boolean cmp(byte[] a,
                          int startA,
                          byte[] b,
                          int startB,
                          int length)
Compare two byte arrays over a region.

Parameters:
a - Array A.
startA - The start position for comparing A.
b - Array B.
startB - The start position for comparing B.
length - Length of region.
Returns:
true if the comparison succeeded.

dump

public static String dump(byte[] buf,
                          int start,
                          int length)
Display a block of bytes sixteen bytes per row.

Parameters:
buf - Buffer to display.
start - Start position in buffer.
length - Length of data to dump.
Returns:
String representing the buffer.
Since:
3.41 (Axl Server)

dumpStack

public static String dumpStack(Throwable t)
Return the stack trace as a string.

Parameters:
t - Exception to trace.
Since:
3.36

hexToArray

public static byte[] hexToArray(String hexString)
                         throws IllegalArgumentException
Return an array of bytes from a hex string.

Parameters:
hexString - Hex string to convert.
Returns:
Byte array.
Throws:
IllegalArgumentException - if there's a problem parsing the hex string.

splitUserName

public static String[] splitUserName(String name,
                                     char prefix,
                                     char realm)
Split the User-Name into prefix, name, and realm. Multiple consecutive prefix characters will be stripped.

For example 'prefix/name@realm' would be returned as ["prefix"] ["name"] ["realm"] as would 'prefix//name@realm'. 'name@realm' would be returned as [""] ["name"] ["realm"].

Parameters:
name - User-Name value.
prefix - Prefix character. If this character is sequentially repeated (like 'prefix//name') all the prefix characters will be stripped.
realm - realm character. This is usually a '@'.
Returns:
Array of three strings containing the prefix, name, and realm respectively. Any values not present are set to empty strings.

toASCII

public static String toASCII(byte[] b)
Convert a byte array to a string using ASCII encoding. This should not be used for conversion of RADIUS strings. Please use toUTF8().

In the event that US-ASCII is unavailable (highly unlikely) the encoding will be the platform's default encoding.

Parameters:
b - Byte array to convert.
Returns:
String.

toASCII

public static byte[] toASCII(String s)
Convert a string to bytes encoded using ASCII, the TACACS+ protocol standard encoding. This should not be used for conversion of RADIUS strings. Please use toUTF8().

In the event that US-ASCII is unavailable (highly unlikely) the encoding will be the platform's default encoding.

Parameters:
s - String to convert to a ASCII byte array.
Returns:
ASCII byte array.

toHexString

public static String toHexString(byte[] buf)
Convert a byte buffer to a hex string.

Parameters:
buf - Byte array.
Returns:
Hexadecimal representation.

toHexString

public static String toHexString(byte[] buf,
                                 int start,
                                 int length)
Convert a byte buffer to a hex string.

Parameters:
buf - Byte array.
start - Start position in array.
length - Number of bytes to display.
Returns:
Hexadecimal representation.

toUTF8

public static String toUTF8(byte[] b)
Convert a byte array to a string using UTF8 encoding.

In the event that UTF8 is unavailable (highly unlikely) the encoding will be US-ASCII.

Parameters:
b - Byte array to convert.
Returns:
String.

toUTF8

public static byte[] toUTF8(char[] c)
Convert a char array to a UTF8 byte array.

In the event that UTF8 is unavailable (highly unlikely) the encoding will be US-ASCII.

Parameters:
c - Char array to convert.
Returns:
the UTF8 byte array.

toUTF8

public static byte[] toUTF8(String s)
Convert a string to bytes encoded using UTF8, the RADIUS protocol standard encoding.

In the event that UTF8 is unavailable (highly unlikely) the encoding will be US-ASCII.

Parameters:
s - String to convert to a UTF8 byte array.
Returns:
UTF8 byte array.

AXL RADIUS Server API V3

Submit a bug report or feature request

Copyright 1998-2008 AXL Software. PO Box 97, Viola, Delaware 19979, U.S.A. All Rights Reserved.