Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2017 DTCC, Fujitsu Australia Software Technology, IBM - 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.
*/
package org.hyperledger.fabric.sdk;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import io.netty.util.internal.StringUtil;
import org.apache.commons.io.IOUtils;
import org.hyperledger.fabric.protos.common.MspPrincipal.MSPPrincipal;
import org.hyperledger.fabric.protos.common.MspPrincipal.MSPRole;
import org.hyperledger.fabric.protos.common.Policies;
import org.hyperledger.fabric.protos.common.Policies.SignaturePolicy;
import org.hyperledger.fabric.sdk.exception.ChaincodeEndorsementPolicyParseException;
import org.yaml.snakeyaml.Yaml;
import static java.lang.String.format;
/**
* A wrapper for the Hyperledger Fabric Policy object
*/
public class ChaincodeEndorsementPolicy {
private static final Pattern noofPattern = Pattern.compile("^(\\d+)-of$");
private byte[] policyBytes = null;
/**
* The null constructor for the ChaincodeEndorsementPolicy wrapper. You will
* need to use the {@link #fromBytes(byte[])} method to
* populate the policy
*/
public ChaincodeEndorsementPolicy() {
}
private static SignaturePolicy parsePolicy(IndexedHashMap identities, Map, ?> mp) throws ChaincodeEndorsementPolicyParseException {
if (mp == null) {
throw new ChaincodeEndorsementPolicyParseException("No policy section was found in the document.");
}
if (!(mp instanceof Map)) {
throw new ChaincodeEndorsementPolicyParseException("Policy expected object section was not found in the document.");
}
for (Map.Entry, ?> ks : mp.entrySet()) {
Object ko = ks.getKey();
Object vo = ks.getValue();
final String key = (String) ko;
// String val = (String) vo;
if ("signed-by".equals(key)) {
if (!(vo instanceof String)) {
throw new ChaincodeEndorsementPolicyParseException("signed-by expecting a string value");
}
MSPPrincipal mspPrincipal = identities.get(vo);
if (null == mspPrincipal) {
throw new ChaincodeEndorsementPolicyParseException(format("No identity found by name %s in signed-by.", vo));
}
return SignaturePolicy.newBuilder()
.setSignedBy(identities.getKeysIndex((String) vo))
.build();
} else {
Matcher match = noofPattern.matcher(key);
if (match.matches() && match.groupCount() == 1) {
String matchStingNo = match.group(1).trim();
int matchNo = Integer.parseInt(matchStingNo);
if (!(vo instanceof List)) {
throw new ChaincodeEndorsementPolicyParseException(format("%s expected to have list but found %s.", key, String.valueOf(vo)));
}
@SuppressWarnings ("unchecked") final List