Skip to content

Commit

Permalink
use Google's Protobuf library instead of GoGo
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Jan 4, 2023
1 parent 756e1c9 commit 22ac18c
Show file tree
Hide file tree
Showing 45 changed files with 3,107 additions and 9,177 deletions.
25 changes: 13 additions & 12 deletions core/crypto/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import (
"fmt"
"io"

pb "github.com/libp2p/go-libp2p/core/crypto/pb"
"github.com/libp2p/go-libp2p/core/crypto/pb"

"github.com/gogo/protobuf/proto"
"google.golang.org/protobuf/proto"
)

//go:generate protoc --go_out=. --go_opt=Mpb/crypto.proto=./pb pb/crypto.proto

const (
// RSA is an enum for the supported RSA key type
RSA = iota
Expand Down Expand Up @@ -194,7 +196,7 @@ func PublicKeyFromProto(pmes *pb.PublicKey) (PubKey, error) {

switch tpk := pk.(type) {
case *RsaPublicKey:
tpk.cached, _ = pmes.Marshal()
tpk.cached, _ = proto.Marshal(pmes)
}

return pk, nil
Expand All @@ -214,14 +216,14 @@ func MarshalPublicKey(k PubKey) ([]byte, error) {
// PublicKeyToProto converts a public key object into an unserialized
// protobuf PublicKey message.
func PublicKeyToProto(k PubKey) (*pb.PublicKey, error) {
pbmes := new(pb.PublicKey)
pbmes.Type = k.Type()
data, err := k.Raw()
if err != nil {
return nil, err
}
pbmes.Data = data
return pbmes, nil
return &pb.PublicKey{
Type: k.Type().Enum(),
Data: data,
}, nil
}

// UnmarshalPrivateKey converts a protobuf serialized private key into its
Expand All @@ -243,15 +245,14 @@ func UnmarshalPrivateKey(data []byte) (PrivKey, error) {

// MarshalPrivateKey converts a key object into its protobuf serialized form.
func MarshalPrivateKey(k PrivKey) ([]byte, error) {
pbmes := new(pb.PrivateKey)
pbmes.Type = k.Type()
data, err := k.Raw()
if err != nil {
return nil, err
}

pbmes.Data = data
return proto.Marshal(pbmes)
return proto.Marshal(&pb.PrivateKey{
Type: k.Type().Enum(),
Data: data,
})
}

// ConfigDecodeKey decodes from b64 (for config file) to a byte array that can be unmarshalled.
Expand Down
11 changes: 0 additions & 11 deletions core/crypto/pb/Makefile

This file was deleted.

Loading

0 comments on commit 22ac18c

Please sign in to comment.