Skip to content
This repository has been archived by the owner on Mar 13, 2019. It is now read-only.

Process PrintableString and UTF8String ASN.1 types #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"reflect"
"sort"
"time"
)

// Expected values
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -405,6 +410,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 == tagBitString {
raw.Tag = tagOctetString
}
if e.class == raw.Class && e.tag == raw.Tag {
err := e.decoder(raw.Content, e.value)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
tagOctetString = 0x04
tagNull = 0x05
tagOid = 0x06
tagUTF8String = 0x0c
tagSequence = 0x10
tagSet = 0x11
tagPrintableString = 0x13
Expand Down
11 changes: 11 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/big"
"reflect"
"time"
)

// Pre-calculated types for convenience
Expand Down Expand Up @@ -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
*/
Expand Down