use of org.hyperledger.fabric.sdk.exception.InvalidArgumentException in project fabric-sdk-java by hyperledger.
the class CryptoPrimitives method setSecurityLevel.
// validateCertificate
/**
* Security Level determines the elliptic curve used in key generation
*
* @param securityLevel currently 256 or 384
* @throws InvalidArgumentException
*/
void setSecurityLevel(final int securityLevel) throws InvalidArgumentException {
logger.trace(format("setSecurityLevel to %d", securityLevel));
if (securityCurveMapping.isEmpty()) {
throw new InvalidArgumentException("Security curve mapping has no entries.");
}
if (!securityCurveMapping.containsKey(securityLevel)) {
StringBuilder sb = new StringBuilder();
String sp = "";
for (int x : securityCurveMapping.keySet()) {
sb.append(sp).append(x);
sp = ", ";
}
throw new InvalidArgumentException(format("Illegal security level: %d. Valid values are: %s", securityLevel, sb.toString()));
}
String lcurveName = securityCurveMapping.get(securityLevel);
logger.debug(format("Mapped curve strength %d to %s", securityLevel, lcurveName));
X9ECParameters params = ECNamedCurveTable.getByName(lcurveName);
// Check if can match curve name to requested strength.
if (params == null) {
InvalidArgumentException invalidArgumentException = new InvalidArgumentException(format("Curve %s defined for security strength %d was not found.", curveName, securityLevel));
logger.error(invalidArgumentException);
throw invalidArgumentException;
}
curveName = lcurveName;
this.securityLevel = securityLevel;
}
use of org.hyperledger.fabric.sdk.exception.InvalidArgumentException in project fabric-sdk-java by hyperledger.
the class InstantiateProposalBuilder method createNetModeTransaction.
private void createNetModeTransaction() throws InvalidArgumentException {
logger.debug("NetModeTransaction");
if (chaincodeType == null) {
throw new InvalidArgumentException("Chaincode type is required");
}
List<String> modlist = new LinkedList<>();
modlist.add("init");
modlist.addAll(argList);
switch(chaincodeType) {
case JAVA:
ccType(Chaincode.ChaincodeSpec.Type.JAVA);
break;
case NODE:
ccType(Chaincode.ChaincodeSpec.Type.NODE);
break;
case GO_LANG:
ccType(Chaincode.ChaincodeSpec.Type.GOLANG);
break;
default:
throw new InvalidArgumentException("Requested chaincode type is not supported: " + chaincodeType);
}
ChaincodeDeploymentSpec depspec = createDeploymentSpec(ccType, chaincodeName, chaincodePath, chaincodeVersion, modlist, null);
List<ByteString> argList = new ArrayList<>();
argList.add(ByteString.copyFrom(action, StandardCharsets.UTF_8));
argList.add(ByteString.copyFrom(context.getChannelID(), StandardCharsets.UTF_8));
argList.add(depspec.toByteString());
if (chaincodePolicy != null) {
argList.add(ByteString.copyFrom(chaincodePolicy));
}
args(argList);
}
use of org.hyperledger.fabric.sdk.exception.InvalidArgumentException in project fabric-sdk-java by hyperledger.
the class ProposalResponse method getChaincodeActionResponsePayload.
/**
* ChaincodeActionResponsePayload is the result of the executing chaincode.
*
* @return the result of the executing chaincode.
* @throws InvalidArgumentException
*/
public byte[] getChaincodeActionResponsePayload() throws InvalidArgumentException {
if (isInvalid()) {
throw new InvalidArgumentException("Proposal response is invalid.");
}
try {
final ProposalResponsePayloadDeserializer proposalResponsePayloadDeserializer = getProposalResponsePayloadDeserializer();
ByteString ret = proposalResponsePayloadDeserializer.getExtension().getChaincodeAction().getResponse().getPayload();
if (null == ret) {
return null;
}
return ret.toByteArray();
} catch (InvalidArgumentException e) {
throw e;
} catch (Exception e) {
throw new InvalidArgumentException(e);
}
}
use of org.hyperledger.fabric.sdk.exception.InvalidArgumentException in project fabric-sdk-java by hyperledger.
the class ProposalResponse method getChaincodeID.
// public ByteString getPayload() {
// return proposalResponse.getPayload();
// }
/**
* Chaincode ID that was executed.
*
* @return See {@link ChaincodeID}
* @throws InvalidArgumentException
*/
public ChaincodeID getChaincodeID() throws InvalidArgumentException {
try {
if (chaincodeID == null) {
Header header = Header.parseFrom(proposal.getHeader());
Common.ChannelHeader channelHeader = Common.ChannelHeader.parseFrom(header.getChannelHeader());
ChaincodeHeaderExtension chaincodeHeaderExtension = ChaincodeHeaderExtension.parseFrom(channelHeader.getExtension());
chaincodeID = new ChaincodeID(chaincodeHeaderExtension.getChaincodeId());
}
return chaincodeID;
} catch (Exception e) {
throw new InvalidArgumentException(e);
}
}
use of org.hyperledger.fabric.sdk.exception.InvalidArgumentException in project fabric-sdk-java by hyperledger.
the class HFClient method deSerializeChannel.
/**
* Deserialize a channel serialized by {@link Channel#serializeChannel()}
*
* @param channelBytes bytes to be deserialized.
* @return A Channel that has not been initialized.
* @throws IOException
* @throws ClassNotFoundException
* @throws InvalidArgumentException
*/
public Channel deSerializeChannel(byte[] channelBytes) throws IOException, ClassNotFoundException, InvalidArgumentException {
Channel channel;
ObjectInputStream in = null;
try {
in = new ObjectInputStream(new ByteArrayInputStream(channelBytes));
channel = (Channel) in.readObject();
final String name = channel.getName();
synchronized (channels) {
if (null != getChannel(name)) {
channel.shutdown(true);
throw new InvalidArgumentException(format("Channel %s already exists in the client", name));
}
channels.put(name, channel);
channel.client = this;
}
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
// Best effort here.
logger.error(e);
}
}
return channel;
}
Aggregations