issrg.ac
Class Util

java.lang.Object
  extended by issrg.ac.Util

public class Util
extends java.lang.Object

This class contains various utility routines for converting things from one representation into another.

Version:
1.0
Author:
A Otenko

Field Summary
static java.lang.String DATE_SEPARATOR
          This is the separator between the dates.
static java.lang.String SN_ATTRIBUTE_TYPE
          This variable sets the attribute type for the serial number in the DN, when constructing it for the IssuerSerial case.
static java.lang.String SN_NAME_SEPARATOR
          This is the separator between the serial number and the DN of the Issuer.
static java.lang.String TIME_SEPARATOR
          This is the separator between the times.
 
Constructor Summary
Util()
           
 
Method Summary
static Generalized_Time buildGeneralizedTime(java.lang.String date)
          Builds a date out of a string representation of it in date.
static iaik.asn1.structures.GeneralNames buildGeneralNames(java.lang.String DN)
          This method builds a General Names construct out of the string representation of an LDAP DN that should be RFC2253 compliant.
static IssuerSerial buildIssuerSerial(java.lang.String what)
           
static java.lang.String generalNamesToString(iaik.asn1.structures.GeneralNames gns)
          Converts the given general Name in iaik representation into a String.
static byte[] hashDN(java.lang.String name)
          This method converts the given string to a canonical DN, then calculates its hash using hashString.
static byte[] hashName(GeneralNames gn)
          This is a utility method that returns the hash of the DN contained in the GeneralNames.
static byte[] hashString(java.lang.String s)
          Returns MD5 hash of the given string.
static java.lang.String hashToString(byte[] hash)
          This method converts the hash byte array to string.
static java.lang.String issuerSerialToDN(java.lang.String issuerDN, java.math.BigInteger serialNumber)
          This is the universal way for constructing the LDAP DN for the entry, whose name is constructed out of the PKC Issuer DN and PKC SN.
static java.lang.String issuerToString(AttCertIssuer aci)
          Returns the string representation of the Issuer General Name, if V1Form or IssuerName of the V2Form is present.
static java.lang.String timeToString(java.util.Calendar date)
          Converts the given date into internal format "ccyy.mm.dd hh:mm:ss".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SN_ATTRIBUTE_TYPE

public static final java.lang.String SN_ATTRIBUTE_TYPE
This variable sets the attribute type for the serial number in the DN, when constructing it for the IssuerSerial case.

See Also:
Constant Field Values

TIME_SEPARATOR

public static java.lang.String TIME_SEPARATOR
This is the separator between the times. You can change it at runtime


SN_NAME_SEPARATOR

public static java.lang.String SN_NAME_SEPARATOR
This is the separator between the serial number and the DN of the Issuer. You can change it at runtime


DATE_SEPARATOR

public static java.lang.String DATE_SEPARATOR
This is the separator between the dates. You can change it at runtime

Constructor Detail

Util

public Util()
Method Detail

generalNamesToString

public static java.lang.String generalNamesToString(iaik.asn1.structures.GeneralNames gns)
Converts the given general Name in iaik representation into a String.

Parameters:
gns - the GeneralNames construct to convert; must be an X.500 directory name.
Returns:
the string representation of a General Name in reverse order; for example, "cn=Sassa, ou=ISI, o=Salford University, c=GB"

issuerSerialToDN

public static java.lang.String issuerSerialToDN(java.lang.String issuerDN,
                                                java.math.BigInteger serialNumber)
This is the universal way for constructing the LDAP DN for the entry, whose name is constructed out of the PKC Issuer DN and PKC SN.

Parameters:
issuerDN - - the DN of the issuer
serialNumber - - the serial number of the PKC issued by that issuer
Returns:
the DN combining the serial number and the issuer DN

issuerToString

public static java.lang.String issuerToString(AttCertIssuer aci)
Returns the string representation of the Issuer General Name, if V1Form or IssuerName of the V2Form is present. Otherwise, returns null.

Parameters:
aci - - the AttCertIssuer structure
Returns:
String of the Issuer GeneralName, or null, if the name is not present in the given AttCertIssuer structure.

buildGeneralNames

public static iaik.asn1.structures.GeneralNames buildGeneralNames(java.lang.String DN)
This method builds a General Names construct out of the string representation of an LDAP DN that should be RFC2253 compliant. Note that the attribute names are case insensitive, even though RFC2253 specifies otherwise.

Parameters:
DN - is the String with LDAP DN; if a parse error occures, a GeneralNames corresponding to the null DN will be constructed
Returns:
a GeneralNames construct; is never null

hashToString

public static java.lang.String hashToString(byte[] hash)
This method converts the hash byte array to string. Use this method, if you are looking for filenames, so the filenames are created in a uniform fashion.

Parameters:
hash - - the byte array of the hash
Returns:
the String of the hash in hexadecimal form

hashString

public static byte[] hashString(java.lang.String s)
Returns MD5 hash of the given string. Returns null, if the string is null.

Parameters:
s - - the string of which the hash has to be calculated.
Returns:
the MD5 hash, or null, if the string is null, or MD5 provider was not found

hashDN

public static byte[] hashDN(java.lang.String name)
This method converts the given string to a canonical DN, then calculates its hash using hashString. If the string is not a canonical DN, null will be hashed (see hashString).

Parameters:
name - - the DN to canonicalise and hash
Returns:
the MD5 hash of the canonical RFC2253 DN

hashName

public static byte[] hashName(GeneralNames gn)
This is a utility method that returns the hash of the DN contained in the GeneralNames.

Parameters:
gn - - the GeneralNames of which the directoryName will be converted to a canonical RFC2253-compliant LDAP distinguished name and then hashed

buildGeneralizedTime

public static Generalized_Time buildGeneralizedTime(java.lang.String date)
                                             throws ACCreationException
Builds a date out of a string representation of it in date.

Parameters:
date - the string representation of the date in form "yyyy.mm.dd hh:mm:ss". The separators between numbers are defined by DATE_SEPARATOR and TIME_SEPARATOR respectively, the space between date and time is not redefinable. The lengths of numbers and ranges of their values are not checked (unless Generalized_Time or GregorianCalendar constructor does. More specific time values can be omitted. That is, "yyyy" is a valid value, and "yyyy.mm", and "yyyy.mm.dd hh", etc; but "yyyy.mm hh" is not: day must be specified first.
Returns:
returns Generalized_Time object, which contains the date.
Throws:
ACCreationException - if the string representation does not comply with the rules specified above.

timeToString

public static java.lang.String timeToString(java.util.Calendar date)
Converts the given date into internal format "ccyy.mm.dd hh:mm:ss". Actual date and time separators are taken from the corresponding constants DATE_SEPARATOR and TIME_SEPARATOR.

Parameters:
date - the date to convert.
Returns:
returns the string representation of the date in format "ccyy.mm.dd hh:mm:ss"

buildIssuerSerial

public static IssuerSerial buildIssuerSerial(java.lang.String what)
                                      throws ACCreationException
Throws:
ACCreationException