Commit d47c9bce authored by Hiroshi Ioka's avatar Hiroshi Ioka Committed by Adam Langley

encoding/asn1: handle application tag in Marshal

Fixes #20488

Change-Id: Iae963b612aea3d9e814b08f655e2eb019ece256e
Reviewed-on: https://go-review.googlesource.com/44110Reviewed-by: 's avatarAdam Langley <agl@golang.org>
Run-TryBot: Adam Langley <agl@golang.org>
parent 4a5f85ba
......@@ -560,7 +560,6 @@ func makeField(v reflect.Value, params fieldParameters) (e encoder, err error) {
if !ok {
return nil, StructuralError{fmt.Sprintf("unknown Go type: %v", v.Type())}
}
class := ClassUniversal
if params.timeType != 0 && tag != TagUTCTime {
return nil, StructuralError{"explicit time type given to non-time member"}
......@@ -610,15 +609,23 @@ func makeField(v reflect.Value, params fieldParameters) (e encoder, err error) {
bodyLen := t.body.Len()
class := ClassUniversal
if params.tag != nil {
if params.application {
class = ClassApplication
} else {
class = ClassContextSpecific
}
if params.explicit {
t.tag = bytesEncoder(appendTagAndLength(t.scratch[:0], tagAndLength{class, tag, bodyLen, isCompound}))
t.tag = bytesEncoder(appendTagAndLength(t.scratch[:0], tagAndLength{ClassUniversal, tag, bodyLen, isCompound}))
tt := new(taggedEncoder)
tt.body = t
tt.tag = bytesEncoder(appendTagAndLength(tt.scratch[:0], tagAndLength{
class: ClassContextSpecific,
class: class,
tag: *params.tag,
length: bodyLen + t.tag.Len(),
isCompound: true,
......@@ -627,10 +634,8 @@ func makeField(v reflect.Value, params fieldParameters) (e encoder, err error) {
return tt, nil
}
if params.tag != nil {
// implicit tag.
tag = *params.tag
class = ClassContextSpecific
}
t.tag = bytesEncoder(appendTagAndLength(t.scratch[:0], tagAndLength{class, tag, bodyLen, isCompound}))
......
......@@ -71,6 +71,11 @@ type defaultTest struct {
A int `asn1:"optional,default:1"`
}
type applicationTest struct {
A int `asn1:"application,tag:0"`
B int `asn1:"application,tag:1,explicit"`
}
type testSET []int
var PST = time.FixedZone("PST", -8*60*60)
......@@ -152,6 +157,7 @@ var marshalTests = []marshalTest{
{defaultTest{0}, "3003020100"},
{defaultTest{1}, "3000"},
{defaultTest{2}, "3003020102"},
{applicationTest{1, 2}, "30084001016103020102"},
}
func TestMarshal(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment