Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/asn1: "default" label not working properly #16712

Closed
zhengping12 opened this issue Aug 16, 2016 · 2 comments
Closed

encoding/asn1: "default" label not working properly #16712

zhengping12 opened this issue Aug 16, 2016 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@zhengping12
Copy link

zhengping12 commented Aug 16, 2016

Please answer these questions before submitting your issue. Thanks!

  1. 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

  1. 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"
)
type test struct {
  A int
  B int `asn1:"default:1,tag:1"`
}

func main() {
  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.

@rakyll rakyll changed the title asn1 package "default" label not working properly encoding/asn1: "default" label not working properly Aug 16, 2016
@rakyll rakyll added this to the Go1.8 milestone Aug 16, 2016
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 6, 2016
@rsc
Copy link
Contributor

rsc commented Oct 26, 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.

@gopherbot
Copy link

CL https://golang.org/cl/32171 mentions this issue.

@golang golang locked and limited conversation to collaborators Nov 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants