It looks like adding the x509.OID type and associated fields to the x509.Certificate struct breaks the ability to gob-encode the certificate. The following test program succeeds on go 1.21.6 and fails on 1.22.0:
package main
import (
"log"
"bytes"
"encoding/gob"
"crypto/x509"
"crypto/rsa"
"crypto/dsa"
"crypto/ecdh"
"crypto/ecdsa"
"crypto/ed25519"
)
func init() {
gob.Register(rsa.PrivateKey{})
gob.Register(dsa.PrivateKey{})
gob.Register(ecdh.PrivateKey{})
gob.Register(ecdsa.PrivateKey{})
gob.Register(ed25519.PrivateKey{})
gob.Register(rsa.PublicKey{})
gob.Register(dsa.PublicKey{})
gob.Register(ecdh.PublicKey{})
gob.Register(ecdsa.PublicKey{})
gob.Register(ed25519.PublicKey{})
}
func main() {
c := &x509.Certificate{}
b := &bytes.Buffer{}
enc := gob.NewEncoder(b)
if err := enc.Encode(c); err != nil {
log.Printf("Failed to gob encode empty x.509 cert: %v", err)
} else {
log.Printf("Encoded empty x.509 cert")
}
}
It looks like the x509.OID type is not able to be marshalled by gob since it is a struct that contains a single unexported field, and it doesn't implement text or binary marshalling.