org.jasn
Class StringUtilities

java.lang.Object
  extended byorg.jasn.StringUtilities

public class StringUtilities
extends Object

Methods in this class are used to determine whether characters may appear in certain ASN.1 String type.

Author:
Nicolas Vraux

Method Summary
static int formatGeneralizedTime(byte[] buf, int off, int len, Calendar date)
           
static int formatUTCTime(byte[] buf, int off, int len, Calendar date)
           
static boolean isDigit(char c)
          Determines if the specified character is an ISO-Latin-1 digit ('0' through '9').
static boolean isIA5(char c)
          Tests wether the specified character is a valid IA5String character.
static boolean isIA5(String text)
          Tests wether the specified string contains only valid ASN.1 PrintableString characters.
static boolean isNumeric(char c)
          Tests wether the specified character is a valid ASN.1 NumericString character.
static boolean isPrintable(char c)
          Tests wether the specified character is a valid ASN.1 PrintableString character.
static boolean isPrintable(String text)
          Tests wether the specified string contains only valid ASN.1 PrintableString characters.
static boolean isVisible(char c)
          Tests wether the specified character is a valid VisibleString character.
static String normalize(String s)
          Returns a new string derived from the specified one after having removed leading and trailing white space and converted internal substrings of one or more consecutive white space characters to a single space.
static int parse2Digits(char[] s, int off, int len, int min, int max)
           
static int parse4Digits(char[] s, int off, int len, int min, int max)
           
static int parseDigit(char c)
          Returns the numeric value of the specified character in the decimal radix.
static Calendar parseGeneralizedTime(char[] s, int off, int len)
          Decodes an ASN.1 GeneralizedTime value from the sequence of len characters starting at off in s.
static Calendar parseUTCTime(char[] s, int off, int len)
          Decodes an ASN.1 UTCTime value from the sequence of len characters starting at off in s.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isNumeric

public static boolean isNumeric(char c)
Tests wether the specified character is a valid ASN.1 NumericString character.

Parameters:
c - the character to be checked.
Returns:
true if the specified character is a valid NumericString character; false otherwise.

isPrintable

public static boolean isPrintable(char c)
Tests wether the specified character is a valid ASN.1 PrintableString character.

Parameters:
c - the character to be checked.
Returns:
true if the specified character is a valid PrintableString character; false otherwise.

isPrintable

public static boolean isPrintable(String text)
Tests wether the specified string contains only valid ASN.1 PrintableString characters.

Parameters:
text - the string to be checked.
Returns:
true if the specified string is a valid PrintableString; false otherwise.

isVisible

public static boolean isVisible(char c)
Tests wether the specified character is a valid VisibleString character.

Parameters:
c - the character to be checked.
Returns:
true if the specified character is a valid VisibleString character; false otherwise.

isIA5

public static boolean isIA5(char c)
Tests wether the specified character is a valid IA5String character.

Parameters:
c - the character to be checked.
Returns:
true if the specified character is a valid IA5String character; false otherwise.

isIA5

public static boolean isIA5(String text)
Tests wether the specified string contains only valid ASN.1 PrintableString characters.

Parameters:
text - the string to be checked.
Returns:
true if the specified string is a valid PrintableString; false otherwise.

normalize

public static String normalize(String s)
Returns a new string derived from the specified one after having removed leading and trailing white space and converted internal substrings of one or more consecutive white space characters to a single space.

Parameters:
s - the string to be normalized.
Returns:
the normalized string.

parseUTCTime

public static Calendar parseUTCTime(char[] s,
                                    int off,
                                    int len)
                             throws ParseException
Decodes an ASN.1 UTCTime value from the sequence of len characters starting at off in s.

If s is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array s, then an IndexOutOfBoundsException is thrown.

Parameters:
s - the array of characters to be parsed.
off - the offset in the array from which the characters are parsed.
len - the number of characters to be parsed.
Returns:
a Calendar instance describing the parsed UTCTime.
Throws:
ParseException

parseGeneralizedTime

public static Calendar parseGeneralizedTime(char[] s,
                                            int off,
                                            int len)
                                     throws ParseException
Decodes an ASN.1 GeneralizedTime value from the sequence of len characters starting at off in s.

If s is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array s, then an IndexOutOfBoundsException is thrown.

Parameters:
s - the array of characters to be parsed.
off - the offset in the array from which the characters are parsed.
len - the number of characters to be parsed.
Returns:
a Calendar instance describing the parsed time.
Throws:
ParseException

formatUTCTime

public static int formatUTCTime(byte[] buf,
                                int off,
                                int len,
                                Calendar date)

formatGeneralizedTime

public static int formatGeneralizedTime(byte[] buf,
                                        int off,
                                        int len,
                                        Calendar date)

parse2Digits

public static int parse2Digits(char[] s,
                               int off,
                               int len,
                               int min,
                               int max)
                        throws ParseException
Throws:
ParseException

parse4Digits

public static int parse4Digits(char[] s,
                               int off,
                               int len,
                               int min,
                               int max)
                        throws ParseException
Throws:
ParseException

parseDigit

public static int parseDigit(char c)
                      throws ParseException
Returns the numeric value of the specified character in the decimal radix.

Parameters:
c - the character to be converted.
Returns:
the numeric value of the specified character in the decimal radix.
Throws:
ParseException - if the character is not a decimal digit.

isDigit

public static boolean isDigit(char c)
Determines if the specified character is an ISO-Latin-1 digit ('0' through '9').

Parameters:
c - the character to be tested.
Returns:
true if the character is a digit; false otherwise.


Copyright © 2004 Nicolas Vraux. All Rights Reserved.