You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
1.6.3
2. What operating system and processor architecture are you using (go env)?
OS X El Capitan 10.11.6
Issue
The "default" label in a struct does not imply "optional" tag.
According to A Layman's Guide to a Subset of ASN.1, BER, and DER http://luca.ntop.org/Teaching/Appunti/asn1.html
Section 5.12 SEQUENCE "The OPTIONAL qualifier indicates that the value of a component is optional and need not be present in the sequence. The DEFAULT qualifier also indicates that the value of a component is optional, and assigns a default value to the component when the component is absent."
The default tag should imply optional
This problem is recreated using code snippet below
package main
import (
"fmt""encoding/asn1"
)
typeteststruct {
AintBint`asn1:"default:1,tag:1"`
}
funcmain() {
e, _:=asn1.Marshal(test{A:5})
fmt.Println(e)
}
$ go build && ./test
[48 6 2 1 5 129 1 0]
As you can see, asn1 marshaled/encoded 0, which is the default for B in struct test.
While compliant implementation should yield
[48 6 2 1 5] leaving the B part out.
The text was updated successfully, but these errors were encountered:
rakyll
changed the title
asn1 package "default" label not working properly
encoding/asn1: "default" label not working properly
Aug 16, 2016
I'll document that default:x is only consulted for optional.
I don't want to change the semantics now.
It's easy for people to keep saying optional,default:x.
Please answer these questions before submitting your issue. Thanks!
go version
)?1.6.3
2. What operating system and processor architecture are you using (
go env
)?OS X El Capitan 10.11.6
The "default" label in a struct does not imply "optional" tag.
According to A Layman's Guide to a Subset of ASN.1, BER, and DER
http://luca.ntop.org/Teaching/Appunti/asn1.html
Section 5.12 SEQUENCE "The OPTIONAL qualifier indicates that the value of a component is optional and need not be present in the sequence. The DEFAULT qualifier also indicates that the value of a component is optional, and assigns a default value to the component when the component is absent."
The default tag should imply optional
This problem is recreated using code snippet below
As you can see, asn1 marshaled/encoded 0, which is the default for B in struct test.
While compliant implementation should yield
[48 6 2 1 5] leaving the B part out.
The text was updated successfully, but these errors were encountered: