]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/compile/internal/reflectdata/reflect.go
[dev.boringcrypto] all: merge commit 9d0819b27c (CL 314609) into dev.boringcrypto
[gostls13.git] / src / cmd / compile / internal / reflectdata / reflect.go
index 01eaf26a0a62e905ce8ff79c6402a2870244d8ed..034a092d6ceaac88f05b164b598cc3097a043c15 100644 (file)
@@ -1130,6 +1130,33 @@ func writeType(t *types.Type) *obj.LSym {
        // for security, only the exported fields.
        case types.TSTRUCT:
                fields := t.Fields().Slice()
+
+               // omitFieldForAwfulBoringCryptoKludge reports whether
+               // the field t should be omitted from the reflect data.
+               // In the crypto/... packages we omit an unexported field
+               // named "boring", to keep from breaking client code that
+               // expects rsa.PublicKey etc to have only public fields.
+               // As the name suggests, this is an awful kludge, but it is
+               // limited to the dev.boringcrypto branch and avoids
+               // much more invasive effects elsewhere.
+               omitFieldForAwfulBoringCryptoKludge := func(t *types.Field) bool {
+                       if t.Sym == nil || t.Sym.Name != "boring" || t.Sym.Pkg == nil {
+                               return false
+                       }
+                       path := t.Sym.Pkg.Path
+                       if t.Sym.Pkg == types.LocalPkg {
+                               path = base.Ctxt.Pkgpath
+                       }
+                       return strings.HasPrefix(path, "crypto/")
+               }
+               newFields := fields[:0:0]
+               for _, t1 := range fields {
+                       if !omitFieldForAwfulBoringCryptoKludge(t1) {
+                               newFields = append(newFields, t1)
+                       }
+               }
+               fields = newFields
+
                for _, t1 := range fields {
                        writeType(t1.Type)
                }