summaryrefslogtreecommitdiff
path: root/bcprov/src/main/java/org/bouncycastle/asn1/ASN1UTCTime.java
diff options
context:
space:
mode:
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/asn1/ASN1UTCTime.java')
-rw-r--r--bcprov/src/main/java/org/bouncycastle/asn1/ASN1UTCTime.java30
1 files changed, 16 insertions, 14 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/asn1/ASN1UTCTime.java b/bcprov/src/main/java/org/bouncycastle/asn1/ASN1UTCTime.java
index d2909370..d9a26291 100644
--- a/bcprov/src/main/java/org/bouncycastle/asn1/ASN1UTCTime.java
+++ b/bcprov/src/main/java/org/bouncycastle/asn1/ASN1UTCTime.java
@@ -90,7 +90,7 @@ public class ASN1UTCTime
}
else
{
- return new ASN1UTCTime(((ASN1OctetString)o).getOctets());
+ return new ASN1UTCTime(ASN1OctetString.getInstance(o).getOctets());
}
}
@@ -159,7 +159,15 @@ public class ASN1UTCTime
ASN1UTCTime(
byte[] time)
{
+ if (time.length < 2)
+ {
+ throw new IllegalArgumentException("UTCTime string too short");
+ }
this.time = time;
+ if (!(isDigit(0) && isDigit(1)))
+ {
+ throw new IllegalArgumentException("illegal characters in UTCTime string");
+ }
}
/**
@@ -275,6 +283,11 @@ public class ASN1UTCTime
}
}
+ private boolean isDigit(int pos)
+ {
+ return time.length > pos && time[pos] >= '0' && time[pos] <= '9';
+ }
+
boolean isConstructed()
{
return false;
@@ -287,20 +300,9 @@ public class ASN1UTCTime
return 1 + StreamUtil.calculateBodyLength(length) + length;
}
- void encode(
- ASN1OutputStream out)
- throws IOException
+ void encode(ASN1OutputStream out, boolean withTag) 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]);
- }
+ out.writeEncoded(withTag, BERTags.UTC_TIME, time);
}
boolean asn1Equals(