move envelope to record package.

This commit is contained in:
Raúl Kripalani 2019-12-27 20:09:43 +00:00 committed by Yusef Napora
parent 6028ba0bba
commit 123324dc1b
2 changed files with 9 additions and 8 deletions

View File

@ -1,14 +1,15 @@
package crypto package record
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/gogo/protobuf/proto"
pool "github.com/libp2p/go-buffer-pool" pool "github.com/libp2p/go-buffer-pool"
"github.com/libp2p/go-libp2p-core/crypto"
pb "github.com/libp2p/go-libp2p-core/crypto/pb" pb "github.com/libp2p/go-libp2p-core/crypto/pb"
"github.com/gogo/protobuf/proto"
"github.com/multiformats/go-varint" "github.com/multiformats/go-varint"
) )
@ -20,7 +21,7 @@ import (
// and access the payload. // and access the payload.
type SignedEnvelope struct { type SignedEnvelope struct {
// The public key that can be used to verify the signature and derive the peer id of the signer. // The public key that can be used to verify the signature and derive the peer id of the signer.
PublicKey PubKey PublicKey crypto.PubKey
// A binary identifier that indicates what kind of data is contained in the payload. // A binary identifier that indicates what kind of data is contained in the payload.
// TODO(yusef): enforce multicodec prefix // TODO(yusef): enforce multicodec prefix
@ -42,7 +43,7 @@ var ErrInvalidSignature = errors.New("invalid signature or incorrect domain")
// and must be supplied when verifying the signature. // and must be supplied when verifying the signature.
// //
// The 'PayloadType' field indicates what kind of data is contained and may be empty. // The 'PayloadType' field indicates what kind of data is contained and may be empty.
func MakeEnvelope(privateKey PrivKey, domain string, payloadType []byte, payload []byte) (*SignedEnvelope, error) { func MakeEnvelope(privateKey crypto.PrivKey, domain string, payloadType []byte, payload []byte) (*SignedEnvelope, error) {
if domain == "" { if domain == "" {
return nil, ErrEmptyDomain return nil, ErrEmptyDomain
} }
@ -86,7 +87,7 @@ func UnmarshalEnvelope(data []byte) (*SignedEnvelope, error) {
return nil, err return nil, err
} }
key, err := PublicKeyFromProto(e.PublicKey) key, err := crypto.PublicKeyFromProto(e.PublicKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -102,7 +103,7 @@ func UnmarshalEnvelope(data []byte) (*SignedEnvelope, error) {
// Marshal returns a byte slice containing a serialized protobuf representation // Marshal returns a byte slice containing a serialized protobuf representation
// of a SignedEnvelope. // of a SignedEnvelope.
func (e *SignedEnvelope) Marshal() ([]byte, error) { func (e *SignedEnvelope) Marshal() ([]byte, error) {
key, err := PublicKeyToProto(e.PublicKey) key, err := crypto.PublicKeyToProto(e.PublicKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,4 +1,4 @@
package crypto_test package record
import ( import (
"bytes" "bytes"