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-07-17 10:23:10 +0400
committerDavid Hook <dgh@cryptoworkshop.com>2014-07-17 10:23:10 +0400
commita02b5f52528e2ed6073793975f161f71fe566b82 (patch)
tree75a09075cbf290bd89be66063360cfea8f0c6ea9
parent43aa4227f41ad04da4651d8ea1eade17bc03b75b (diff)
BJA-467 added support for passing in a specific locale to help with date interpretation.
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/eac/PackedDate.java23
1 files changed, 22 insertions, 1 deletions
diff --git a/core/src/main/java/org/bouncycastle/asn1/eac/PackedDate.java b/core/src/main/java/org/bouncycastle/asn1/eac/PackedDate.java
index 29b08812..e19c96f1 100644
--- a/core/src/main/java/org/bouncycastle/asn1/eac/PackedDate.java
+++ b/core/src/main/java/org/bouncycastle/asn1/eac/PackedDate.java
@@ -3,6 +3,7 @@ package org.bouncycastle.asn1.eac;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Locale;
import java.util.SimpleTimeZone;
import org.bouncycastle.util.Arrays;
@@ -21,7 +22,9 @@ public class PackedDate
}
/**
- * base constructer from a java.util.date object
+ * Base constructor from a java.util.date object.
+ *
+ * @param time a date object representing the time of interest.
*/
public PackedDate(
Date time)
@@ -33,6 +36,24 @@ public class PackedDate
this.time = convert(dateF.format(time));
}
+ /**
+ * Base constructor from a java.util.date object. You may need to use this constructor if the default locale
+ * doesn't use a Gregorian calender so that the PackedDate produced is compatible with other ASN.1 implementations.
+ *
+ * @param time a date object representing the time of interest.
+ * @param locale an appropriate Locale for producing an ASN.1 GeneralizedTime value.
+ */
+ public PackedDate(
+ Date time,
+ Locale locale)
+ {
+ SimpleDateFormat dateF = new SimpleDateFormat("yyMMdd'Z'", locale);
+
+ dateF.setTimeZone(new SimpleTimeZone(0,"Z"));
+
+ this.time = convert(dateF.format(time));
+ }
+
private byte[] convert(String sTime)
{
char[] digs = sTime.toCharArray();