aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/asn1
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2020-10-14 18:41:16 -0700
committerJoe Tsai <thebrokentoaster@gmail.com>2021-02-25 21:21:51 +0000
commitb83d073e9eb4cbd0cd5ca530f576668c49f6d0f1 (patch)
treef706562328a6ff09eec8117618bc5edb100b2466 /src/encoding/asn1
parent7fcf9893f71c75f6b2fd53bea326d5061f705208 (diff)
downloadgo-b83d073e9eb4cbd0cd5ca530f576668c49f6d0f1.tar.gz
go-b83d073e9eb4cbd0cd5ca530f576668c49f6d0f1.zip
reflect: add Method.IsExported and StructField.IsExported methods
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>
Diffstat (limited to 'src/encoding/asn1')
-rw-r--r--src/encoding/asn1/asn1.go2
-rw-r--r--src/encoding/asn1/marshal.go2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/encoding/asn1/asn1.go b/src/encoding/asn1/asn1.go
index f9b9cb4930..cffc06dc9c 100644
--- a/src/encoding/asn1/asn1.go
+++ b/src/encoding/asn1/asn1.go
@@ -914,7 +914,7 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
structType := fieldType
for i := 0; i < structType.NumField(); i++ {
- if structType.Field(i).PkgPath != "" {
+ if !structType.Field(i).IsExported() {
err = StructuralError{"struct contains unexported fields"}
return
}
diff --git a/src/encoding/asn1/marshal.go b/src/encoding/asn1/marshal.go
index 0d34d5aa1e..5b4d786d49 100644
--- a/src/encoding/asn1/marshal.go
+++ b/src/encoding/asn1/marshal.go
@@ -488,7 +488,7 @@ func makeBody(value reflect.Value, params fieldParameters) (e encoder, err error
t := v.Type()
for i := 0; i < t.NumField(); i++ {
- if t.Field(i).PkgPath != "" {
+ if !t.Field(i).IsExported() {
return nil, StructuralError{"struct contains unexported fields"}
}
}