User-visible regression in the x509.Certificate struct from go 1.21.6 to 1.22.0

57 views
Skip to first unread message

Victor Lowther

unread,
Feb 8, 2024, 4:26:24 PM2/8/24
to golang-nuts
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.
Reply all
Reply to author
Forward
0 new messages