aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/asn1
AgeCommit message (Collapse)Author
2021-04-20all: remove redundant spaces before . and ,Yury Smolsky
Change-Id: I6a4bd2544276d0638bddf07ebcf2ee636db30fea Reviewed-on: https://go-review.googlesource.com/c/go/+/311009 Run-TryBot: Yury Smolsky <yury@smolsky.by> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-02-25reflect: add Method.IsExported and StructField.IsExported methodsJoe Tsai
The IsExported method is a more intuitive helper for checking whether the method or field is exported than checking whether PkgPath is empty. In the same CL, modify the standard library to make use of this helper. Fixes #41563 Change-Id: Iaacfb3b74449501f98e2707aa32095a32bd3c3c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/266197 Trust: Joe Tsai <joetsai@digital-static.net> Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-01-12encoding/asn1: document unmarshaling behavior for IMPLICIT string fieldsEric Chiang
Fixes #42570. Change-Id: I73e339cdebe1720c141861a12e28a94cef13c75b Reviewed-on: https://go-review.googlesource.com/c/go/+/269798 Reviewed-by: Katie Hockman <katie@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> Run-TryBot: Katie Hockman <katie@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Katie Hockman <katie@golang.org>
2020-11-09encoding/asn1: optimize asn1.UnmarshalDmitrii Okunev
Used type-switch instead of switch by reflect.Type and added BenchmarkUnmarshal. name old time/op new time/op delta Marshal-8 28.1µs ± 2% 27.9µs ± 1% ~ (p=0.094 n=9+9) Unmarshal-8 6.45µs ± 1% 5.83µs ± 4% -9.59% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Marshal-8 8.26kB ± 0% 8.26kB ± 0% ~ (all equal) Unmarshal-8 840B ± 0% 488B ± 0% -41.90% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Marshal-8 363 ± 0% 363 ± 0% ~ (all equal) Unmarshal-8 50.0 ± 0% 43.0 ± 0% -14.00% (p=0.000 n=10+10) Change-Id: I6b53833c7a3e2524f025453311841d03c1256a45 GitHub-Pull-Request: golang/go#36341 Reviewed-on: https://go-review.googlesource.com/c/go/+/268557 Trust: Filippo Valsorda <filippo@golang.org> Trust: Roland Shoemaker <roland@golang.org> Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
2020-10-05encoding/asn1: clarify use of SET suffixRoland Bracewell Shoemaker
This change clarifies the usage of the SET type name suffix. Previously the documentation was somewhat confusing about where the suffix should be used, and when used what it applied to. For instance the previous language could be interpreted such that []exampleSET would be parsed as a SEQUENCE OF SET, which is incorrect as the SET suffix only applies to slice types, such as type exampleSET []struct{} which is parsed as a SET OF SEQUENCE. Change-Id: I74201d9969f931f69391c236559f66cb460569ec GitHub-Last-Rev: d0d2ddc587df4564a265c800efb9d8e204002624 GitHub-Pull-Request: golang/go#38543 Reviewed-on: https://go-review.googlesource.com/c/go/+/229078 Trust: Roland Shoemaker <roland@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-09-29encoding/asn1: error instead of panic on invalid value to UnmarshalKimMachineGun
Changes Unmarshal to return an error, instead of panicking when its value is nil or not a pointer. This change matches the behavior of other encoding packages like json. Fixes #41509. Change-Id: I92c3af3a960144566e4c2b55d00c3a6fe477c8d5 GitHub-Last-Rev: c668b6e4ad826f84542c2675eb31ccfb010c45bb GitHub-Pull-Request: golang/go#41485 Reviewed-on: https://go-review.googlesource.com/c/go/+/255881 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Filippo Valsorda <filippo@golang.org> Trust: Emmanuel Odeke <emm.odeke@gmail.com>
2020-08-18encoding/asn1: speed up marshal by reducing allocationsMartin Möhrmann
Replace strings.Split by strings.IndexByte and explicit slicing to avoid the allocation of the return slice of strings.Split. name old time/op new time/op delta Marshal 43.3µs ± 1% 36.7µs ± 1% -15.23% (p=0.000 n=9+9) name old alloc/op new alloc/op delta Marshal 10.7kB ± 0% 9.2kB ± 0% -13.96% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Marshal 444 ± 0% 366 ± 0% -17.57% (p=0.000 n=10+10) Change-Id: I9e727defa23f7e5fc684f246de0136fe28cf8d25 Reviewed-on: https://go-review.googlesource.com/c/go/+/231738 TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-05-23encoding/asn1: document what Unmarshal returns in restRoland Shoemaker
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>
2020-05-08encoding/asn1: sort order of 'SET of' components during MarshalRoland Shoemaker
Per X690 Section 11.6 sort the order of SET of components when generating DER. This CL makes no changes to Unmarshal, meaning unordered components will still be accepted, and won't be re-ordered during parsing. In order to sort the components a new encoder, setEncoder, which is similar to multiEncoder is added. The functional difference is that setEncoder encodes each component to a [][]byte, sorts the slice using a sort.Sort interface, and then writes it out to the destination slice. The ordering matches the output of OpenSSL. Fixes #24254 Change-Id: Iff4560f0b8c2dce5aae616ba30226f39c10b972e GitHub-Last-Rev: e52fc43658e9351538ad8484d81e892ff67a4914 GitHub-Pull-Request: golang/go#38228 Reviewed-on: https://go-review.googlesource.com/c/go/+/226984 Reviewed-by: Filippo Valsorda <filippo@golang.org> Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-07encoding/asn1: only accept minimally encoded base 128 integersRoland Shoemaker
Reject base 128 encoded integers that aren't using minimal encoding, specifically if the leading octet of an encoded integer is 0x80. This only affects parsing of tags and OIDs, both of which expect this encoding (see X.690 8.1.2.4.2 and 8.19.2). Fixes #36881 Change-Id: I969cf48ac1fba7e56bac334672806a0784d3e123 GitHub-Last-Rev: fefc03d2022e10b318e532ef5a461bb46016cf12 GitHub-Pull-Request: golang/go#38281 Reviewed-on: https://go-review.googlesource.com/c/go/+/227320 Reviewed-by: Filippo Valsorda <filippo@golang.org> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-08Revert "encoding/asn1: fix unmarshalling SEQUENCE OF SET"Than McIntosh
This reverts CL 160819 (commit 4692343cf401a5bbcc29) Reason for revert: causing lots of failures on master Change-Id: I96fd39ae80fe350ba8b3aa310443d41daec38093 Reviewed-on: https://go-review.googlesource.com/c/go/+/206146 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-11-08encoding/asn1: fix unmarshalling SEQUENCE OF SETkaxapi
Fixes #27426 Change-Id: I34d4784658ce7b9e6130bae9717e80d0e9a290a2 GitHub-Last-Rev: 6de610cdcef11832f131b84a0338b68af16b10da GitHub-Pull-Request: golang/go#30059 Reviewed-on: https://go-review.googlesource.com/c/go/+/160819 Reviewed-by: Agniva De Sarker <agniva.quicksilver@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Agniva De Sarker <agniva.quicksilver@gmail.com>
2019-09-09encoding/asn1: handle ASN1's string type BMPStringsergeilem
This code enables handling of ASN1's string type BMPString, used in some digital signatures. Parsing code taken from golang.org/x/crypto/pkcs12. Change-Id: Ibeae9cf4d8ae7c18f8b5420ad9244a16e117ff6b GitHub-Last-Rev: 694525351411f2ec3982a6bf4ac33be892ce1b12 GitHub-Pull-Request: golang/go#26690 Reviewed-on: https://go-review.googlesource.com/c/go/+/126624 Run-TryBot: Andrew Bonventre <andybons@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-11-02all: use "reports whether" consistently in the few places that didn'tBrad Fitzpatrick
Go documentation style for boolean funcs is to say: // Foo reports whether ... func Foo() bool (rather than "returns true if") This CL also replaces 4 uses of "iff" with the same "reports whether" wording, which doesn't lose any meaning, and will prevent people from sending typo fixes when they don't realize it's "if and only if". In the past I think we've had the typo CLs updated to just say "reports whether". So do them all at once. (Inspired by the addition of another "returns true if" in CL 146938 in fd_plan9.go) Created with: $ perl -i -npe 's/returns true if/reports whether/' $(git grep -l "returns true iff" | grep -v vendor) $ perl -i -npe 's/returns true if/reports whether/' $(git grep -l "returns true if" | grep -v vendor) Change-Id: Ided502237f5ab0d25cb625dbab12529c361a8b9f Reviewed-on: https://go-review.googlesource.com/c/147037 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-07encoding/asn1: gofmtTobias Klauser
CL 113837 introduced some changes which were not properly gofmt'ed, fix them. Change-Id: I89329063f9c468238051e45380d752e66efdb939 Reviewed-on: https://go-review.googlesource.com/116895 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-05-31encoding/asn1: fix returned type for an Object IdentifierConstantin Konstantinidis
Unmarshal/Marshal/Unmarshal was not idempotent as the Object Identifier type was not returned through the interface. The limit case OID = 0 returns an error. The zero OID is 0.0 A test is fixed to use the Object Identifier type. Other related test are added. Fixes #11130 Change-Id: I15483a3126066c9b99cf5bd9c4b0cc15ec1d61ca Reviewed-on: https://go-review.googlesource.com/113837 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2018-05-17encoding/asn1: allow Marshaling and Unmarshaling private tag classHAMANO Tsukasa
ASN.1 has an private class, but current implementation does not support it. Change-Id: I3ebf07a048831869572f75223cb17d4c115caef7 GitHub-Last-Rev: b3c69ad091218acfa0bb0e34111cceae69586eb9 GitHub-Pull-Request: golang/go#25195 Reviewed-on: https://go-review.googlesource.com/110561 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2017-12-05encoding/asn1: allow '&' in PrintableString fieldschristopher-henderson
There are, unfortunately, intermediate CA ceritificates in circulation that contain the invalid character '&' in some PrintableString fields, notably Organization Name. This patch allows for ampersand to be parsed as though it is valid in an ASN.1 PrintableString. Fixes #22970 Change-Id: Ifab1a10bbff1cdac68e843c6b857ff1a031051aa Reviewed-on: https://go-review.googlesource.com/81635 Reviewed-by: Adam Langley <agl@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Adam Langley <agl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-11-25encoding/asn1: support Unmarshaling NumericStringMansour Rahimi
ASN.1 has an specific string type, called NumericString (tag 18). The value of this type can be numeric characters (0-9) and space. Fixes #22396 Change-Id: Ia6d81ab7faa311ff22759bf76862626974d3013e Reviewed-on: https://go-review.googlesource.com/78655 Run-TryBot: Adam Langley <agl@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-16encoding/asn1: add MarshalWithParamsHiroshi Ioka
Fixes #18873 Change-Id: Idb9750f739f91ebca34efcbc177254d412b4d90d Reviewed-on: https://go-review.googlesource.com/44111 Reviewed-by: Adam Langley <agl@golang.org> Run-TryBot: Adam Langley <agl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-10-09encoding/asn1: don't encode strings with '*' as PrintableString.Adam Langley
The '*' character is not allowed in ASN.1 PrintableString. However, due to wide-spread use, we permit it so that we can parse many certificates with wildcards. However, that also meant that generic strings with asterisks in would be encoded as PrintableString. This change makes the default for such strings to be UTF8String. Thus, while the code PrintableStrings containing '*', it will not generate them unless the string type was specified in the struct field tag. Change-Id: I2d458da36649427352eeaa50a1b6020108b2ccbd Reviewed-on: https://go-review.googlesource.com/68990 Reviewed-by: Adam Langley <agl@golang.org>
2017-09-30encoding/asn1: respect “explicit” and “tag” when unmarshaling RawValues.Adam Langley
Previously, any “explicit” and/or “tag” decorations on a RawValue would be ignored when unmarshaling. The RawValue would swallow whatever element was encountered. This change causes these decorations to be respected. Thus a field like: Foo asn1.RawValue `asn1:"explicit,tag:1,optional"` will only match if an explicit tag with value one is encountered. Otherwise the RawValue will get the default value and parsing will move onto the next element. Thanks to Martin Kreichgauer for reporting the issue. Change-Id: If6c4488685b9bd039cb5e352d6d75744f98dbb1f Reviewed-on: https://go-review.googlesource.com/34503 Run-TryBot: Adam Langley <agl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
2017-09-15all: fix article typosKunpei Sakai
a -> an Change-Id: I7362bdc199e83073a712be657f5d9ba16df3077e Reviewed-on: https://go-review.googlesource.com/63850 Reviewed-by: Rob Pike <r@golang.org>
2017-08-23all: fix easy-to-miss typosAgniva De Sarker
Using the wonderful https://github.com/client9/misspell tool. Change-Id: Icdbc75a5559854f4a7a61b5271bcc7e3f99a1a24 Reviewed-on: https://go-review.googlesource.com/57851 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com> Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-08-15encoding/asn1: handle application tag in MarshalHiroshi Ioka
Fixes #20488 Change-Id: Iae963b612aea3d9e814b08f655e2eb019ece256e Reviewed-on: https://go-review.googlesource.com/44110 Reviewed-by: Adam Langley <agl@golang.org> Run-TryBot: Adam Langley <agl@golang.org>
2017-04-24encoding/asn1: add NullBytes and NullRawValue for working with ASN.1 NULLAndrew Benton
There were a number of places in crypto/x509 that used hardcoded representations of the ASN.1 NULL type, in both byte slice and RawValue struct forms. This change adds two new exported vars to the asn1 package for working with ASN.1 NULL in both its forms, and converts all usages from the x509 package. In addition, tests were added to exercise Marshal and Unmarshal on both vars. See #19446 for discussion. Change-Id: I63dbd0835841ccbc810bd6ec794360a84e933f1e Reviewed-on: https://go-review.googlesource.com/38660 Run-TryBot: Adam Langley <agl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
2017-04-13encoding/asn1: support 31 bit identifiers with OIDMonis Khan
The current implementation uses a max of 28 bits when decoding an ObjectIdentifier. This change makes it so that an int64 is used to accumulate up to 35 bits. If the resulting data would not overflow an int32, it is used as an int. Thus up to 31 bits may be used to represent each subidentifier of an ObjectIdentifier. Fixes #19933 Change-Id: I95d74b64b24cdb1339ff13421055bce61c80243c Reviewed-on: https://go-review.googlesource.com/40436 Reviewed-by: Adam Langley <agl@golang.org> Run-TryBot: Adam Langley <agl@golang.org>
2017-04-11encoding/asn1: document "utc" and "generalized" tagsHiroshi Ioka
Also reformat tables. Fixes #19889 Change-Id: I05083d2bab8bca46c4e22a415eb9b73513df6994 Reviewed-on: https://go-review.googlesource.com/40071 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-12-08all: make spelling consistentBrad Fitzpatrick
Fixes #17938 Change-Id: Iad12155f4976846bd4a9a53869f89e40e5b3deb3 Reviewed-on: https://go-review.googlesource.com/34147 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2016-11-03encoding/asn1: document that default:x tag only has meaning with optional tagRuss Cox
Fixes #16712. Change-Id: Ib216059c6c0c952162c19e080dcf3799f0652a8d Reviewed-on: https://go-review.googlesource.com/32171 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Quentin Smith <quentin@golang.org>
2016-11-03encoding/asn1: return error for unexported fields in Marshal, UnmarshalHiroshi Ioka
The old code cannot handle unexported fields, it panics. The new code returns error instead. Fixes #17462 Change-Id: I927fc46b21d60e86cb52e84c65f2122f9159b21d Reviewed-on: https://go-review.googlesource.com/31540 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2016-10-17encoding/asn1: return error instead of dereferencing nil *big.Int in marshalingHiroshi Ioka
Fixes #17461 Change-Id: I9954f6ae46c7e15560d7460841be8f2bc37233a9 Reviewed-on: https://go-review.googlesource.com/31121 Reviewed-by: Adam Langley <agl@golang.org> Run-TryBot: Adam Langley <agl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-09-13encoding/asn1: reduce allocations in MarshalHiroshi Ioka
Current code uses trees of bytes.Buffer as data representation. Each bytes.Buffer takes 4k bytes at least, so it's waste of memory. The change introduces trees of lazy-encoder as alternative one which reduce allocations. name old time/op new time/op delta Marshal-4 64.7µs ± 2% 42.0µs ± 1% -35.07% (p=0.000 n=9+10) name old alloc/op new alloc/op delta Marshal-4 35.1kB ± 0% 7.6kB ± 0% -78.27% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Marshal-4 503 ± 0% 293 ± 0% -41.75% (p=0.000 n=10+10) Change-Id: I32b96c20b8df00414b282d69743d71a598a11336 Reviewed-on: https://go-review.googlesource.com/27030 Reviewed-by: Adam Langley <agl@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Adam Langley <agl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-15all: remove unnecessary type conversionsMatthew Dempsky
cmd and runtime were handled separately, and I'm intentionally skipped syscall. This is the rest of the standard library. CL generated mechanically with github.com/mdempsky/unconvert. Change-Id: I9e0eff886974dedc37adb93f602064b83e469122 Reviewed-on: https://go-review.googlesource.com/22104 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-10all: replace magic 0x80 with named constant utf8.RuneSelfMartin Möhrmann
Change-Id: Id1c2e8e9d60588de866e8b6ca59cc83dd28f848f Reviewed-on: https://go-review.googlesource.com/21756 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-25encoding/asn1: tags should be encoded in minimal form.David Benjamin
High tag number form may not be used for tag numbers that fit in low tag number form. Change-Id: I93edde0e1f86087047e0b3f2e55d6180b01e78bf Reviewed-on: https://go-review.googlesource.com/18224 Reviewed-by: Adam Langley <agl@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2016-03-02all: single space after period.Brad Fitzpatrick
The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-01-06encoding/asn1: fix off-by-one in parseBase128Int.David Benjamin
parseBase128Int compares |shifted| with four, seemingly to ensure the result fits in an int32 on 32-bit platforms where int is 32-bit. However, there is an off-by-one in this logic, so it actually allows five shifts, making the maximum tag number or OID component 2^35-1. Fix this so the maximum is 2^28-1 which should be plenty for OID components and tag numbers while not overflowing on 32-bit platforms. Change-Id: If825b30cc53a0fc08e68ea1a24d265e7eb1a13a4 Reviewed-on: https://go-review.googlesource.com/18225 Reviewed-by: Adam Langley <agl@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2015-12-03encoding/asn1: export tag and class constantsBrad Fitzpatrick
Fixes #9236 Change-Id: I744d7f071e945ea6e6e50203d931f4678c8b545d Reviewed-on: https://go-review.googlesource.com/17311 Reviewed-by: Adam Langley <agl@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-12-01encoding/asn1: Reject invalid INTEGERs.David Benjamin
The empty string is not a valid DER integer. DER also requires that values be minimally-encoded, so excess padding with leading 0s (0xff for negative numbers) is forbidden. (These rules also apply to BER, incidentally.) Fixes #12622. Change-Id: I041f94e34a8afa29dbf94dd8fc450944bc91c9c3 Reviewed-on: https://go-review.googlesource.com/17008 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-11-18encoding/asn1: enforce use of short form lengths.David Benjamin
BER allows the sender to choose either short form or long form where both are legal, but DER requires the minimal one be used. Enforce this and add a test. Fix one test which was not minimally-encoded and another which would not distinguish rejecting the input because the long form length wasn't minimally-encoded from rejecting it because long form was chosen when short form was allowed. Change-Id: I1b56fcca594dcdeddea9378b4fab427cbe7cd26d Reviewed-on: https://go-review.googlesource.com/16517 Reviewed-by: Adam Langley <agl@golang.org> Run-TryBot: Adam Langley <agl@golang.org>
2015-11-10html/template, encoding/asn1: fix test errorsDominik Honnef
Change-Id: I1da1d718609eb6a7b78d29b173ec780bde22c687 Reviewed-on: https://go-review.googlesource.com/16422 Reviewed-by: Ralph Corderoy <ralph@inputplus.co.uk> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-08-29encoding/asn1: fix panic when Marshaling nil.Michal Bohuslávek
Fixes #11127. Change-Id: Ibcfc3a05e91fa4260d70b04bee2bbba2376bd313 Reviewed-on: https://go-review.googlesource.com/13923 Reviewed-by: Adam Langley <agl@golang.org>
2015-08-24encoding/asn1: fix unused assignmentsTarmigan Casebolt
Unused assignment for `err` encoding/asn1/marshal.go:622:3 Unused assignment for `err` encoding/asn1/marshal.go:650:5 Change-Id: I4226238645ce3640f25124cb405444e61439fd3f Reviewed-on: https://go-review.googlesource.com/13847 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-06-29encoding/asn1: don't parse invalid UTF-8.Adam Langley
Invalid UTF-8 triggers an error when marshaling but, previously, not when unmarshaling. This means that ASN.1 structures were not round-tripping. This change makes invalid UTF-8 in a string marked as UTF-8 to be an error when Unmarshaling. Fixes #11126. Change-Id: Ic37be84d21dc5c03983525e244d955a8b1e1ff14 Reviewed-on: https://go-review.googlesource.com/11056 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-29encoding/asn1: be stricter by reserialising parsed times.Adam Langley
The time package does normalisation of times: for example day zero is converted to the last day of the previous month and the 31st of February is moved into March etc. This makes the ASN.1 parsing a little worryingly lax. This change causes the parser to reserialise parsed times to ensure that they round-trip correctly and thus were not normalised. Fixes #11134. Change-Id: I3988bb95153a7b33d64ab861fbe51b1a34a359e9 Reviewed-on: https://go-review.googlesource.com/11094 Run-TryBot: Adam Langley <agl@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-13encoding/asn1: check bounds when parsing tag and lengthKyle Isom
This was found while fuzzing another program, triggering a panic in x509.ParseECPrivateKey. Fixes #11154 Change-Id: Ief35ead38adf14caec4d37b9eacf8a92e67cd1e6 Reviewed-on: https://go-review.googlesource.com/10712 Reviewed-by: Adam Langley <agl@golang.org> Run-TryBot: Adam Langley <agl@golang.org>
2015-04-28encoding/asn1: Improved control of flags and timesRichard Barnes
This change corrects the serialization of asn1.Flag values, so that when set, they serialize to an empty value, and when unset, they are omitted. It also adds a format parameter that allows calling code to control whether time.Time values are serialized as UTCTime or GeneralizedTime. Change-Id: I6d97abf009ea317338dab30c80f35a2de7e07104 Reviewed-on: https://go-review.googlesource.com/5970 Reviewed-by: Adam Langley <agl@golang.org> Run-TryBot: Adam Langley <agl@golang.org>
2015-03-24debug/dwarf, encoding/asn1, go/ast: fix old commentsMatthew Dempsky
The debug/dwarf and encoding/asn1 examples were added in 2009, a few months before Go added implicit semicolons, and never updated. The go/ast node types have always been named just "Expr", "Stmt", and "Decl", so the comments about "ExprNode", "StmtNode", and "DeclNode" were likely just mistaken because the interface tag methods are "exprNode", "stmtNode", and "declNode", respectively. Change-Id: I9d138cc3a16c1a51453da1406914d7b320bf6270 Reviewed-on: https://go-review.googlesource.com/7980 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-03-18all: use "reports whether" in place of "returns true if(f)"Josh Bleecher Snyder
Comment changes only. Change-Id: I56848814564c4aa0988b451df18bebdfc88d6d94 Reviewed-on: https://go-review.googlesource.com/7721 Reviewed-by: Rob Pike <r@golang.org>