// MarshalPublicKey converts a public key object into a protobuf serialized // public key func MarshalPublicKey(k PubKey) ([]byte, error) { b, err := MarshalRsaPublicKey(k.(*RsaPublicKey)) if err != nil { return nil, err } pmes := new(pb.PublicKey) typ := pb.KeyType_RSA // for now only type. pmes.Type = &typ pmes.Data = b return proto.Marshal(pmes) }
func (pk *RsaPublicKey) Bytes() ([]byte, error) { b, err := x509.MarshalPKIXPublicKey(pk.k) if err != nil { return nil, err } pbmes := new(pb.PublicKey) typ := pb.KeyType_RSA pbmes.Type = &typ pbmes.Data = b return proto.Marshal(pbmes) }
//Encode into a protobuf func MarshalAccount(acc Account) ([]byte, error) { accpb := new(pb.Account) // make proto account accpb.RegistrationDate = &acc.RegistrationDate //Gather up Private key3 cPrivData := crypto.MarshalRsaPrivateKey(acc.PrivKey.(*crypto.RsaPrivateKey)) cPrivK := new(keypb.PrivateKey) typ := keypb.KeyType_RSA cPrivK.Type = &typ cPrivK.Data = cPrivData accpb.PrivKey = cPrivK // add proto private key //Gather up Public key cPubData, err2 := crypto.MarshalRsaPublicKey(acc.PubKey.(*crypto.RsaPublicKey)) if err2 != nil { return nil, err2 } cPubK := new(keypb.PublicKey) cPubK.Type = &typ cPubK.Data = cPubData accpb.PubKey = cPubK // add proto public key //Do the damn thing return proto.Marshal(accpb) //Explosions }