diff options
author | Roland Shoemaker <rolandshoemaker@gmail.com> | 2020-05-12 11:06:42 -0700 |
---|---|---|
committer | Emmanuel Odeke <emm.odeke@gmail.com> | 2020-05-23 06:47:06 +0000 |
commit | b68fa57c599720d33a2d735782969ce95eabf794 (patch) | |
tree | 82f93622d21ae0e1571127f92dc255ea93a3fb0a /src/encoding/asn1 | |
parent | 9acdc705e7d53a59b8418dd0beb570db35f7a744 (diff) | |
download | go-b68fa57c599720d33a2d735782969ce95eabf794.tar.gz go-b68fa57c599720d33a2d735782969ce95eabf794.zip |
encoding/asn1: document what Unmarshal returns in rest
Specifically, this change documents the behavior of Unmarshal when a
SEQUENCE contains trailing elements.
For context Unmarshal treats trailing elements of a SEQUENCE that do not
have matching struct fields as valid, as this is how ASN.1 structures
are typically extended. This can be somewhat confusing as you might
expect those elements to be appended to rest, but rest is really only
for trailing data unrelated to the structure being parsed (i.e. if you
append a second sequence to b, it would be returned in rest).
Fixes #35680
Change-Id: Ia2c68b2f7d8674d09e859b4b7f9aff327da26fa0
Reviewed-on: https://go-review.googlesource.com/c/go/+/233537
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
Diffstat (limited to 'src/encoding/asn1')
-rw-r--r-- | src/encoding/asn1/asn1.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/encoding/asn1/asn1.go b/src/encoding/asn1/asn1.go index 90ba5775af..d809dde278 100644 --- a/src/encoding/asn1/asn1.go +++ b/src/encoding/asn1/asn1.go @@ -1037,6 +1037,12 @@ func setDefaultValue(v reflect.Value, params fieldParameters) (ok bool) { // Because Unmarshal uses the reflect package, the structs // being written to must use upper case field names. // +// After parsing b, any bytes that were leftover and not used to fill +// val will be returned in rest. When parsing a SEQUENCE into a struct, +// any trailing elements of the SEQUENCE that do not have matching +// fields in val will not be included in rest, as these are considered +// valid elements of the SEQUENCE and not trailing data. +// // An ASN.1 INTEGER can be written to an int, int32, int64, // or *big.Int (from the math/big package). // If the encoded value does not fit in the Go type, |