I see no possible workaround that doesn't involve copying parts of crypto/x509 or encoding/asn1.
It definitely makes more sense to me to use the default value to trigger the "optional" behavior. Other marshalers, like JSON, use the zero value (for omitempty) but those don't have a default setting. From what I know about ASN.1 I would be surprised by the current behavior. I also think that marshaling and unmarshaling should be inverses of each other to the greatest extent possible. The current behavior is not documented and in fact the documentation suggests that the default value should be used to make omission decisions.
default:x sets the default value for optional integer fields
We do have two exceptions in the Go 1 compatibility promise that might be considered to cover this change, despite the fact that it has the potential to break existing programs:
- Unspecified behavior. The Go specification tries to be explicit about most properties of the language, but there are some aspects that are undefined. Programs that depend on such unspecified behavior may break in future releases.
- Specification errors. If it becomes necessary to address an inconsistency or incompleteness in the specification, resolving the issue could affect the meaning or legality of existing programs. We reserve the right to address such issues, including updating the implementations. Except for security issues, no incompatible changes to the specification would be made.
Regards,
Matt