Top Description Fields Constructors Methods
org.bouncycastle.asn1

public Class ASN1GeneralizedTime

extends ASN1Primitive
Class Inheritance
Known Direct Subclasses
org.bouncycastle.asn1.DERGeneralizedTime
Imports
java.io.IOException, java.text.ParseException, .SimpleDateFormat, java.util.Date, .Locale, .SimpleTimeZone, .TimeZone, org.bouncycastle.util.Arrays, .Strings

Base class representing the ASN.1 GeneralizedTime type.

The main difference between these and UTC time is a 4 digit year.

One second resolution date+time on UTC timezone (Z) with 4 digit year (valid from 0001 to 9999).

Timestamp format is: yyyymmddHHMMSS'Z'

X.690

This is what is called "restricted string", and it uses ASCII characters to encode digits and supplemental data.

11: Restrictions on BER employed by both CER and DER

11.7 GeneralizedTime

11.7.1 The encoding shall terminate with a "Z", as described in the ITU-T Rec. X.680 | ISO/IEC 8824-1 clause on GeneralizedTime.

11.7.2 The seconds element shall always be present.

11.7.3 The fractional-seconds elements, if present, shall omit all trailing zeros; if the elements correspond to 0, they shall be wholly omitted, and the decimal point element also shall be omitted.

Field Summary

Modifier and TypeField and Description
pack-priv final byte[]
pack-priv static final ASN1UniversalType

Constructor Summary

AccessConstructor and Description
public
ASN1GeneralizedTime(String
the time string.
time
)

The correct format for this is YYYYMMDDHHMMSS[.f]Z, or without the Z for local time, or Z+-HHMM on the end, for difference between local time and UTC time.

public
ASN1GeneralizedTime(Date
a date object representing the time of interest.
time
)

Base constructor from a java.util.date object

public
ASN1GeneralizedTime(Date
a date object representing the time of interest.
time
,
Locale
an appropriate Locale for producing an ASN.1 GeneralizedTime value.
locale
)

Base constructor from a java.util.date and Locale - you may need to use this if the default locale doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations.

pack-priv
ASN1GeneralizedTime(byte[] bytes)

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
asn1Equals(ASN1Primitive o)

Implements abstract org.bouncycastle.asn1.ASN1Primitive.asn1Equals.

Equality (similarity) comparison for two ASN1Primitive objects.

private SimpleDateFormat
private String
private String
convert(int time)

pack-priv static ASN1GeneralizedTime
createPrimitive(byte[] contents)

pack-priv void
encode(ASN1OutputStream out, boolean withTag)

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encode.

pack-priv final boolean
encodeConstructed()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encodeConstructed.

Return true if this objected is a CONSTRUCTED one, false otherwise.

pack-priv int
public Date
public static ASN1GeneralizedTime

Returns:

an ASN1GeneralizedTime instance, or null.
getInstance
(Object
an ASN1GeneralizedTime or an object that can be converted into one.
obj
)

return a generalized time from the passed in object

public static ASN1GeneralizedTime

Returns:

an ASN1GeneralizedTime instance.
getInstance
(ASN1TaggedObject
the tagged object holding the object we want
taggedObject
,
boolean
true if the object is meant to be explicitly tagged false otherwise.
explicit
)

return a Generalized Time object from a tagged object.

public String

Returns:

a String representation of the time.
getTime
()

return the time - always in the form of YYYYMMDDhhmmssGMT(+hh:mm|-hh:mm).

public String

Returns:

The time string as it appeared in the encoded object.
getTimeString
()

Return the time.

protected boolean
public int
hashCode()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.hashCode.

Returns a hash code value for this object.

protected boolean
protected boolean
private boolean
isDigit(int pos)

private String
pack-priv ASN1Primitive
toDERObject()

Overrides org.bouncycastle.asn1.ASN1Primitive.toDERObject.

Return the current object as one which encodes using Distinguished Encoding Rules.

Inherited from org.bouncycastle.asn1.ASN1Primitive:
encodeToencodeToequalsequalsequalsfromByteArraytoASN1PrimitivetoDLObject

Field Detail

contentsback to summary
pack-priv final byte[] contents
TYPEback to summary
pack-priv static final ASN1UniversalType TYPE

Constructor Detail

ASN1GeneralizedTimeback to summary
public ASN1GeneralizedTime(String time)

