iaik.asn1.structures
Class ChoiceOfTime

java.lang.Object
  |
  +--iaik.asn1.structures.ChoiceOfTime

public class ChoiceOfTime
extends Object

This class represents the ASN.1 structure "ChoiceOfTime".

ChoiceOfTime ::= CHOICE { utcTime UTCTime, generalTime GeneralizedTime }

This class handles both possible rules to encode a date. The encoding format should depend on the following rule:

Till year 2050 the date shall be encoded as UTCTime. After 2050 the date shall be encoded as GeneralizedTime.


Per default the encoding scheme of this class is set to UTCTime meaning that per default the date value of a ChoiceOfTime object will be encoded as UTCTime. However, an application may call the setEncodingType method for enforcing a GeneralizedTime encoding, e.g.:

 ChoiceOfTime choiceOfTime = new ChoiceOfTime();
 choiceOfTime.setEncodingType(ASN.GeneralizedTime);
 
This class supplies four constructors for specifying the Date to be represented by a ChoiceOfTime object:

Version:
File Revision 21
See Also:
UTCTime, GeneralizedTime

Constructor Summary
ChoiceOfTime()
          Creates a new ChoiceOfTime from the current Date.
ChoiceOfTime(ASN1Object obj)
          Creates a new ChoiceOfTime from an ASN1Object.
ChoiceOfTime(Date date)
          Creates a new ChoiceOfTime from the given Date.
ChoiceOfTime(Date date, ASN encodingType)
          Creates a new ChoiceOfTime from the given Date using the specified encoding type.
ChoiceOfTime(Date date, boolean do2050Encoding)
          Creates a new ChoiceOfTime from the given Date.
ChoiceOfTime(String date, ASN encodingType)
          Creates a ChoiceOfTime for the given date, represented as string.
 
Method Summary
 Date getDate()
          Returns the date this ChoiceOfTime represents.
 ASN getEncodingType()
          Returns the encoding type, either UTCTime or GeneralizedTime.
 void setEncodingType(ASN encodingType)
          Sets the encoding type.
 ASN1Object toASN1Object()
          Returns the value of this object as an ASN1Object.
 String toString()
          Returns a string that represents the contents of the extensions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChoiceOfTime

public ChoiceOfTime()
Creates a new ChoiceOfTime from the current Date.

Per default the encoding scheme is set to UTCTime. Use the setEncodingType method for enforcing a GeneralizedTime encoding.


ChoiceOfTime

public ChoiceOfTime(Date date)
Creates a new ChoiceOfTime from the given Date.

Per default the encoding scheme is set to UTCTime. Use the setEncodingType method for enforcing a GeneralizedTime encoding.

Parameters:
date - the desired date

ChoiceOfTime

public ChoiceOfTime(Date date,
                    boolean do2050Encoding)
Creates a new ChoiceOfTime from the given Date.

Per default the encoding scheme is set to UTCTime. Use the setEncodingType method for enforcing a GeneralizedTime encoding.

If do2050Encoding is set to true automatically time values before 2050 are encoded as UTCTime and after 2050 as GeneralizedTime, e.g.:

 Date date = ...;
 ChoiceOfTime choiceOfTime = new ChoiceOfTime(date, true);
 
Parameters:
date - the desired date
do2050Encoding - whether to automatically switch to GeneralizedTime for dates beyound 2050

ChoiceOfTime

public ChoiceOfTime(Date date,
                    ASN encodingType)
Creates a new ChoiceOfTime from the given Date using the specified encoding type.
Parameters:
date - the desired date
encodingType - the encoding type, either UTCTime or GeneralizedTime
Throws:
IllegalArgumentException - if the supplied encoding type is not UTCTime or GeneralizedTime

ChoiceOfTime

public ChoiceOfTime(String date,
                    ASN encodingType)
             throws ParseException
Creates a ChoiceOfTime for the given date, represented as string. The string representation has to fulfill the format "yyyyMMDDHHmmss" (year MonthOfYear DayOfMonth HourOfDay minuteOfHour secondOfMinute) and an optional local time-shift against Coordinated Universal Time (UTC time), which may be indicated by a plus (+) or minus (-) sign, followed by hour and minute specifications, each of them owning two digits, e.g:
 String timeStr = "19991003121730+0230";
 ChoiceOfTime choiceOfTime = new ChoiceOfTime("19991003121730+0230",ASN.GeneralizedTime);
 
The second argument above enforces that the Date has to be encoded as GeneralizedTime instead of UTCTime.
Parameters:
date - the string containing the date
encodingType - the encoding type, either UTCTime or GeneralizedTime
Throws:
ParseException - if the format of the date is not correct
IllegalArgumentException - if the supplied encoding type is not UTCTime or GeneralizedTime

ChoiceOfTime

public ChoiceOfTime(ASN1Object obj)
             throws CodingException
Creates a new ChoiceOfTime from an ASN1Object. The supplied ASN1Object represents an already existing ChoiceOfTime that may have been created by means of the toASN1Object() method.
Parameters:
obj - the ChoiceOfTime as ASN1Object
Throws:
CodingException - if the ASN1Object could not be parsed
Method Detail

toASN1Object

public ASN1Object toASN1Object()
Returns the value of this object as an ASN1Object. The type of the ASN1Object returned by this method is either UTCTime or GeneralizedTime.
Returns:
the value of this object as an ASN1Object

getEncodingType

public ASN getEncodingType()
Returns the encoding type, either UTCTime or GeneralizedTime.
Returns:
the encoding type

setEncodingType

public void setEncodingType(ASN encodingType)
                     throws IllegalArgumentException
Sets the encoding type.

Please note that when you have created a ChoiceOfTime of type UTCTime and now change to GeneralizedTime, the millisecond value may be zero; so it might be perferable to set the encoding type right from the beginning when creating a ChoiceOfTime object.

Parameters:
encodingType - the encoding type
Throws:
IllegalArgumentException - if the supplied encoding type is not UTCTime or GeneralizedTime

getDate

public Date getDate()
Returns the date this ChoiceOfTime represents.
Returns:
the date

toString

public String toString()
Returns a string that represents the contents of the extensions.
Overrides:
toString in class Object
Returns:
the string representation

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK