public class ChoiceOfTime
extends java.lang.Object
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:
constructor
creates a
ChoiceOfTime
object for the current date:
ChoiceOfTime choiceOfTime = new ChoiceOfTime();
constructor
that expects the Date
specification as java.util.Date instance, e.g.:
Date date = ...; ChoiceOfTime choiceOfTime = new ChoiceOfTime(date);
constructor
that contains a
boolean parameter do2050Encoding
that can be set to
automatically encode time values before 2050 as UTCTime and after 2050 as
GeneralizedTime , e.g.:
Date date = ...; ChoiceOfTime choiceOfTime = new ChoiceOfTime(date, true);
constructor
where the Date may be
supplied as string representation of 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.
UTCTime
,
GeneralizedTime
Constructor and Description |
---|
ChoiceOfTime()
Creates a new ChoiceOfTime from the current Date.
|
ChoiceOfTime(ASN1Object obj)
Creates a new ChoiceOfTime from an ASN1Object.
|
ChoiceOfTime(java.util.Date date)
Creates a new ChoiceOfTime from the given Date.
|
ChoiceOfTime(java.util.Date date,
ASN encodingType)
Creates a new ChoiceOfTime from the given Date using the specified encoding
type.
|
ChoiceOfTime(java.util.Date date,
ASN encodingType,
boolean includeMilliSeconds)
Creates a new ChoiceOfTime from the given Date using the specified encoding
type.
|
ChoiceOfTime(java.util.Date date,
boolean do2050Encoding)
Creates a new ChoiceOfTime from the given Date.
|
ChoiceOfTime(java.util.Date date,
boolean do2050Encoding,
boolean includeMilliSeconds)
Creates a new ChoiceOfTime from the given Date.
|
ChoiceOfTime(java.lang.String date,
ASN encodingType)
Creates a ChoiceOfTime for the given date, represented as string.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj)
Compares this ChoiceOfTime with the given object.
|
java.util.Date |
getDate()
Returns the date this ChoiceOfTime represents.
|
ASN |
getEncodingType()
Returns the encoding type, either UTCTime or GeneralizedTime.
|
int |
hashCode()
Returns a hash code for this object.
|
void |
setEncodingType(ASN encodingType)
Sets the encoding type.
|
ASN1Object |
toASN1Object()
Returns the value of this object as an ASN1Object.
|
java.lang.String |
toString()
Returns a string that represents the contents of the extensions.
|
public ChoiceOfTime()
Per default the encoding scheme is set to UTCTime. Use the
setEncodingType
method for enforcing a
GeneralizedTime encoding.
public ChoiceOfTime(java.util.Date date)
Per default the encoding scheme is set to UTCTime. Use the
ChoiceOfTime(date, encodingType)
constructor for enforcing a GeneralizedTime encoding.
date
- the desired datepublic ChoiceOfTime(java.util.Date date, boolean do2050Encoding)
Per default the encoding scheme is set to UTCTime.
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);Milliseconds are included in GeneralizedTime encodings.
date
- the desired datedo2050Encoding
- whether to automatically switch to GeneralizedTime for dates
beyound 2050public ChoiceOfTime(java.util.Date date, boolean do2050Encoding, boolean includeMilliSeconds)
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);
date
- the desired datedo2050Encoding
- whether to automatically switch to GeneralizedTime for dates
beyound 2050includeMilliSeconds
- whether to include milliseconds in GeneralizedTime
encoding. Some profiles, e.g. PKIX, may require
to not include fractional seconds if GeneralizedTime
is used). Default is true
(milliseconds
are included). If set false
milliseconds
are stripped.public ChoiceOfTime(java.util.Date date, ASN encodingType)
date
- the desired dateencodingType
- the encoding type, either UTCTime or GeneralizedTimejava.lang.IllegalArgumentException
- if the supplied encoding type is not UTCTime or
GeneralizedTimepublic ChoiceOfTime(java.util.Date date, ASN encodingType, boolean includeMilliSeconds)
date
- the desired dateencodingType
- the encoding type, either UTCTime or GeneralizedTimeincludeMilliSeconds
- whether to include milliseconds in GeneralizedTime
encoding. Some profiles, e.g. PKIX, may require
to not include fractional seconds if GeneralizedTime
is used). Default is true
(milliseconds
are included). If set false
milliseconds
are stripped.java.lang.IllegalArgumentException
- if the supplied encoding type is not UTCTime or
GeneralizedTimepublic ChoiceOfTime(java.lang.String date, ASN encodingType) throws java.text.ParseException
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.
date
- the string containing the dateencodingType
- the encoding type, either UTCTime or GeneralizedTimejava.text.ParseException
- if the format of the date is not correctjava.lang.IllegalArgumentException
- if the supplied encoding type is not UTCTime or
GeneralizedTimepublic ChoiceOfTime(ASN1Object obj) throws CodingException
toASN1Object()
method.obj
- the ChoiceOfTime as ASN1ObjectCodingException
- if the ASN1Object could not be parsedpublic ASN1Object toASN1Object()
public ASN getEncodingType()
public void setEncodingType(ASN encodingType) throws java.lang.IllegalArgumentException
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.
encodingType
- the encoding typejava.lang.IllegalArgumentException
- if the supplied encoding type is not UTCTime or
GeneralizedTimepublic java.util.Date getDate()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the object to compare withtrue
if the two objects are equal (represent the
same ASN.1 time type and the same time value, false
if they are not equalpublic java.lang.String toString()
toString
in class java.lang.Object