The correct format for this is YYYYMMDDHHMMSS[.f]Z, or without the Z for local time, or Z+-HHMM on the end, for difference between local time and UTC time. The fractional second amount f must consist of at least one number with trailing zeroes removed.

Parameters
time:String

the time string.

Exceptions
IllegalArgumentException:
if String is an illegal format.
ASN1GeneralizedTimeback to summary
public ASN1GeneralizedTime(Date time)

Base constructor from a java.util.date object

Parameters
time:Date

a date object representing the time of interest.

ASN1GeneralizedTimeback to summary
public ASN1GeneralizedTime(Date time, Locale locale)

Base constructor from a java.util.date and Locale - you may need to use this if the default locale doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations.

Parameters
time:Date

a date object representing the time of interest.

locale:Locale

an appropriate Locale for producing an ASN.1 GeneralizedTime value.

ASN1GeneralizedTimeback to summary
pack-priv ASN1GeneralizedTime(byte[] bytes)

Method Detail

asn1Equalsback to summary
pack-priv boolean asn1Equals(ASN1Primitive o)

Implements abstract org.bouncycastle.asn1.ASN1Primitive.asn1Equals.

Doc from org.bouncycastle.asn1.ASN1Primitive.asn1Equals.

Equality (similarity) comparison for two ASN1Primitive objects.

calculateGMTDateFormatback to summary
private SimpleDateFormat calculateGMTDateFormat()
calculateGMTOffsetback to summary
private String calculateGMTOffset(String stime)
convertback to summary
private String convert(int time)
createPrimitiveback to summary
pack-priv static ASN1GeneralizedTime createPrimitive(byte[] contents)
encodeback to summary
pack-priv void encode(ASN1OutputStream out, boolean withTag) throws IOException

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encode.

encodeConstructedback to summary
pack-priv final boolean encodeConstructed()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encodeConstructed.

Doc from org.bouncycastle.asn1.ASN1Primitive.encodeConstructed.

Return true if this objected is a CONSTRUCTED one, false otherwise.

Returns:boolean

true if CONSTRUCTED bit set on object's tag, false otherwise.

encodedLengthback to summary
pack-priv int encodedLength(boolean withTag)

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encodedLength.

getDateback to summary
public Date getDate() throws ParseException
getInstanceback to summary
public static ASN1GeneralizedTime getInstance(Object obj)

return a generalized time from the passed in object

Parameters
obj:Object

an ASN1GeneralizedTime or an object that can be converted into one.

Returns:ASN1GeneralizedTime

an ASN1GeneralizedTime instance, or null.

Exceptions
IllegalArgumentException:
if the object cannot be converted.
getInstanceback to summary
public static ASN1GeneralizedTime getInstance(ASN1TaggedObject taggedObject, boolean explicit)

return a Generalized Time object from a tagged object.

Parameters
taggedObject:ASN1TaggedObject

the tagged object holding the object we want

explicit:boolean

true if the object is meant to be explicitly tagged false otherwise.

Returns:ASN1GeneralizedTime

an ASN1GeneralizedTime instance.

Exceptions
IllegalArgumentException:
if the tagged object cannot be converted.
getTimeback to summary
public String getTime()

return the time - always in the form of YYYYMMDDhhmmssGMT(+hh:mm|-hh:mm).

Normally in a certificate we would expect "Z" rather than "GMT", however adding the "GMT" means we can just use:

    dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
To read in the time and get a date which is compatible with our local time zone.
Returns:String

a String representation of the time.

getTimeStringback to summary
public String getTimeString()

Return the time.

Returns:String

The time string as it appeared in the encoded object.

hasFractionalSecondsback to summary
protected boolean hasFractionalSeconds()
hashCodeback to summary
public int hashCode()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

hasMinutesback to summary
protected boolean hasMinutes()
hasSecondsback to summary
protected boolean hasSeconds()
isDigitback to summary
private boolean isDigit(int pos)
pruneFractionalSecondsback to summary
private String pruneFractionalSeconds(String origTime)
toDERObjectback to summary
pack-priv ASN1Primitive toDERObject()

Overrides org.bouncycastle.asn1.ASN1Primitive.toDERObject.

Doc from org.bouncycastle.asn1.ASN1Primitive.toDERObject.

Return the current object as one which encodes using Distinguished Encoding Rules.

Returns:ASN1Primitive

a DER version of this.