Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2014-03-22 05:13:55 +0400
committerDavid Hook <dgh@cryptoworkshop.com>2014-03-22 05:13:55 +0400
commite3920e43ad2ac78310809ed41426715b9a770ff7 (patch)
treec8009b6097e6bb7464dcdac45ebacb91d0e12db2 /core/src/main/java/org/bouncycastle
parentd59ed2205fede2c7ef5a5ff69021ea8f5cd21bf6 (diff)
refactoring UTCTime, GeneralizedTime
Diffstat (limited to 'core/src/main/java/org/bouncycastle')
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/ASN1GeneralizedTime.java350
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/ASN1UTCTime.java262
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/DERGeneralizedTime.java340
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/DERUTCTime.java269
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/cmp/PKIHeader.java8
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/cmp/PKIHeaderBuilder.java11
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/cms/RecipientKeyIdentifier.java16
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/cms/Time.java26
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/ocsp/CrlID.java3
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/ocsp/ResponseData.java3
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/ocsp/SingleResponse.java23
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/util/ASN1Dump.java12
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/x509/PrivateKeyUsagePeriod.java12
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/x509/TBSCertList.java8
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/x509/Time.java26
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/x509/V3TBSCertificateGenerator.java6
16 files changed, 671 insertions, 704 deletions
diff --git a/core/src/main/java/org/bouncycastle/asn1/ASN1GeneralizedTime.java b/core/src/main/java/org/bouncycastle/asn1/ASN1GeneralizedTime.java
index 0088a536..d38aa1c0 100644
--- a/core/src/main/java/org/bouncycastle/asn1/ASN1GeneralizedTime.java
+++ b/core/src/main/java/org/bouncycastle/asn1/ASN1GeneralizedTime.java
@@ -1,22 +1,342 @@
package org.bouncycastle.asn1;
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.SimpleTimeZone;
+import java.util.TimeZone;
+
+import org.bouncycastle.util.Arrays;
+import org.bouncycastle.util.Strings;
public class ASN1GeneralizedTime
- extends DERGeneralizedTime
+ extends ASN1Primitive
{
- ASN1GeneralizedTime(byte[] bytes)
- {
- super(bytes);
- }
-
- public ASN1GeneralizedTime(Date time)
- {
- super(time);
- }
-
- public ASN1GeneralizedTime(String time)
- {
- super(time);
- }
+ private byte[] time;
+
+ /**
+ * return a generalized time from the passed in object
+ *
+ * @exception IllegalArgumentException if the object cannot be converted.
+ */
+ public static ASN1GeneralizedTime getInstance(
+ Object obj)
+ {
+ if (obj == null || obj instanceof ASN1GeneralizedTime)
+ {
+ return (ASN1GeneralizedTime)obj;
+ }
+
+ if (obj instanceof byte[])
+ {
+ try
+ {
+ return (ASN1GeneralizedTime)fromByteArray((byte[])obj);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("encoding error in getInstance: " + e.toString());
+ }
+ }
+
+ throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+ }
+
+ /**
+ * return a Generalized Time object from a tagged object.
+ *
+ * @param obj the tagged object holding the object we want
+ * @param explicit true if the object is meant to be explicitly
+ * tagged false otherwise.
+ * @exception IllegalArgumentException if the tagged object cannot
+ * be converted.
+ */
+ public static ASN1GeneralizedTime getInstance(
+ ASN1TaggedObject obj,
+ boolean explicit)
+ {
+ ASN1Primitive o = obj.getObject();
+
+ if (explicit || o instanceof ASN1GeneralizedTime)
+ {
+ return getInstance(o);
+ }
+ else
+ {
+ return new ASN1GeneralizedTime(((ASN1OctetString)o).getOctets());
+ }
+ }
+
+ /**
+ * 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.
+ *
+ * @param time the time string.
+ * @exception IllegalArgumentException if String is an illegal format.
+ */
+ public ASN1GeneralizedTime(
+ String time)
+ {
+ this.time = Strings.toByteArray(time);
+ try
+ {
+ this.getDate();
+ }
+ catch (ParseException e)
+ {
+ throw new IllegalArgumentException("invalid date string: " + e.getMessage());
+ }
+ }
+
+ /**
+ * base constructor from a java.util.date object
+ */
+ public ASN1GeneralizedTime(
+ Date time)
+ {
+ SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
+
+ dateF.setTimeZone(new SimpleTimeZone(0,"Z"));
+
+ this.time = Strings.toByteArray(dateF.format(time));
+ }
+
+ ASN1GeneralizedTime(
+ byte[] bytes)
+ {
+ this.time = bytes;
+ }
+
+ /**
+ * Return the time.
+ * @return The time string as it appeared in the encoded object.
+ */
+ public String getTimeString()
+ {
+ return Strings.fromByteArray(time);
+ }
+
+ /**
+ * return the time - always in the form of
+ * YYYYMMDDhhmmssGMT(+hh:mm|-hh:mm).
+ * <p>
+ * Normally in a certificate we would expect "Z" rather than "GMT",
+ * however adding the "GMT" means we can just use:
+ * <pre>
+ * dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
+ * </pre>
+ * To read in the time and get a date which is compatible with our local
+ * time zone.
+ */
+ public String getTime()
+ {
+ String stime = Strings.fromByteArray(time);
+
+ //
+ // standardise the format.
+ //
+ if (stime.charAt(stime.length() - 1) == 'Z')
+ {
+ return stime.substring(0, stime.length() - 1) + "GMT+00:00";
+ }
+ else
+ {
+ int signPos = stime.length() - 5;
+ char sign = stime.charAt(signPos);
+ if (sign == '-' || sign == '+')
+ {
+ return stime.substring(0, signPos)
+ + "GMT"
+ + stime.substring(signPos, signPos + 3)
+ + ":"
+ + stime.substring(signPos + 3);
+ }
+ else
+ {
+ signPos = stime.length() - 3;
+ sign = stime.charAt(signPos);
+ if (sign == '-' || sign == '+')
+ {
+ return stime.substring(0, signPos)
+ + "GMT"
+ + stime.substring(signPos)
+ + ":00";
+ }
+ }
+ }
+ return stime + calculateGMTOffset();
+ }
+
+ private String calculateGMTOffset()
+ {
+ String sign = "+";
+ TimeZone timeZone = TimeZone.getDefault();
+ int offset = timeZone.getRawOffset();
+ if (offset < 0)
+ {
+ sign = "-";
+ offset = -offset;
+ }
+ int hours = offset / (60 * 60 * 1000);
+ int minutes = (offset - (hours * 60 * 60 * 1000)) / (60 * 1000);
+
+ try
+ {
+ if (timeZone.useDaylightTime() && timeZone.inDaylightTime(this.getDate()))
+ {
+ hours += sign.equals("+") ? 1 : -1;
+ }
+ }
+ catch (ParseException e)
+ {
+ // we'll do our best and ignore daylight savings
+ }
+
+ return "GMT" + sign + convert(hours) + ":" + convert(minutes);
+ }
+
+ private String convert(int time)
+ {
+ if (time < 10)
+ {
+ return "0" + time;
+ }
+
+ return Integer.toString(time);
+ }
+
+ public Date getDate()
+ throws ParseException
+ {
+ SimpleDateFormat dateF;
+ String stime = Strings.fromByteArray(time);
+ String d = stime;
+
+ if (stime.endsWith("Z"))
+ {
+ if (hasFractionalSeconds())
+ {
+ dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'");
+ }
+ else
+ {
+ dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
+ }
+
+ dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
+ }
+ else if (stime.indexOf('-') > 0 || stime.indexOf('+') > 0)
+ {
+ d = this.getTime();
+ if (hasFractionalSeconds())
+ {
+ dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSSz");
+ }
+ else
+ {
+ dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
+ }
+
+ dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
+ }
+ else
+ {
+ if (hasFractionalSeconds())
+ {
+ dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
+ }
+ else
+ {
+ dateF = new SimpleDateFormat("yyyyMMddHHmmss");
+ }
+
+ dateF.setTimeZone(new SimpleTimeZone(0, TimeZone.getDefault().getID()));
+ }
+
+ if (hasFractionalSeconds())
+ {
+ // java misinterprets extra digits as being milliseconds...
+ String frac = d.substring(14);
+ int index;
+ for (index = 1; index < frac.length(); index++)
+ {
+ char ch = frac.charAt(index);
+ if (!('0' <= ch && ch <= '9'))
+ {
+ break;
+ }
+ }
+
+ if (index - 1 > 3)
+ {
+ frac = frac.substring(0, 4) + frac.substring(index);
+ d = d.substring(0, 14) + frac;
+ }
+ else if (index - 1 == 1)
+ {
+ frac = frac.substring(0, index) + "00" + frac.substring(index);
+ d = d.substring(0, 14) + frac;
+ }
+ else if (index - 1 == 2)
+ {
+ frac = frac.substring(0, index) + "0" + frac.substring(index);
+ d = d.substring(0, 14) + frac;
+ }
+ }
+
+ return dateF.parse(d);
+ }
+
+ private boolean hasFractionalSeconds()
+ {
+ for (int i = 0; i != time.length; i++)
+ {
+ if (time[i] == '.')
+ {
+ if (i == 14)
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ boolean isConstructed()
+ {
+ return false;
+ }
+
+ int encodedLength()
+ {
+ int length = time.length;
+
+ return 1 + StreamUtil.calculateBodyLength(length) + length;
+ }
+
+ void encode(
+ ASN1OutputStream out)
+ throws IOException
+ {
+ out.writeEncoded(BERTags.GENERALIZED_TIME, time);
+ }
+
+ boolean asn1Equals(
+ ASN1Primitive o)
+ {
+ if (!(o instanceof ASN1GeneralizedTime))
+ {
+ return false;
+ }
+
+ return Arrays.areEqual(time, ((ASN1GeneralizedTime)o).time);
+ }
+
+ public int hashCode()
+ {
+ return Arrays.hashCode(time);
+ }
}
diff --git a/core/src/main/java/org/bouncycastle/asn1/ASN1UTCTime.java b/core/src/main/java/org/bouncycastle/asn1/ASN1UTCTime.java
index d3816f22..fc7ff636 100644
--- a/core/src/main/java/org/bouncycastle/asn1/ASN1UTCTime.java
+++ b/core/src/main/java/org/bouncycastle/asn1/ASN1UTCTime.java
@@ -1,22 +1,270 @@
package org.bouncycastle.asn1;
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.SimpleTimeZone;
+
+import org.bouncycastle.util.Arrays;
+import org.bouncycastle.util.Strings;
public class ASN1UTCTime
- extends DERUTCTime
+ extends ASN1Primitive
{
- ASN1UTCTime(byte[] bytes)
+ private byte[] time;
+
+ /**
+ * return an UTC Time from the passed in object.
+ *
+ * @exception IllegalArgumentException if the object cannot be converted.
+ */
+ public static ASN1UTCTime getInstance(
+ Object obj)
+ {
+ if (obj == null || obj instanceof ASN1UTCTime)
+ {
+ return (ASN1UTCTime)obj;
+ }
+
+ if (obj instanceof byte[])
+ {
+ try
+ {
+ return (ASN1UTCTime)fromByteArray((byte[])obj);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("encoding error in getInstance: " + e.toString());
+ }
+ }
+
+ throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+ }
+
+ /**
+ * return an UTC Time from a tagged object.
+ *
+ * @param obj the tagged object holding the object we want
+ * @param explicit true if the object is meant to be explicitly
+ * tagged false otherwise.
+ * @exception IllegalArgumentException if the tagged object cannot
+ * be converted.
+ */
+ public static ASN1UTCTime getInstance(
+ ASN1TaggedObject obj,
+ boolean explicit)
+ {
+ ASN1Object o = obj.getObject();
+
+ if (explicit || o instanceof ASN1UTCTime)
+ {
+ return getInstance(o);
+ }
+ else
+ {
+ return new ASN1UTCTime(((ASN1OctetString)o).getOctets());
+ }
+ }
+
+ /**
+ * The correct format for this is YYMMDDHHMMSSZ (it used to be that seconds were
+ * never encoded. When you're creating one of these objects from scratch, that's
+ * what you want to use, otherwise we'll try to deal with whatever gets read from
+ * the input stream... (this is why the input format is different from the getTime()
+ * method output).
+ * <p>
+ *
+ * @param time the time string.
+ */
+ public ASN1UTCTime(
+ String time)
+ {
+ this.time = Strings.toByteArray(time);
+ try
+ {
+ this.getDate();
+ }
+ catch (ParseException e)
+ {
+ throw new IllegalArgumentException("invalid date string: " + e.getMessage());
+ }
+ }
+
+ /**
+ * base constructer from a java.util.date object
+ */
+ public ASN1UTCTime(
+ Date time)
{
- super(bytes);
+ SimpleDateFormat dateF = new SimpleDateFormat("yyMMddHHmmss'Z'");
+
+ dateF.setTimeZone(new SimpleTimeZone(0,"Z"));
+
+ this.time = Strings.toByteArray(dateF.format(time));
+ }
+
+ ASN1UTCTime(
+ byte[] time)
+ {
+ this.time = time;
+ }
+
+ /**
+ * return the time as a date based on whatever a 2 digit year will return. For
+ * standardised processing use getAdjustedDate().
+ *
+ * @return the resulting date
+ * @exception ParseException if the date string cannot be parsed.
+ */
+ public Date getDate()
+ throws ParseException
+ {
+ SimpleDateFormat dateF = new SimpleDateFormat("yyMMddHHmmssz");
+
+ return dateF.parse(getTime());
+ }
+
+ /**
+ * return the time as an adjusted date
+ * in the range of 1950 - 2049.
+ *
+ * @return a date in the range of 1950 to 2049.
+ * @exception ParseException if the date string cannot be parsed.
+ */
+ public Date getAdjustedDate()
+ throws ParseException
+ {
+ SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
+
+ dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
+
+ return dateF.parse(getAdjustedTime());
+ }
+
+ /**
+ * return the time - always in the form of
+ * YYMMDDhhmmssGMT(+hh:mm|-hh:mm).
+ * <p>
+ * Normally in a certificate we would expect "Z" rather than "GMT",
+ * however adding the "GMT" means we can just use:
+ * <pre>
+ * dateF = new SimpleDateFormat("yyMMddHHmmssz");
+ * </pre>
+ * To read in the time and get a date which is compatible with our local
+ * time zone.
+ * <p>
+ * <b>Note:</b> In some cases, due to the local date processing, this
+ * may lead to unexpected results. If you want to stick the normal
+ * convention of 1950 to 2049 use the getAdjustedTime() method.
+ */
+ public String getTime()
+ {
+ String stime = Strings.fromByteArray(time);
+
+ //
+ // standardise the format.
+ //
+ if (stime.indexOf('-') < 0 && stime.indexOf('+') < 0)
+ {
+ if (stime.length() == 11)
+ {
+ return stime.substring(0, 10) + "00GMT+00:00";
+ }
+ else
+ {
+ return stime.substring(0, 12) + "GMT+00:00";
+ }
+ }
+ else
+ {
+ int index = stime.indexOf('-');
+ if (index < 0)
+ {
+ index = stime.indexOf('+');
+ }
+ String d = stime;
+
+ if (index == stime.length() - 3)
+ {
+ d += "00";
+ }
+
+ if (index == 10)
+ {
+ return d.substring(0, 10) + "00GMT" + d.substring(10, 13) + ":" + d.substring(13, 15);
+ }
+ else
+ {
+ return d.substring(0, 12) + "GMT" + d.substring(12, 15) + ":" + d.substring(15, 17);
+ }
+ }
+ }
+
+ /**
+ * return a time string as an adjusted date with a 4 digit year. This goes
+ * in the range of 1950 - 2049.
+ */
+ public String getAdjustedTime()
+ {
+ String d = this.getTime();
+
+ if (d.charAt(0) < '5')
+ {
+ return "20" + d;
+ }
+ else
+ {
+ return "19" + d;
+ }
+ }
+
+ boolean isConstructed()
+ {
+ return false;
+ }
+
+ int encodedLength()
+ {
+ int length = time.length;
+
+ return 1 + StreamUtil.calculateBodyLength(length) + length;
+ }
+
+ void encode(
+ ASN1OutputStream out)
+ throws IOException
+ {
+ out.write(BERTags.UTC_TIME);
+
+ int length = time.length;
+
+ out.writeLength(length);
+
+ for (int i = 0; i != length; i++)
+ {
+ out.write((byte)time[i]);
+ }
+ }
+
+ boolean asn1Equals(
+ ASN1Primitive o)
+ {
+ if (!(o instanceof ASN1UTCTime))
+ {
+ return false;
+ }
+
+ return Arrays.areEqual(time, ((ASN1UTCTime)o).time);
}
- public ASN1UTCTime(Date time)
+ public int hashCode()
{
- super(time);
+ return Arrays.hashCode(time);
}
- public ASN1UTCTime(String time)
+ public String toString()
{
- super(time);
+ return Strings.fromByteArray(time);
}
}
diff --git a/core/src/main/java/org/bouncycastle/asn1/DERGeneralizedTime.java b/core/src/main/java/org/bouncycastle/asn1/DERGeneralizedTime.java
index 43e46731..adee74ec 100644
--- a/core/src/main/java/org/bouncycastle/asn1/DERGeneralizedTime.java
+++ b/core/src/main/java/org/bouncycastle/asn1/DERGeneralizedTime.java
@@ -1,350 +1,28 @@
package org.bouncycastle.asn1;
-import java.io.IOException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.Date;
-import java.util.SimpleTimeZone;
-import java.util.TimeZone;
-
-import org.bouncycastle.util.Arrays;
-import org.bouncycastle.util.Strings;
/**
- * Generalized time object.
+ * DER Generalized time object.
*/
public class DERGeneralizedTime
- extends ASN1Primitive
+ extends ASN1GeneralizedTime
{
- private byte[] time;
-
- /**
- * return a generalized time from the passed in object
- *
- * @exception IllegalArgumentException if the object cannot be converted.
- */
- public static ASN1GeneralizedTime getInstance(
- Object obj)
- {
- if (obj == null || obj instanceof ASN1GeneralizedTime)
- {
- return (ASN1GeneralizedTime)obj;
- }
-
- if (obj instanceof DERGeneralizedTime)
- {
- return new ASN1GeneralizedTime(((DERGeneralizedTime)obj).time);
- }
-
- if (obj instanceof byte[])
- {
- try
- {
- return (ASN1GeneralizedTime)fromByteArray((byte[])obj);
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("encoding error in getInstance: " + e.toString());
- }
- }
-
- throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
- }
-
- /**
- * return a Generalized Time object from a tagged object.
- *
- * @param obj the tagged object holding the object we want
- * @param explicit true if the object is meant to be explicitly
- * tagged false otherwise.
- * @exception IllegalArgumentException if the tagged object cannot
- * be converted.
- */
- public static ASN1GeneralizedTime getInstance(
- ASN1TaggedObject obj,
- boolean explicit)
- {
- ASN1Primitive o = obj.getObject();
-
- if (explicit || o instanceof DERGeneralizedTime)
- {
- return getInstance(o);
- }
- else
- {
- return new ASN1GeneralizedTime(((ASN1OctetString)o).getOctets());
- }
- }
-
- /**
- * 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.
- *
- * @param time the time string.
- * @exception IllegalArgumentException if String is an illegal format.
- */
- public DERGeneralizedTime(
- String time)
- {
- this.time = Strings.toByteArray(time);
- try
- {
- this.getDate();
- }
- catch (ParseException e)
- {
- throw new IllegalArgumentException("invalid date string: " + e.getMessage());
- }
- }
-
- /**
- * base constructor from a java.util.date object
- */
- public DERGeneralizedTime(
- Date time)
- {
- SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
-
- dateF.setTimeZone(new SimpleTimeZone(0,"Z"));
-
- this.time = Strings.toByteArray(dateF.format(time));
- }
-
- DERGeneralizedTime(
- byte[] bytes)
- {
- this.time = bytes;
- }
-
- /**
- * Return the time.
- * @return The time string as it appeared in the encoded object.
- */
- public String getTimeString()
- {
- return Strings.fromByteArray(time);
- }
-
- /**
- * return the time - always in the form of
- * YYYYMMDDhhmmssGMT(+hh:mm|-hh:mm).
- * <p>
- * Normally in a certificate we would expect "Z" rather than "GMT",
- * however adding the "GMT" means we can just use:
- * <pre>
- * dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
- * </pre>
- * To read in the time and get a date which is compatible with our local
- * time zone.
- */
- public String getTime()
- {
- String stime = Strings.fromByteArray(time);
-
- //
- // standardise the format.
- //
- if (stime.charAt(stime.length() - 1) == 'Z')
- {
- return stime.substring(0, stime.length() - 1) + "GMT+00:00";
- }
- else
- {
- int signPos = stime.length() - 5;
- char sign = stime.charAt(signPos);
- if (sign == '-' || sign == '+')
- {
- return stime.substring(0, signPos)
- + "GMT"
- + stime.substring(signPos, signPos + 3)
- + ":"
- + stime.substring(signPos + 3);
- }
- else
- {
- signPos = stime.length() - 3;
- sign = stime.charAt(signPos);
- if (sign == '-' || sign == '+')
- {
- return stime.substring(0, signPos)
- + "GMT"
- + stime.substring(signPos)
- + ":00";
- }
- }
- }
- return stime + calculateGMTOffset();
- }
- private String calculateGMTOffset()
+ DERGeneralizedTime(byte[] bytes)
{
- String sign = "+";
- TimeZone timeZone = TimeZone.getDefault();
- int offset = timeZone.getRawOffset();
- if (offset < 0)
- {
- sign = "-";
- offset = -offset;
- }
- int hours = offset / (60 * 60 * 1000);
- int minutes = (offset - (hours * 60 * 60 * 1000)) / (60 * 1000);
-
- try
- {
- if (timeZone.useDaylightTime() && timeZone.inDaylightTime(this.getDate()))
- {
- hours += sign.equals("+") ? 1 : -1;
- }
- }
- catch (ParseException e)
- {
- // we'll do our best and ignore daylight savings
- }
-
- return "GMT" + sign + convert(hours) + ":" + convert(minutes);
+ super(bytes);
}
- private String convert(int time)
+ public DERGeneralizedTime(Date time)
{
- if (time < 10)
- {
- return "0" + time;
- }
-
- return Integer.toString(time);
- }
-
- public Date getDate()
- throws ParseException
- {
- SimpleDateFormat dateF;
- String stime = Strings.fromByteArray(time);
- String d = stime;
-
- if (stime.endsWith("Z"))
- {
- if (hasFractionalSeconds())
- {
- dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'");
- }
- else
- {
- dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
- }
-
- dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
- }
- else if (stime.indexOf('-') > 0 || stime.indexOf('+') > 0)
- {
- d = this.getTime();
- if (hasFractionalSeconds())
- {
- dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSSz");
- }
- else
- {
- dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
- }
-
- dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
- }
- else
- {
- if (hasFractionalSeconds())
- {
- dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
- }
- else
- {
- dateF = new SimpleDateFormat("yyyyMMddHHmmss");
- }
-
- dateF.setTimeZone(new SimpleTimeZone(0, TimeZone.getDefault().getID()));
- }
-
- if (hasFractionalSeconds())
- {
- // java misinterprets extra digits as being milliseconds...
- String frac = d.substring(14);
- int index;
- for (index = 1; index < frac.length(); index++)
- {
- char ch = frac.charAt(index);
- if (!('0' <= ch && ch <= '9'))
- {
- break;
- }
- }
-
- if (index - 1 > 3)
- {
- frac = frac.substring(0, 4) + frac.substring(index);
- d = d.substring(0, 14) + frac;
- }
- else if (index - 1 == 1)
- {
- frac = frac.substring(0, index) + "00" + frac.substring(index);
- d = d.substring(0, 14) + frac;
- }
- else if (index - 1 == 2)
- {
- frac = frac.substring(0, index) + "0" + frac.substring(index);
- d = d.substring(0, 14) + frac;
- }
- }
-
- return dateF.parse(d);
+ super(time);
}
- private boolean hasFractionalSeconds()
+ public DERGeneralizedTime(String time)
{
- for (int i = 0; i != time.length; i++)
- {
- if (time[i] == '.')
- {
- if (i == 14)
- {
- return true;
- }
- }
- }
- return false;
+ super(time);
}
- boolean isConstructed()
- {
- return false;
- }
-
- int encodedLength()
- {
- int length = time.length;
-
- return 1 + StreamUtil.calculateBodyLength(length) + length;
- }
-
- void encode(
- ASN1OutputStream out)
- throws IOException
- {
- out.writeEncoded(BERTags.GENERALIZED_TIME, time);
- }
-
- boolean asn1Equals(
- ASN1Primitive o)
- {
- if (!(o instanceof DERGeneralizedTime))
- {
- return false;
- }
-
- return Arrays.areEqual(time, ((DERGeneralizedTime)o).time);
- }
-
- public int hashCode()
- {
- return Arrays.hashCode(time);
- }
+ // TODO: create proper DER encoding.
}
diff --git a/core/src/main/java/org/bouncycastle/asn1/DERUTCTime.java b/core/src/main/java/org/bouncycastle/asn1/DERUTCTime.java
index c5bd536f..18e17b12 100644
--- a/core/src/main/java/org/bouncycastle/asn1/DERUTCTime.java
+++ b/core/src/main/java/org/bouncycastle/asn1/DERUTCTime.java
@@ -1,278 +1,27 @@
package org.bouncycastle.asn1;
-import java.io.IOException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.Date;
-import java.util.SimpleTimeZone;
-
-import org.bouncycastle.util.Arrays;
-import org.bouncycastle.util.Strings;
/**
- * UTC time object.
+ * DER UTC time object.
*/
public class DERUTCTime
- extends ASN1Primitive
+ extends ASN1UTCTime
{
- private byte[] time;
-
- /**
- * return an UTC Time from the passed in object.
- *
- * @exception IllegalArgumentException if the object cannot be converted.
- */
- public static ASN1UTCTime getInstance(
- Object obj)
- {
- if (obj == null || obj instanceof ASN1UTCTime)
- {
- return (ASN1UTCTime)obj;
- }
-
- if (obj instanceof DERUTCTime)
- {
- return new ASN1UTCTime(((DERUTCTime)obj).time);
- }
-
- if (obj instanceof byte[])
- {
- try
- {
- return (ASN1UTCTime)fromByteArray((byte[])obj);
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("encoding error in getInstance: " + e.toString());
- }
- }
-
- throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
- }
-
- /**
- * return an UTC Time from a tagged object.
- *
- * @param obj the tagged object holding the object we want
- * @param explicit true if the object is meant to be explicitly
- * tagged false otherwise.
- * @exception IllegalArgumentException if the tagged object cannot
- * be converted.
- */
- public static ASN1UTCTime getInstance(
- ASN1TaggedObject obj,
- boolean explicit)
- {
- ASN1Object o = obj.getObject();
-
- if (explicit || o instanceof ASN1UTCTime)
- {
- return getInstance(o);
- }
- else
- {
- return new ASN1UTCTime(((ASN1OctetString)o).getOctets());
- }
- }
-
- /**
- * The correct format for this is YYMMDDHHMMSSZ (it used to be that seconds were
- * never encoded. When you're creating one of these objects from scratch, that's
- * what you want to use, otherwise we'll try to deal with whatever gets read from
- * the input stream... (this is why the input format is different from the getTime()
- * method output).
- * <p>
- *
- * @param time the time string.
- */
- public DERUTCTime(
- String time)
- {
- this.time = Strings.toByteArray(time);
- try
- {
- this.getDate();
- }
- catch (ParseException e)
- {
- throw new IllegalArgumentException("invalid date string: " + e.getMessage());
- }
- }
-
- /**
- * base constructer from a java.util.date object
- */
- public DERUTCTime(
- Date time)
- {
- SimpleDateFormat dateF = new SimpleDateFormat("yyMMddHHmmss'Z'");
-
- dateF.setTimeZone(new SimpleTimeZone(0,"Z"));
-
- this.time = Strings.toByteArray(dateF.format(time));
- }
-
- DERUTCTime(
- byte[] time)
- {
- this.time = time;
- }
-
- /**
- * return the time as a date based on whatever a 2 digit year will return. For
- * standardised processing use getAdjustedDate().
- *
- * @return the resulting date
- * @exception ParseException if the date string cannot be parsed.
- */
- public Date getDate()
- throws ParseException
- {
- SimpleDateFormat dateF = new SimpleDateFormat("yyMMddHHmmssz");
-
- return dateF.parse(getTime());
- }
-
- /**
- * return the time as an adjusted date
- * in the range of 1950 - 2049.
- *
- * @return a date in the range of 1950 to 2049.
- * @exception ParseException if the date string cannot be parsed.
- */
- public Date getAdjustedDate()
- throws ParseException
+ DERUTCTime(byte[] bytes)
{
- SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
-
- dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
-
- return dateF.parse(getAdjustedTime());
- }
-
- /**
- * return the time - always in the form of
- * YYMMDDhhmmssGMT(+hh:mm|-hh:mm).
- * <p>
- * Normally in a certificate we would expect "Z" rather than "GMT",
- * however adding the "GMT" means we can just use:
- * <pre>
- * dateF = new SimpleDateFormat("yyMMddHHmmssz");
- * </pre>
- * To read in the time and get a date which is compatible with our local
- * time zone.
- * <p>
- * <b>Note:</b> In some cases, due to the local date processing, this
- * may lead to unexpected results. If you want to stick the normal
- * convention of 1950 to 2049 use the getAdjustedTime() method.
- */
- public String getTime()
- {
- String stime = Strings.fromByteArray(time);
-
- //
- // standardise the format.
- //
- if (stime.indexOf('-') < 0 && stime.indexOf('+') < 0)
- {
- if (stime.length() == 11)
- {
- return stime.substring(0, 10) + "00GMT+00:00";
- }
- else
- {
- return stime.substring(0, 12) + "GMT+00:00";
- }
- }
- else
- {
- int index = stime.indexOf('-');
- if (index < 0)
- {
- index = stime.indexOf('+');
- }
- String d = stime;
-
- if (index == stime.length() - 3)
- {
- d += "00";
- }
-
- if (index == 10)
- {
- return d.substring(0, 10) + "00GMT" + d.substring(10, 13) + ":" + d.substring(13, 15);
- }
- else
- {
- return d.substring(0, 12) + "GMT" + d.substring(12, 15) + ":" + d.substring(15, 17);
- }
- }
- }
-
- /**
- * return a time string as an adjusted date with a 4 digit year. This goes
- * in the range of 1950 - 2049.
- */
- public String getAdjustedTime()
- {
- String d = this.getTime();
-
- if (d.charAt(0) < '5')
- {
- return "20" + d;
- }
- else
- {
- return "19" + d;
- }
- }
-
- boolean isConstructed()
- {
- return false;
+ super(bytes);
}
- int encodedLength()
+ public DERUTCTime(Date time)
{
- int length = time.length;
-
- return 1 + StreamUtil.calculateBodyLength(length) + length;
+ super(time);
}
- void encode(
- ASN1OutputStream out)
- throws IOException
+ public DERUTCTime(String time)
{
- out.write(BERTags.UTC_TIME);
-
- int length = time.length;
-
- out.writeLength(length);
-
- for (int i = 0; i != length; i++)
- {
- out.write((byte)time[i]);
- }
+ super(time);
}
-
- boolean asn1Equals(
- ASN1Primitive o)
- {
- if (!(o instanceof DERUTCTime))
- {
- return false;
- }
- return Arrays.areEqual(time, ((DERUTCTime)o).time);
- }
-
- public int hashCode()
- {
- return Arrays.hashCode(time);
- }
-
- public String toString()
- {
- return Strings.fromByteArray(time);
- }
+ // TODO: create proper DER encoding.
}
diff --git a/core/src/main/java/org/bouncycastle/asn1/cmp/PKIHeader.java b/core/src/main/java/org/bouncycastle/asn1/cmp/PKIHeader.java
index afab1920..82f1b087 100644
--- a/core/src/main/java/org/bouncycastle/asn1/cmp/PKIHeader.java
+++ b/core/src/main/java/org/bouncycastle/asn1/cmp/PKIHeader.java
@@ -4,13 +4,13 @@ import java.util.Enumeration;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
+import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1TaggedObject;
-import org.bouncycastle.asn1.DERGeneralizedTime;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERTaggedObject;
import org.bouncycastle.asn1.x500.X500Name;
@@ -31,7 +31,7 @@ public class PKIHeader
private ASN1Integer pvno;
private GeneralName sender;
private GeneralName recipient;
- private DERGeneralizedTime messageTime;
+ private ASN1GeneralizedTime messageTime;
private AlgorithmIdentifier protectionAlg;
private ASN1OctetString senderKID; // KeyIdentifier
private ASN1OctetString recipKID; // KeyIdentifier
@@ -56,7 +56,7 @@ public class PKIHeader
switch (tObj.getTagNo())
{
case 0:
- messageTime = DERGeneralizedTime.getInstance(tObj, true);
+ messageTime = ASN1GeneralizedTime.getInstance(tObj, true);
break;
case 1:
protectionAlg = AlgorithmIdentifier.getInstance(tObj, true);
@@ -136,7 +136,7 @@ public class PKIHeader
return recipient;
}
- public DERGeneralizedTime getMessageTime()
+ public ASN1GeneralizedTime getMessageTime()
{
return messageTime;
}
diff --git a/core/src/main/java/org/bouncycastle/asn1/cmp/PKIHeaderBuilder.java b/core/src/main/java/org/bouncycastle/asn1/cmp/PKIHeaderBuilder.java
index 76d6bab3..c5465a97 100644
--- a/core/src/main/java/org/bouncycastle/asn1/cmp/PKIHeaderBuilder.java
+++ b/core/src/main/java/org/bouncycastle/asn1/cmp/PKIHeaderBuilder.java
@@ -6,7 +6,6 @@ import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Sequence;
-import org.bouncycastle.asn1.DERGeneralizedTime;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERTaggedObject;
@@ -46,16 +45,6 @@ public class PKIHeaderBuilder
this.recipient = recipient;
}
- /**
- * @deprecated use ASN1GeneralizedTime
- */
- public PKIHeaderBuilder setMessageTime(DERGeneralizedTime time)
- {
- messageTime = ASN1GeneralizedTime.getInstance(time);
-
- return this;
- }
-
public PKIHeaderBuilder setMessageTime(ASN1GeneralizedTime time)
{
messageTime = time;
diff --git a/core/src/main/java/org/bouncycastle/asn1/cms/RecipientKeyIdentifier.java b/core/src/main/java/org/bouncycastle/asn1/cms/RecipientKeyIdentifier.java
index f0eae592..a680e4aa 100644
--- a/core/src/main/java/org/bouncycastle/asn1/cms/RecipientKeyIdentifier.java
+++ b/core/src/main/java/org/bouncycastle/asn1/cms/RecipientKeyIdentifier.java
@@ -1,12 +1,12 @@
package org.bouncycastle.asn1.cms;
import org.bouncycastle.asn1.ASN1EncodableVector;
+import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1TaggedObject;
-import org.bouncycastle.asn1.DERGeneralizedTime;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSequence;
@@ -28,12 +28,12 @@ public class RecipientKeyIdentifier
extends ASN1Object
{
private ASN1OctetString subjectKeyIdentifier;
- private DERGeneralizedTime date;
+ private ASN1GeneralizedTime date;
private OtherKeyAttribute other;
public RecipientKeyIdentifier(
ASN1OctetString subjectKeyIdentifier,
- DERGeneralizedTime date,
+ ASN1GeneralizedTime date,
OtherKeyAttribute other)
{
this.subjectKeyIdentifier = subjectKeyIdentifier;
@@ -43,7 +43,7 @@ public class RecipientKeyIdentifier
public RecipientKeyIdentifier(
byte[] subjectKeyIdentifier,
- DERGeneralizedTime date,
+ ASN1GeneralizedTime date,
OtherKeyAttribute other)
{
this.subjectKeyIdentifier = new DEROctetString(subjectKeyIdentifier);
@@ -71,9 +71,9 @@ public class RecipientKeyIdentifier
case 1:
break;
case 2:
- if (seq.getObjectAt(1) instanceof DERGeneralizedTime)
+ if (seq.getObjectAt(1) instanceof ASN1GeneralizedTime)
{
- date = (DERGeneralizedTime)seq.getObjectAt(1);
+ date = ASN1GeneralizedTime.getInstance(seq.getObjectAt(1));
}
else
{
@@ -81,7 +81,7 @@ public class RecipientKeyIdentifier
}
break;
case 3:
- date = (DERGeneralizedTime)seq.getObjectAt(1);
+ date = ASN1GeneralizedTime.getInstance(seq.getObjectAt(1));
other = OtherKeyAttribute.getInstance(seq.getObjectAt(2));
break;
default:
@@ -136,7 +136,7 @@ public class RecipientKeyIdentifier
return subjectKeyIdentifier;
}
- public DERGeneralizedTime getDate()
+ public ASN1GeneralizedTime getDate()
{
return date;
}
diff --git a/core/src/main/java/org/bouncycastle/asn1/cms/Time.java b/core/src/main/java/org/bouncycastle/asn1/cms/Time.java
index 977fce64..81b8bc03 100644
--- a/core/src/main/java/org/bouncycastle/asn1/cms/Time.java
+++ b/core/src/main/java/org/bouncycastle/asn1/cms/Time.java
@@ -6,9 +6,11 @@ import java.util.Date;
import java.util.SimpleTimeZone;
import org.bouncycastle.asn1.ASN1Choice;
+import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1TaggedObject;
+import org.bouncycastle.asn1.ASN1UTCTime;
import org.bouncycastle.asn1.DERGeneralizedTime;
import org.bouncycastle.asn1.DERUTCTime;
@@ -47,8 +49,8 @@ public class Time
public Time(
ASN1Primitive time)
{
- if (!(time instanceof DERUTCTime)
- && !(time instanceof DERGeneralizedTime))
+ if (!(time instanceof ASN1UTCTime)
+ && !(time instanceof ASN1GeneralizedTime))
{
throw new IllegalArgumentException("unknown object passed to Time");
}
@@ -103,13 +105,13 @@ public class Time
{
return (Time)obj;
}
- else if (obj instanceof DERUTCTime)
+ else if (obj instanceof ASN1UTCTime)
{
- return new Time((DERUTCTime)obj);
+ return new Time((ASN1UTCTime)obj);
}
- else if (obj instanceof DERGeneralizedTime)
+ else if (obj instanceof ASN1GeneralizedTime)
{
- return new Time((DERGeneralizedTime)obj);
+ return new Time((ASN1GeneralizedTime)obj);
}
throw new IllegalArgumentException("unknown object in factory: " + obj.getClass().getName());
@@ -120,13 +122,13 @@ public class Time
*/
public String getTime()
{
- if (time instanceof DERUTCTime)
+ if (time instanceof ASN1UTCTime)
{
- return ((DERUTCTime)time).getAdjustedTime();
+ return ((ASN1UTCTime)time).getAdjustedTime();
}
else
{
- return ((DERGeneralizedTime)time).getTime();
+ return ((ASN1GeneralizedTime)time).getTime();
}
}
@@ -137,13 +139,13 @@ public class Time
{
try
{
- if (time instanceof DERUTCTime)
+ if (time instanceof ASN1UTCTime)
{
- return ((DERUTCTime)time).getAdjustedDate();
+ return ((ASN1UTCTime)time).getAdjustedDate();
}
else
{
- return ((DERGeneralizedTime)time).getDate();
+ return ((ASN1GeneralizedTime)time).getDate();
}
}
catch (ParseException e)
diff --git a/core/src/main/java/org/bouncycastle/asn1/ocsp/CrlID.java b/core/src/main/java/org/bouncycastle/asn1/ocsp/CrlID.java
index e14fe294..f5a35811 100644
--- a/core/src/main/java/org/bouncycastle/asn1/ocsp/CrlID.java
+++ b/core/src/main/java/org/bouncycastle/asn1/ocsp/CrlID.java
@@ -9,7 +9,6 @@ import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1TaggedObject;
-import org.bouncycastle.asn1.DERGeneralizedTime;
import org.bouncycastle.asn1.DERIA5String;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERTaggedObject;
@@ -39,7 +38,7 @@ public class CrlID
crlNum = ASN1Integer.getInstance(o, true);
break;
case 2:
- crlTime = DERGeneralizedTime.getInstance(o, true);
+ crlTime = ASN1GeneralizedTime.getInstance(o, true);
break;
default:
throw new IllegalArgumentException(
diff --git a/core/src/main/java/org/bouncycastle/asn1/ocsp/ResponseData.java b/core/src/main/java/org/bouncycastle/asn1/ocsp/ResponseData.java
index e2a9f955..6874b227 100644
--- a/core/src/main/java/org/bouncycastle/asn1/ocsp/ResponseData.java
+++ b/core/src/main/java/org/bouncycastle/asn1/ocsp/ResponseData.java
@@ -7,7 +7,6 @@ import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1TaggedObject;
-import org.bouncycastle.asn1.DERGeneralizedTime;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERTaggedObject;
import org.bouncycastle.asn1.x509.Extensions;
@@ -49,7 +48,7 @@ public class ResponseData
*/
public ResponseData(
ResponderID responderID,
- DERGeneralizedTime producedAt,
+ ASN1GeneralizedTime producedAt,
ASN1Sequence responses,
X509Extensions responseExtensions)
{
diff --git a/core/src/main/java/org/bouncycastle/asn1/ocsp/SingleResponse.java b/core/src/main/java/org/bouncycastle/asn1/ocsp/SingleResponse.java
index ca5a5c42..0dc2a91c 100644
--- a/core/src/main/java/org/bouncycastle/asn1/ocsp/SingleResponse.java
+++ b/core/src/main/java/org/bouncycastle/asn1/ocsp/SingleResponse.java
@@ -6,7 +6,6 @@ import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1TaggedObject;
-import org.bouncycastle.asn1.DERGeneralizedTime;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERTaggedObject;
import org.bouncycastle.asn1.x509.Extensions;
@@ -32,31 +31,13 @@ public class SingleResponse
public SingleResponse(
CertID certID,
CertStatus certStatus,
- DERGeneralizedTime thisUpdate,
- DERGeneralizedTime nextUpdate,
+ ASN1GeneralizedTime thisUpdate,
+ ASN1GeneralizedTime nextUpdate,
X509Extensions singleExtensions)
{
this(certID, certStatus, thisUpdate, nextUpdate, Extensions.getInstance(singleExtensions));
}
- /**
- * @deprecated use method taking ASN1GeneralizedTime and Extensions
- * @param certID
- * @param certStatus
- * @param thisUpdate
- * @param nextUpdate
- * @param singleExtensions
- */
- public SingleResponse(
- CertID certID,
- CertStatus certStatus,
- DERGeneralizedTime thisUpdate,
- DERGeneralizedTime nextUpdate,
- Extensions singleExtensions)
- {
- this(certID, certStatus, ASN1GeneralizedTime.getInstance(thisUpdate), ASN1GeneralizedTime.getInstance(nextUpdate), Extensions.getInstance(singleExtensions));
- }
-
public SingleResponse(
CertID certID,
CertStatus certStatus,
diff --git a/core/src/main/java/org/bouncycastle/asn1/util/ASN1Dump.java b/core/src/main/java/org/bouncycastle/asn1/util/ASN1Dump.java
index 8221e182..8a454f27 100644
--- a/core/src/main/java/org/bouncycastle/asn1/util/ASN1Dump.java
+++ b/core/src/main/java/org/bouncycastle/asn1/util/ASN1Dump.java
@@ -6,6 +6,7 @@ import java.util.Enumeration;
import org.bouncycastle.asn1.ASN1Boolean;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Enumerated;
+import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1OctetString;
@@ -13,6 +14,7 @@ import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1Set;
import org.bouncycastle.asn1.ASN1TaggedObject;
+import org.bouncycastle.asn1.ASN1UTCTime;
import org.bouncycastle.asn1.BERApplicationSpecific;
import org.bouncycastle.asn1.BEROctetString;
import org.bouncycastle.asn1.BERSequence;
@@ -23,13 +25,11 @@ import org.bouncycastle.asn1.DERApplicationSpecific;
import org.bouncycastle.asn1.DERBMPString;
import org.bouncycastle.asn1.DERBitString;
import org.bouncycastle.asn1.DERExternal;
-import org.bouncycastle.asn1.DERGeneralizedTime;
import org.bouncycastle.asn1.DERIA5String;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.DERPrintableString;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERT61String;
-import org.bouncycastle.asn1.DERUTCTime;
import org.bouncycastle.asn1.DERUTF8String;
import org.bouncycastle.asn1.DERVisibleString;
import org.bouncycastle.util.encoders.Hex;
@@ -237,13 +237,13 @@ public class ASN1Dump
{
buf.append(indent + "T61String(" + ((DERT61String)obj).getString() + ") " + nl);
}
- else if (obj instanceof DERUTCTime)
+ else if (obj instanceof ASN1UTCTime)
{
- buf.append(indent + "UTCTime(" + ((DERUTCTime)obj).getTime() + ") " + nl);
+ buf.append(indent + "UTCTime(" + ((ASN1UTCTime)obj).getTime() + ") " + nl);
}
- else if (obj instanceof DERGeneralizedTime)
+ else if (obj instanceof ASN1GeneralizedTime)
{
- buf.append(indent + "GeneralizedTime(" + ((DERGeneralizedTime)obj).getTime() + ") " + nl);
+ buf.append(indent + "GeneralizedTime(" + ((ASN1GeneralizedTime)obj).getTime() + ") " + nl);
}
else if (obj instanceof BERApplicationSpecific)
{
diff --git a/core/src/main/java/org/bouncycastle/asn1/x509/PrivateKeyUsagePeriod.java b/core/src/main/java/org/bouncycastle/asn1/x509/PrivateKeyUsagePeriod.java
index 81669260..44e0b671 100644
--- a/core/src/main/java/org/bouncycastle/asn1/x509/PrivateKeyUsagePeriod.java
+++ b/core/src/main/java/org/bouncycastle/asn1/x509/PrivateKeyUsagePeriod.java
@@ -3,11 +3,11 @@ package org.bouncycastle.asn1.x509;
import java.util.Enumeration;
import org.bouncycastle.asn1.ASN1EncodableVector;
+import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1TaggedObject;
-import org.bouncycastle.asn1.DERGeneralizedTime;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERTaggedObject;
@@ -36,7 +36,7 @@ public class PrivateKeyUsagePeriod
return null;
}
- private DERGeneralizedTime _notBefore, _notAfter;
+ private ASN1GeneralizedTime _notBefore, _notAfter;
private PrivateKeyUsagePeriod(ASN1Sequence seq)
{
@@ -47,21 +47,21 @@ public class PrivateKeyUsagePeriod
if (tObj.getTagNo() == 0)
{
- _notBefore = DERGeneralizedTime.getInstance(tObj, false);
+ _notBefore = ASN1GeneralizedTime.getInstance(tObj, false);
}
else if (tObj.getTagNo() == 1)
{
- _notAfter = DERGeneralizedTime.getInstance(tObj, false);
+ _notAfter = ASN1GeneralizedTime.getInstance(tObj, false);
}
}
}
- public DERGeneralizedTime getNotBefore()
+ public ASN1GeneralizedTime getNotBefore()
{
return _notBefore;
}
- public DERGeneralizedTime getNotAfter()
+ public ASN1GeneralizedTime getNotAfter()
{
return _notAfter;
}
diff --git a/core/src/main/java/org/bouncycastle/asn1/x509/TBSCertList.java b/core/src/main/java/org/bouncycastle/asn1/x509/TBSCertList.java
index ce657a76..5fdbcd67 100644
--- a/core/src/main/java/org/bouncycastle/asn1/x509/TBSCertList.java
+++ b/core/src/main/java/org/bouncycastle/asn1/x509/TBSCertList.java
@@ -3,15 +3,15 @@ package org.bouncycastle.asn1.x509;
import java.util.Enumeration;
import org.bouncycastle.asn1.ASN1EncodableVector;
+import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1TaggedObject;
-import org.bouncycastle.asn1.DERGeneralizedTime;
+import org.bouncycastle.asn1.ASN1UTCTime;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERTaggedObject;
-import org.bouncycastle.asn1.DERUTCTime;
import org.bouncycastle.asn1.x500.X500Name;
/**
@@ -190,8 +190,8 @@ public class TBSCertList
thisUpdate = Time.getInstance(seq.getObjectAt(seqPos++));
if (seqPos < seq.size()
- && (seq.getObjectAt(seqPos) instanceof DERUTCTime
- || seq.getObjectAt(seqPos) instanceof DERGeneralizedTime
+ && (seq.getObjectAt(seqPos) instanceof ASN1UTCTime
+ || seq.getObjectAt(seqPos) instanceof ASN1GeneralizedTime
|| seq.getObjectAt(seqPos) instanceof Time))
{
nextUpdate = Time.getInstance(seq.getObjectAt(seqPos++));
diff --git a/core/src/main/java/org/bouncycastle/asn1/x509/Time.java b/core/src/main/java/org/bouncycastle/asn1/x509/Time.java
index 5bffedc5..b68e8646 100644
--- a/core/src/main/java/org/bouncycastle/asn1/x509/Time.java
+++ b/core/src/main/java/org/bouncycastle/asn1/x509/Time.java
@@ -6,9 +6,11 @@ import java.util.Date;
import java.util.SimpleTimeZone;
import org.bouncycastle.asn1.ASN1Choice;
+import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1TaggedObject;
+import org.bouncycastle.asn1.ASN1UTCTime;
import org.bouncycastle.asn1.DERGeneralizedTime;
import org.bouncycastle.asn1.DERUTCTime;
@@ -28,8 +30,8 @@ public class Time
public Time(
ASN1Primitive time)
{
- if (!(time instanceof DERUTCTime)
- && !(time instanceof DERGeneralizedTime))
+ if (!(time instanceof ASN1UTCTime)
+ && !(time instanceof ASN1GeneralizedTime))
{
throw new IllegalArgumentException("unknown object passed to Time");
}
@@ -70,13 +72,13 @@ public class Time
{
return (Time)obj;
}
- else if (obj instanceof DERUTCTime)
+ else if (obj instanceof ASN1UTCTime)
{
- return new Time((DERUTCTime)obj);
+ return new Time((ASN1UTCTime)obj);
}
- else if (obj instanceof DERGeneralizedTime)
+ else if (obj instanceof ASN1GeneralizedTime)
{
- return new Time((DERGeneralizedTime)obj);
+ return new Time((ASN1GeneralizedTime)obj);
}
throw new IllegalArgumentException("unknown object in factory: " + obj.getClass().getName());
@@ -84,13 +86,13 @@ public class Time
public String getTime()
{
- if (time instanceof DERUTCTime)
+ if (time instanceof ASN1UTCTime)
{
- return ((DERUTCTime)time).getAdjustedTime();
+ return ((ASN1UTCTime)time).getAdjustedTime();
}
else
{
- return ((DERGeneralizedTime)time).getTime();
+ return ((ASN1GeneralizedTime)time).getTime();
}
}
@@ -98,13 +100,13 @@ public class Time
{
try
{
- if (time instanceof DERUTCTime)
+ if (time instanceof ASN1UTCTime)
{
- return ((DERUTCTime)time).getAdjustedDate();
+ return ((ASN1UTCTime)time).getAdjustedDate();
}
else
{
- return ((DERGeneralizedTime)time).getDate();
+ return ((ASN1GeneralizedTime)time).getDate();
}
}
catch (ParseException e)
diff --git a/core/src/main/java/org/bouncycastle/asn1/x509/V3TBSCertificateGenerator.java b/core/src/main/java/org/bouncycastle/asn1/x509/V3TBSCertificateGenerator.java
index 3d923b61..d778d7f5 100644
--- a/core/src/main/java/org/bouncycastle/asn1/x509/V3TBSCertificateGenerator.java
+++ b/core/src/main/java/org/bouncycastle/asn1/x509/V3TBSCertificateGenerator.java
@@ -2,10 +2,10 @@ package org.bouncycastle.asn1.x509;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Integer;
+import org.bouncycastle.asn1.ASN1UTCTime;
import org.bouncycastle.asn1.DERBitString;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERTaggedObject;
-import org.bouncycastle.asn1.DERUTCTime;
import org.bouncycastle.asn1.x500.X500Name;
/**
@@ -74,7 +74,7 @@ public class V3TBSCertificateGenerator
}
public void setStartDate(
- DERUTCTime startDate)
+ ASN1UTCTime startDate)
{
this.startDate = new Time(startDate);
}
@@ -86,7 +86,7 @@ public class V3TBSCertificateGenerator
}
public void setEndDate(
- DERUTCTime endDate)
+ ASN1UTCTime endDate)
{
this.endDate = new Time(endDate);
}