|
1 | 1 | /*
|
2 |
| -Copyright IBM Corp. 2017 All Rights Reserved. |
| 2 | +Copyright IBM Corp. All Rights Reserved. |
3 | 3 |
|
4 |
| -Licensed under the Apache License, Version 2.0 (the "License"); |
5 |
| -you may not use this file except in compliance with the License. |
6 |
| -You may obtain a copy of the License at |
7 |
| -
|
8 |
| - http://www.apache.org/licenses/LICENSE-2.0 |
9 |
| -
|
10 |
| -Unless required by applicable law or agreed to in writing, software |
11 |
| -distributed under the License is distributed on an "AS IS" BASIS, |
12 |
| -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 |
| -See the License for the specific language governing permissions and |
14 |
| -limitations under the License. |
| 4 | +SPDX-License-Identifier: Apache-2.0 |
15 | 5 | */
|
16 | 6 |
|
17 | 7 | package msp
|
18 | 8 |
|
19 | 9 | import (
|
| 10 | + "encoding/pem" |
20 | 11 | "fmt"
|
21 | 12 | "io/ioutil"
|
22 |
| - |
23 |
| - "github.com/golang/protobuf/proto" |
24 |
| - |
25 |
| - "encoding/pem" |
26 |
| - "path/filepath" |
27 |
| - |
28 | 13 | "os"
|
| 14 | + "path/filepath" |
29 | 15 |
|
| 16 | + "github.com/golang/protobuf/proto" |
30 | 17 | "github.com/hyperledger/fabric/bccsp"
|
31 | 18 | "github.com/hyperledger/fabric/bccsp/factory"
|
32 | 19 | "github.com/hyperledger/fabric/protos/msp"
|
| 20 | + "github.com/pkg/errors" |
33 | 21 | "gopkg.in/yaml.v2"
|
34 | 22 | )
|
35 | 23 |
|
@@ -276,3 +264,25 @@ func getMspConfig(dir string, ID string, sigid *msp.SigningIdentityInfo) (*msp.M
|
276 | 264 |
|
277 | 265 | return mspconf, nil
|
278 | 266 | }
|
| 267 | + |
| 268 | +// IdemixConfig is the filename of the idemix msp config file |
| 269 | +const IdemixConfig = "idemixmspconfig" |
| 270 | + |
| 271 | +// GetIdemixMspConfig returns the configuration for the Idemix MSP |
| 272 | +func GetIdemixMspConfig(dir string) (*msp.MSPConfig, error) { |
| 273 | + confStringBytes, err := readFile(filepath.Join(dir, IdemixConfig)) |
| 274 | + if err != nil { |
| 275 | + return nil, errors.Wrapf(err, "error reading idemix config file") |
| 276 | + } |
| 277 | + config := &msp.IdemixMSPConfig{} |
| 278 | + err = proto.UnmarshalText(string(confStringBytes), config) |
| 279 | + if err != nil { |
| 280 | + return nil, errors.Wrapf(err, "error unmarshalling idemix config") |
| 281 | + } |
| 282 | + confBytes, err := proto.Marshal(config) |
| 283 | + if err != nil { |
| 284 | + return nil, errors.Wrapf(err, "error creating idemix config") |
| 285 | + } |
| 286 | + |
| 287 | + return &msp.MSPConfig{Config: confBytes, Type: int32(IDEMIX)}, nil |
| 288 | +} |
0 commit comments