diff --git a/msp/msp.go b/msp/msp.go index 4cf63a39fea..d21f8f6929b 100644 --- a/msp/msp.go +++ b/msp/msp.go @@ -203,16 +203,19 @@ const ( OTHER // MSP is of OTHER TYPE // NOTE: as new types are added to this set, - // the mspTypes array below must be extended + // the mspTypes map below must be extended ) -var mspTypeStrings []string = []string{"bccsp", "idemix"} +var mspTypeStrings = map[ProviderType]string{ + FABRIC: "bccsp", + IDEMIX: "idemix", +} // ProviderTypeToString returns a string that represents the ProviderType integer func ProviderTypeToString(id ProviderType) string { - if int(id) < 0 || int(id) > len(mspTypeStrings) { - return "" + if res, found := mspTypeStrings[id]; found { + return res } - return mspTypeStrings[id] + return "" } diff --git a/msp/msp_test.go b/msp/msp_test.go index 94ee133522a..12e17e9b147 100644 --- a/msp/msp_test.go +++ b/msp/msp_test.go @@ -1341,3 +1341,17 @@ func TestAnonymityIdentityFail(t *testing.T) { err = id.SatisfiesPrincipal(principal) assert.Error(t, err) } + +func TestProviderTypeToString(t *testing.T) { + // Check that the provider type is found for FABRIC + pt := ProviderTypeToString(FABRIC) + assert.Equal(t, "bccsp", pt) + + // Check that the provider type is found for IDEMIX + pt = ProviderTypeToString(IDEMIX) + assert.Equal(t, "idemix", pt) + + // Check that the provider type is not found + pt = ProviderTypeToString(OTHER) + assert.Equal(t, "", pt) +}