From d7990e21e903ee413b1f4cd7aa382552742e70ff Mon Sep 17 00:00:00 2001 From: Alex Chistyakov Date: Wed, 24 Aug 2016 02:21:01 +0300 Subject: [PATCH 1/5] Process PrintableString and UTF8String ASN.1 types --- decode.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/decode.go b/decode.go index 0506723..1793f0c 100644 --- a/decode.go +++ b/decode.go @@ -405,6 +405,9 @@ func (ctx *Context) matchExpectedValues(eValues []expectedFieldElement, rValues missing := true if rIndex < len(rValues) { raw := rValues[rIndex] + if raw.Tag == tagPrintableString || raw.Tag == tagUTF8String { + raw.Tag = tagOctetString + } if e.class == raw.Class && e.tag == raw.Tag { err := e.decoder(raw.Content, e.value) if err != nil { From ea1af404b20c743c19a4b6cdc87b482553f03ced Mon Sep 17 00:00:00 2001 From: Alex Chistyakov Date: Wed, 24 Aug 2016 02:27:14 +0300 Subject: [PATCH 2/5] Add tagUTF8String constant --- raw.go | 1 + 1 file changed, 1 insertion(+) diff --git a/raw.go b/raw.go index a60ead6..197c05c 100644 --- a/raw.go +++ b/raw.go @@ -24,6 +24,7 @@ const ( tagOctetString = 0x04 tagNull = 0x05 tagOid = 0x06 + tagUTF8String = 0x0c tagSequence = 0x10 tagSet = 0x11 tagPrintableString = 0x13 From 8be9b1c5adf1a836e1917aba122577fe4cf2e37a Mon Sep 17 00:00:00 2001 From: Alex Chistyakov Date: Wed, 24 Aug 2016 11:23:46 +0300 Subject: [PATCH 3/5] Add an UTC time decoder (does nothing for now) --- types.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/types.go b/types.go index 8e54ab5..d9f48eb 100644 --- a/types.go +++ b/types.go @@ -5,6 +5,7 @@ import ( "fmt" "math/big" "reflect" + "time" ) // Pre-calculated types for convenience @@ -343,6 +344,16 @@ func (ctx *Context) decodeNull(data []byte, value reflect.Value) error { return nil } +func (ctx *Context) decodeUtcTime(data []byte, value reflect.Value) error { + // Check type + type1 := value.Type() + if !(type1 == reflect.TypeOf(time.Time{})) { + // Invalid type or element type + return wrongType("time.Time", value) + } + return nil +} + /* * Helper functions */ From cf18f6f76c66ab6fca475a2270f36a431fd84925 Mon Sep 17 00:00:00 2001 From: Alex Chistyakov Date: Wed, 24 Aug 2016 13:07:09 +0300 Subject: [PATCH 4/5] Process UTC time type --- decode.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/decode.go b/decode.go index 1793f0c..e257b4b 100644 --- a/decode.go +++ b/decode.go @@ -5,6 +5,7 @@ import ( "io" "reflect" "sort" + "time" ) // Expected values @@ -327,6 +328,10 @@ func (ctx *Context) getUniversalTagByKind(objType reflect.Type, opts *fieldOptio elem.decoder = ctx.decodeSlice } } + if objType == reflect.TypeOf(time.Time{}) { + elem.tag = tagUtcTime + elem.decoder = ctx.decodeUtcTime + } return } From b9ff6ac0e6aa56fb37ea2ef5aea0ef8398ffeee1 Mon Sep 17 00:00:00 2001 From: Alex Chistyakov Date: Wed, 24 Aug 2016 13:13:39 +0300 Subject: [PATCH 5/5] Process BitString type --- decode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decode.go b/decode.go index e257b4b..67b2df9 100644 --- a/decode.go +++ b/decode.go @@ -410,7 +410,7 @@ func (ctx *Context) matchExpectedValues(eValues []expectedFieldElement, rValues missing := true if rIndex < len(rValues) { raw := rValues[rIndex] - if raw.Tag == tagPrintableString || raw.Tag == tagUTF8String { + if raw.Tag == tagPrintableString || raw.Tag == tagUTF8String || raw.Tag == tagBitString { raw.Tag = tagOctetString } if e.class == raw.Class && e.tag == raw.Tag {