aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-22 23:44:53 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-22 23:44:53 +0000
commitbdbef403a122237d032af0697d375f135f1a69a3 (patch)
tree699282381f54880e6ec4218d85df631db50fcae6
parentd4314719d42f7380e45f13b0676be4d6e0b09aae (diff)
downloadruby-bdbef403a122237d032af0697d375f135f1a69a3.tar.gz
* ext/openssl/ossl_asn1.c (asn1time_to_time): Implement YYMMDDhhmmZ
format for ASN.1 UTCTime. [ruby-trunk - Bug #8664] * test/openssl/test_asn1.rb: Test for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ext/openssl/ossl_asn1.c13
-rw-r--r--test/openssl/test_asn1.rb8
3 files changed, 24 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 3045cb6525..cb9d799994 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue Jul 23 08:44:37 2013 Eric Hodel <drbrain@segment7.net>
+
+ * ext/openssl/ossl_asn1.c (asn1time_to_time): Implement YYMMDDhhmmZ
+ format for ASN.1 UTCTime. [ruby-trunk - Bug #8664]
+ * test/openssl/test_asn1.rb: Test for the above.
+
Tue Jul 23 08:11:32 2013 Zachary Scott <e@zzak.io>
* lib/rexml/streamlistener.rb: [DOC] Fix examples in
diff --git a/ext/openssl/ossl_asn1.c b/ext/openssl/ossl_asn1.c
index 81881517d3..6b4d523ee3 100644
--- a/ext/openssl/ossl_asn1.c
+++ b/ext/openssl/ossl_asn1.c
@@ -33,15 +33,22 @@ asn1time_to_time(ASN1_TIME *time)
{
struct tm tm;
VALUE argv[6];
+ int count;
if (!time || !time->data) return Qnil;
memset(&tm, 0, sizeof(struct tm));
switch (time->type) {
case V_ASN1_UTCTIME:
- if (sscanf((const char *)time->data, "%2d%2d%2d%2d%2d%2dZ", &tm.tm_year, &tm.tm_mon,
- &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
- ossl_raise(rb_eTypeError, "bad UTCTIME format");
+ count = sscanf((const char *)time->data, "%2d%2d%2d%2d%2d%2dZ",
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min,
+ &tm.tm_sec);
+
+ if (count == 5) {
+ tm.tm_sec = 0;
+ } else if (count != 6) {
+ ossl_raise(rb_eTypeError, "bad UTCTIME format: \"%s\"",
+ time->data);
}
if (tm.tm_year < 69) {
tm.tm_year += 2000;
diff --git a/test/openssl/test_asn1.rb b/test/openssl/test_asn1.rb
index 736655a30b..3ea2638b0b 100644
--- a/test/openssl/test_asn1.rb
+++ b/test/openssl/test_asn1.rb
@@ -263,6 +263,14 @@ rEzBQ0F9dUyqQ9gyRg8KHhDfv9HzT1d/rnUZMkoombwYBRIUChGCYV0GnJcan2Zm
end
end
+ def test_decode_utctime
+ expected = Time.at 1374535380
+ assert_equal expected, OpenSSL::ASN1.decode("\x17\v1307222323Z").value
+
+ expected += 17
+ assert_equal expected, OpenSSL::ASN1.decode("\x17\r130722232317Z").value
+ end
+
def test_create_inf_length_primitive
expected = %w{ 24 80 04 01 61 00 00 }
raw = [expected.join('')].pack('H*')