PolicyIdentifiers []asn1.ObjectIdentifier
// Policies contains all policy identifiers included in the certificate.
+ // In Go 1.22, encoding/gob cannot handle and ignores this field.
Policies []OID
}
"crypto/x509/pkix"
"encoding/asn1"
"encoding/base64"
+ "encoding/gob"
"encoding/hex"
"encoding/pem"
"fmt"
t.Errorf("cert.Policies = %v, want: %v", cert.Policies, expectPolicies)
}
}
+
+func TestGob(t *testing.T) {
+ // Test that gob does not reject Certificate.
+ // See go.dev/issue/65633.
+ cert := new(Certificate)
+ err := gob.NewEncoder(io.Discard).Encode(cert)
+ if err != nil {
+ t.Fatal(err)
+ }
+}
if ut.externalEnc == 0 && srt.Kind() == reflect.Struct {
for fieldNum, wireFieldNum := 0, 0; fieldNum < srt.NumField(); fieldNum++ {
f := srt.Field(fieldNum)
- if !isSent(&f) {
+ if !isSent(srt, &f) {
continue
}
op, indir := encOpFor(f.Type, seen, building)
idToTypeSlice[st.id()] = st
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
- if !isSent(&f) {
+ if !isSent(t, &f) {
continue
}
typ := userType(f.Type).base
// isSent reports whether this struct field is to be transmitted.
// It will be transmitted only if it is exported and not a chan or func field
// or pointer to chan or func.
-func isSent(field *reflect.StructField) bool {
+func isSent(struct_ reflect.Type, field *reflect.StructField) bool {
if !isExported(field.Name) {
return false
}
if typ.Kind() == reflect.Chan || typ.Kind() == reflect.Func {
return false
}
+
+ // Special case for Go 1.22: the x509.Certificate.Policies
+ // field is unencodable but also unused by default.
+ // Ignore it, so that x509.Certificate continues to be encodeable.
+ // Go 1.23 will add the right methods so that gob can
+ // handle the Policies field, and then we can remove this check.
+ // See go.dev/issue/65633.
+ if field.Name == "Policies" && struct_.PkgPath() == "crypto/x509" && struct_.Name() == "Certificate" {
+ return false
+ }
+
return true
}