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"}
bodyLen := t.body.Len()
- if params.explicit {
- t.tag = bytesEncoder(appendTagAndLength(t.scratch[:0], tagAndLength{class, tag, bodyLen, isCompound}))
+ class := ClassUniversal
+ if params.tag != nil {
+ if params.application {
+ class = ClassApplication
+ } else {
+ class = ClassContextSpecific
+ }
- tt := new(taggedEncoder)
+ if params.explicit {
+ t.tag = bytesEncoder(appendTagAndLength(t.scratch[:0], tagAndLength{ClassUniversal, tag, bodyLen, isCompound}))
- tt.body = t
+ tt := new(taggedEncoder)
- tt.tag = bytesEncoder(appendTagAndLength(tt.scratch[:0], tagAndLength{
- class: ClassContextSpecific,
- tag: *params.tag,
- length: bodyLen + t.tag.Len(),
- isCompound: true,
- }))
+ tt.body = t
- return tt, nil
- }
+ tt.tag = bytesEncoder(appendTagAndLength(tt.scratch[:0], tagAndLength{
+ class: class,
+ tag: *params.tag,
+ length: bodyLen + t.tag.Len(),
+ isCompound: true,
+ }))
+
+ 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}))
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)
{defaultTest{0}, "3003020100"},
{defaultTest{1}, "3000"},
{defaultTest{2}, "3003020102"},
+ {applicationTest{1, 2}, "30084001016103020102"},
}
func TestMarshal(t *testing.T) {