Skip to content

Commit

Permalink
Merge "Use protobufs to serialize identities"
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanLevi authored and Gerrit Code Review committed Dec 15, 2016
2 parents 21a1d1b + 8c97f46 commit ccb94c5
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 21 deletions.
7 changes: 3 additions & 4 deletions msp/identities.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ import (

"encoding/pem"

"encoding/asn1"

"errors"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/crypto/bccsp"
"github.com/hyperledger/fabric/core/crypto/bccsp/signer"
)
Expand Down Expand Up @@ -115,8 +114,8 @@ func (id *identity) Serialize() ([]byte, error) {
}

// We serialize identities by prepending the MSPID and appending the ASN.1 DER content of the cert
sId := SerializedIdentity{Mspid: id.id.Mspid, IdBytes: pemBytes}
idBytes, err := asn1.Marshal(sId)
sId := &SerializedIdentity{Mspid: id.id.Mspid, IdBytes: pemBytes}
idBytes, err := proto.Marshal(sId)
if err != nil {
return nil, fmt.Errorf("Could not marshal a SerializedIdentity structure for identity %s, err %s", id.id, err)
}
Expand Down
63 changes: 63 additions & 0 deletions msp/identities.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions msp/identities.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

syntax = "proto3";

option go_package = "github.com/hyperledger/fabric/msp";

package msp;

// This struct represents an Identity
// (with its MSP identifier) to be used
// to serialize it and deserialize it
message SerializedIdentity {
// The identifier of the associated membership service provider
string Mspid = 1;

// the Identity, serialized according to the rules of its MPS
bytes IdBytes = 2;
}
11 changes: 0 additions & 11 deletions msp/msp.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,3 @@ const (
FABRIC ProviderType = iota // MSP is of FABRIC type
OTHER // MSP is of OTHER TYPE
)

// This struct represents an Identity
// (with its MSP identifier) to be used
// to serialize it and deserialize it
type SerializedIdentity struct {
// The identifier of the associated membership service provider
Mspid string

// the Identity, serialized according to the rules of its MPS
IdBytes []byte
}
5 changes: 2 additions & 3 deletions msp/mspimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import (

"encoding/json"

"encoding/asn1"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/crypto/bccsp"
"github.com/hyperledger/fabric/core/crypto/bccsp/signer"
"github.com/hyperledger/fabric/core/crypto/bccsp/sw"
Expand Down Expand Up @@ -263,7 +262,7 @@ func (msp *bccspmsp) DeserializeIdentity(serializedID []byte) (Identity, error)

// We first deserialize to a SerializedIdentity to get the MSP ID
sId := &SerializedIdentity{}
_, err := asn1.Unmarshal(serializedID, sId)
err := proto.Unmarshal(serializedID, sId)
if err != nil {
return nil, fmt.Errorf("Could not deserialize a SerializedIdentity, err %s", err)
}
Expand Down
5 changes: 2 additions & 3 deletions msp/mspmgrimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ package msp
import (
"fmt"

"encoding/asn1"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/protos/msp"
"github.com/op/go-logging"
)
Expand Down Expand Up @@ -106,7 +105,7 @@ func (mgr *mspManagerImpl) GetMSPs() (map[string]MSP, error) {
func (mgr *mspManagerImpl) DeserializeIdentity(serializedID []byte) (Identity, error) {
// We first deserialize to a SerializedIdentity to get the MSP ID
sId := &SerializedIdentity{}
_, err := asn1.Unmarshal(serializedID, sId)
err := proto.Unmarshal(serializedID, sId)
if err != nil {
return nil, fmt.Errorf("Could not deserialize a SerializedIdentity, err %s", err)
}
Expand Down

0 comments on commit ccb94c5

Please sign in to comment.