id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
22,000
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ChannelConfiguration.java
ChannelConfiguration.setChannelConfiguration
public void setChannelConfiguration(byte[] channelConfigurationAsBytes) throws InvalidArgumentException { if (channelConfigurationAsBytes == null) { throw new InvalidArgumentException("ChannelConfiguration channelConfigurationAsBytes must be non-null"); } logger.trace("Creating setChannelConfiguration from bytes"); this.configBytes = channelConfigurationAsBytes; }
java
public void setChannelConfiguration(byte[] channelConfigurationAsBytes) throws InvalidArgumentException { if (channelConfigurationAsBytes == null) { throw new InvalidArgumentException("ChannelConfiguration channelConfigurationAsBytes must be non-null"); } logger.trace("Creating setChannelConfiguration from bytes"); this.configBytes = channelConfigurationAsBytes; }
[ "public", "void", "setChannelConfiguration", "(", "byte", "[", "]", "channelConfigurationAsBytes", ")", "throws", "InvalidArgumentException", "{", "if", "(", "channelConfigurationAsBytes", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"ChannelConfiguration channelConfigurationAsBytes must be non-null\"", ")", ";", "}", "logger", ".", "trace", "(", "\"Creating setChannelConfiguration from bytes\"", ")", ";", "this", ".", "configBytes", "=", "channelConfigurationAsBytes", ";", "}" ]
sets the ChannelConfiguration from a byte array @param channelConfigurationAsBytes the byte array containing the serialized channel configuration
[ "sets", "the", "ChannelConfiguration", "from", "a", "byte", "array" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ChannelConfiguration.java#L81-L87
22,001
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java
IdemixUtils.getRand
public static RAND getRand() { // construct a secure seed int seedLength = IdemixUtils.FIELD_BYTES; SecureRandom random = new SecureRandom(); byte[] seed = random.generateSeed(seedLength); // create a new amcl.RAND and initialize it with the generated seed RAND rng = new RAND(); rng.clean(); rng.seed(seedLength, seed); return rng; }
java
public static RAND getRand() { // construct a secure seed int seedLength = IdemixUtils.FIELD_BYTES; SecureRandom random = new SecureRandom(); byte[] seed = random.generateSeed(seedLength); // create a new amcl.RAND and initialize it with the generated seed RAND rng = new RAND(); rng.clean(); rng.seed(seedLength, seed); return rng; }
[ "public", "static", "RAND", "getRand", "(", ")", "{", "// construct a secure seed", "int", "seedLength", "=", "IdemixUtils", ".", "FIELD_BYTES", ";", "SecureRandom", "random", "=", "new", "SecureRandom", "(", ")", ";", "byte", "[", "]", "seed", "=", "random", ".", "generateSeed", "(", "seedLength", ")", ";", "// create a new amcl.RAND and initialize it with the generated seed", "RAND", "rng", "=", "new", "RAND", "(", ")", ";", "rng", ".", "clean", "(", ")", ";", "rng", ".", "seed", "(", "seedLength", ",", "seed", ")", ";", "return", "rng", ";", "}" ]
Returns a random number generator, amcl.RAND, initialized with a fresh seed. @return a random number generator
[ "Returns", "a", "random", "number", "generator", "amcl", ".", "RAND", "initialized", "with", "a", "fresh", "seed", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java#L66-L78
22,002
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java
IdemixUtils.hashModOrder
public static BIG hashModOrder(byte[] data) { HASH256 hash = new HASH256(); for (byte b : data) { hash.process(b); } byte[] hasheddata = hash.hash(); BIG ret = BIG.fromBytes(hasheddata); ret.mod(IdemixUtils.GROUP_ORDER); return ret; }
java
public static BIG hashModOrder(byte[] data) { HASH256 hash = new HASH256(); for (byte b : data) { hash.process(b); } byte[] hasheddata = hash.hash(); BIG ret = BIG.fromBytes(hasheddata); ret.mod(IdemixUtils.GROUP_ORDER); return ret; }
[ "public", "static", "BIG", "hashModOrder", "(", "byte", "[", "]", "data", ")", "{", "HASH256", "hash", "=", "new", "HASH256", "(", ")", ";", "for", "(", "byte", "b", ":", "data", ")", "{", "hash", ".", "process", "(", "b", ")", ";", "}", "byte", "[", "]", "hasheddata", "=", "hash", ".", "hash", "(", ")", ";", "BIG", "ret", "=", "BIG", ".", "fromBytes", "(", "hasheddata", ")", ";", "ret", ".", "mod", "(", "IdemixUtils", ".", "GROUP_ORDER", ")", ";", "return", "ret", ";", "}" ]
hashModOrder hashes bytes to an amcl.BIG in 0, ..., GROUP_ORDER @param data the data to be hashed @return a BIG in 0, ..., GROUP_ORDER-1 that is the hash of the data
[ "hashModOrder", "hashes", "bytes", "to", "an", "amcl", ".", "BIG", "in", "0", "...", "GROUP_ORDER" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java#L97-L109
22,003
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java
IdemixUtils.bigToBytes
public static byte[] bigToBytes(BIG big) { byte[] ret = new byte[IdemixUtils.FIELD_BYTES]; big.toBytes(ret); return ret; }
java
public static byte[] bigToBytes(BIG big) { byte[] ret = new byte[IdemixUtils.FIELD_BYTES]; big.toBytes(ret); return ret; }
[ "public", "static", "byte", "[", "]", "bigToBytes", "(", "BIG", "big", ")", "{", "byte", "[", "]", "ret", "=", "new", "byte", "[", "IdemixUtils", ".", "FIELD_BYTES", "]", ";", "big", ".", "toBytes", "(", "ret", ")", ";", "return", "ret", ";", "}" ]
bigToBytes turns a BIG into a byte array @param big the BIG to turn into bytes @return a byte array representation of the BIG
[ "bigToBytes", "turns", "a", "BIG", "into", "a", "byte", "array" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java#L117-L121
22,004
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java
IdemixUtils.ecpToBytes
static byte[] ecpToBytes(ECP e) { byte[] ret = new byte[2 * FIELD_BYTES + 1]; e.toBytes(ret, false); return ret; }
java
static byte[] ecpToBytes(ECP e) { byte[] ret = new byte[2 * FIELD_BYTES + 1]; e.toBytes(ret, false); return ret; }
[ "static", "byte", "[", "]", "ecpToBytes", "(", "ECP", "e", ")", "{", "byte", "[", "]", "ret", "=", "new", "byte", "[", "2", "*", "FIELD_BYTES", "+", "1", "]", ";", "e", ".", "toBytes", "(", "ret", ",", "false", ")", ";", "return", "ret", ";", "}" ]
ecpToBytes turns an ECP into a byte array @param e the ECP to turn into bytes @return a byte array representation of the ECP
[ "ecpToBytes", "turns", "an", "ECP", "into", "a", "byte", "array" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java#L129-L133
22,005
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java
IdemixUtils.append
static byte[] append(byte[] data, byte[] toAppend) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { stream.write(data); stream.write(toAppend); } catch (IOException e) { e.printStackTrace(); } return stream.toByteArray(); }
java
static byte[] append(byte[] data, byte[] toAppend) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { stream.write(data); stream.write(toAppend); } catch (IOException e) { e.printStackTrace(); } return stream.toByteArray(); }
[ "static", "byte", "[", "]", "append", "(", "byte", "[", "]", "data", ",", "byte", "[", "]", "toAppend", ")", "{", "ByteArrayOutputStream", "stream", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "try", "{", "stream", ".", "write", "(", "data", ")", ";", "stream", ".", "write", "(", "toAppend", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "stream", ".", "toByteArray", "(", ")", ";", "}" ]
append appends a byte array to an existing byte array @param data the data to which we want to append @param toAppend the data to be appended @return a new byte[] of data + toAppend
[ "append", "appends", "a", "byte", "array", "to", "an", "existing", "byte", "array" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java#L154-L164
22,006
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java
IdemixUtils.append
static byte[] append(byte[] data, boolean[] toAppend) { byte[] toAppendBytes = new byte[toAppend.length]; for (int i = 0; i < toAppend.length; i++) { toAppendBytes[i] = toAppend[i] ? (byte) 1 : (byte) 0; } return append(data, toAppendBytes); }
java
static byte[] append(byte[] data, boolean[] toAppend) { byte[] toAppendBytes = new byte[toAppend.length]; for (int i = 0; i < toAppend.length; i++) { toAppendBytes[i] = toAppend[i] ? (byte) 1 : (byte) 0; } return append(data, toAppendBytes); }
[ "static", "byte", "[", "]", "append", "(", "byte", "[", "]", "data", ",", "boolean", "[", "]", "toAppend", ")", "{", "byte", "[", "]", "toAppendBytes", "=", "new", "byte", "[", "toAppend", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "toAppend", ".", "length", ";", "i", "++", ")", "{", "toAppendBytes", "[", "i", "]", "=", "toAppend", "[", "i", "]", "?", "(", "byte", ")", "1", ":", "(", "byte", ")", "0", ";", "}", "return", "append", "(", "data", ",", "toAppendBytes", ")", ";", "}" ]
append appends a boolean array to an existing byte array @param data the data to which we want to append @param toAppend the data to be appended @return a new byte[] of data + toAppend
[ "append", "appends", "a", "boolean", "array", "to", "an", "existing", "byte", "array" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java#L172-L178
22,007
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java
IdemixUtils.transformFromProto
static ECP transformFromProto(Idemix.ECP w) { byte[] valuex = w.getX().toByteArray(); byte[] valuey = w.getY().toByteArray(); return new ECP(BIG.fromBytes(valuex), BIG.fromBytes(valuey)); }
java
static ECP transformFromProto(Idemix.ECP w) { byte[] valuex = w.getX().toByteArray(); byte[] valuey = w.getY().toByteArray(); return new ECP(BIG.fromBytes(valuex), BIG.fromBytes(valuey)); }
[ "static", "ECP", "transformFromProto", "(", "Idemix", ".", "ECP", "w", ")", "{", "byte", "[", "]", "valuex", "=", "w", ".", "getX", "(", ")", ".", "toByteArray", "(", ")", ";", "byte", "[", "]", "valuey", "=", "w", ".", "getY", "(", ")", ".", "toByteArray", "(", ")", ";", "return", "new", "ECP", "(", "BIG", ".", "fromBytes", "(", "valuex", ")", ",", "BIG", ".", "fromBytes", "(", "valuey", ")", ")", ";", "}" ]
Returns an amcl.BN256.ECP on input of an ECP protobuf object. @param w a protobuf object representing an ECP @return a ECP created from the protobuf object
[ "Returns", "an", "amcl", ".", "BN256", ".", "ECP", "on", "input", "of", "an", "ECP", "protobuf", "object", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java#L186-L190
22,008
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java
IdemixUtils.transformFromProto
static ECP2 transformFromProto(Idemix.ECP2 w) { byte[] valuexa = w.getXa().toByteArray(); byte[] valuexb = w.getXb().toByteArray(); byte[] valueya = w.getYa().toByteArray(); byte[] valueyb = w.getYb().toByteArray(); FP2 valuex = new FP2(BIG.fromBytes(valuexa), BIG.fromBytes(valuexb)); FP2 valuey = new FP2(BIG.fromBytes(valueya), BIG.fromBytes(valueyb)); return new ECP2(valuex, valuey); }
java
static ECP2 transformFromProto(Idemix.ECP2 w) { byte[] valuexa = w.getXa().toByteArray(); byte[] valuexb = w.getXb().toByteArray(); byte[] valueya = w.getYa().toByteArray(); byte[] valueyb = w.getYb().toByteArray(); FP2 valuex = new FP2(BIG.fromBytes(valuexa), BIG.fromBytes(valuexb)); FP2 valuey = new FP2(BIG.fromBytes(valueya), BIG.fromBytes(valueyb)); return new ECP2(valuex, valuey); }
[ "static", "ECP2", "transformFromProto", "(", "Idemix", ".", "ECP2", "w", ")", "{", "byte", "[", "]", "valuexa", "=", "w", ".", "getXa", "(", ")", ".", "toByteArray", "(", ")", ";", "byte", "[", "]", "valuexb", "=", "w", ".", "getXb", "(", ")", ".", "toByteArray", "(", ")", ";", "byte", "[", "]", "valueya", "=", "w", ".", "getYa", "(", ")", ".", "toByteArray", "(", ")", ";", "byte", "[", "]", "valueyb", "=", "w", ".", "getYb", "(", ")", ".", "toByteArray", "(", ")", ";", "FP2", "valuex", "=", "new", "FP2", "(", "BIG", ".", "fromBytes", "(", "valuexa", ")", ",", "BIG", ".", "fromBytes", "(", "valuexb", ")", ")", ";", "FP2", "valuey", "=", "new", "FP2", "(", "BIG", ".", "fromBytes", "(", "valueya", ")", ",", "BIG", ".", "fromBytes", "(", "valueyb", ")", ")", ";", "return", "new", "ECP2", "(", "valuex", ",", "valuey", ")", ";", "}" ]
Returns an amcl.BN256.ECP2 on input of an ECP2 protobuf object. @param w a protobuf object representing an ECP2 @return a ECP2 created from the protobuf object
[ "Returns", "an", "amcl", ".", "BN256", ".", "ECP2", "on", "input", "of", "an", "ECP2", "protobuf", "object", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java#L198-L206
22,009
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java
IdemixUtils.transformToProto
static Idemix.ECP2 transformToProto(ECP2 w) { byte[] valueXA = new byte[IdemixUtils.FIELD_BYTES]; byte[] valueXB = new byte[IdemixUtils.FIELD_BYTES]; byte[] valueYA = new byte[IdemixUtils.FIELD_BYTES]; byte[] valueYB = new byte[IdemixUtils.FIELD_BYTES]; w.getX().getA().toBytes(valueXA); w.getX().getB().toBytes(valueXB); w.getY().getA().toBytes(valueYA); w.getY().getB().toBytes(valueYB); return Idemix.ECP2.newBuilder() .setXa(ByteString.copyFrom(valueXA)) .setXb(ByteString.copyFrom(valueXB)) .setYa(ByteString.copyFrom(valueYA)) .setYb(ByteString.copyFrom(valueYB)) .build(); }
java
static Idemix.ECP2 transformToProto(ECP2 w) { byte[] valueXA = new byte[IdemixUtils.FIELD_BYTES]; byte[] valueXB = new byte[IdemixUtils.FIELD_BYTES]; byte[] valueYA = new byte[IdemixUtils.FIELD_BYTES]; byte[] valueYB = new byte[IdemixUtils.FIELD_BYTES]; w.getX().getA().toBytes(valueXA); w.getX().getB().toBytes(valueXB); w.getY().getA().toBytes(valueYA); w.getY().getB().toBytes(valueYB); return Idemix.ECP2.newBuilder() .setXa(ByteString.copyFrom(valueXA)) .setXb(ByteString.copyFrom(valueXB)) .setYa(ByteString.copyFrom(valueYA)) .setYb(ByteString.copyFrom(valueYB)) .build(); }
[ "static", "Idemix", ".", "ECP2", "transformToProto", "(", "ECP2", "w", ")", "{", "byte", "[", "]", "valueXA", "=", "new", "byte", "[", "IdemixUtils", ".", "FIELD_BYTES", "]", ";", "byte", "[", "]", "valueXB", "=", "new", "byte", "[", "IdemixUtils", ".", "FIELD_BYTES", "]", ";", "byte", "[", "]", "valueYA", "=", "new", "byte", "[", "IdemixUtils", ".", "FIELD_BYTES", "]", ";", "byte", "[", "]", "valueYB", "=", "new", "byte", "[", "IdemixUtils", ".", "FIELD_BYTES", "]", ";", "w", ".", "getX", "(", ")", ".", "getA", "(", ")", ".", "toBytes", "(", "valueXA", ")", ";", "w", ".", "getX", "(", ")", ".", "getB", "(", ")", ".", "toBytes", "(", "valueXB", ")", ";", "w", ".", "getY", "(", ")", ".", "getA", "(", ")", ".", "toBytes", "(", "valueYA", ")", ";", "w", ".", "getY", "(", ")", ".", "getB", "(", ")", ".", "toBytes", "(", "valueYB", ")", ";", "return", "Idemix", ".", "ECP2", ".", "newBuilder", "(", ")", ".", "setXa", "(", "ByteString", ".", "copyFrom", "(", "valueXA", ")", ")", ".", "setXb", "(", "ByteString", ".", "copyFrom", "(", "valueXB", ")", ")", ".", "setYa", "(", "ByteString", ".", "copyFrom", "(", "valueYA", ")", ")", ".", "setYb", "(", "ByteString", ".", "copyFrom", "(", "valueYB", ")", ")", ".", "build", "(", ")", ";", "}" ]
Converts an amcl.BN256.ECP2 into an ECP2 protobuf object. @param w an ECP2 to be transformed into a protobuf object @return a protobuf representation of the ECP2
[ "Converts", "an", "amcl", ".", "BN256", ".", "ECP2", "into", "an", "ECP2", "protobuf", "object", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java#L214-L232
22,010
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java
IdemixUtils.transformToProto
static Idemix.ECP transformToProto(ECP w) { byte[] valueX = new byte[IdemixUtils.FIELD_BYTES]; byte[] valueY = new byte[IdemixUtils.FIELD_BYTES]; w.getX().toBytes(valueX); w.getY().toBytes(valueY); return Idemix.ECP.newBuilder().setX(ByteString.copyFrom(valueX)).setY(ByteString.copyFrom(valueY)).build(); }
java
static Idemix.ECP transformToProto(ECP w) { byte[] valueX = new byte[IdemixUtils.FIELD_BYTES]; byte[] valueY = new byte[IdemixUtils.FIELD_BYTES]; w.getX().toBytes(valueX); w.getY().toBytes(valueY); return Idemix.ECP.newBuilder().setX(ByteString.copyFrom(valueX)).setY(ByteString.copyFrom(valueY)).build(); }
[ "static", "Idemix", ".", "ECP", "transformToProto", "(", "ECP", "w", ")", "{", "byte", "[", "]", "valueX", "=", "new", "byte", "[", "IdemixUtils", ".", "FIELD_BYTES", "]", ";", "byte", "[", "]", "valueY", "=", "new", "byte", "[", "IdemixUtils", ".", "FIELD_BYTES", "]", ";", "w", ".", "getX", "(", ")", ".", "toBytes", "(", "valueX", ")", ";", "w", ".", "getY", "(", ")", ".", "toBytes", "(", "valueY", ")", ";", "return", "Idemix", ".", "ECP", ".", "newBuilder", "(", ")", ".", "setX", "(", "ByteString", ".", "copyFrom", "(", "valueX", ")", ")", ".", "setY", "(", "ByteString", ".", "copyFrom", "(", "valueY", ")", ")", ".", "build", "(", ")", ";", "}" ]
Converts an amcl.BN256.ECP into an ECP protobuf object. @param w an ECP to be transformed into a protobuf object @return a protobuf representation of the ECP
[ "Converts", "an", "amcl", ".", "BN256", ".", "ECP", "into", "an", "ECP", "protobuf", "object", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java#L240-L248
22,011
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java
IdemixUtils.modAdd
static BIG modAdd(BIG a, BIG b, BIG m) { BIG c = a.plus(b); c.mod(m); return c; }
java
static BIG modAdd(BIG a, BIG b, BIG m) { BIG c = a.plus(b); c.mod(m); return c; }
[ "static", "BIG", "modAdd", "(", "BIG", "a", ",", "BIG", "b", ",", "BIG", "m", ")", "{", "BIG", "c", "=", "a", ".", "plus", "(", "b", ")", ";", "c", ".", "mod", "(", "m", ")", ";", "return", "c", ";", "}" ]
Takes input BIGs a, b, m and returns a+b modulo m @param a the first BIG to add @param b the second BIG to add @param m the modulus @return Returns a+b (mod m)
[ "Takes", "input", "BIGs", "a", "b", "m", "and", "returns", "a", "+", "b", "modulo", "m" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java#L258-L262
22,012
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java
IdemixUtils.modSub
static BIG modSub(BIG a, BIG b, BIG m) { return modAdd(a, BIG.modneg(b, m), m); }
java
static BIG modSub(BIG a, BIG b, BIG m) { return modAdd(a, BIG.modneg(b, m), m); }
[ "static", "BIG", "modSub", "(", "BIG", "a", ",", "BIG", "b", ",", "BIG", "m", ")", "{", "return", "modAdd", "(", "a", ",", "BIG", ".", "modneg", "(", "b", ",", "m", ")", ",", "m", ")", ";", "}" ]
Modsub takes input BIGs a, b, m and returns a-b modulo m @param a the minuend of the modular subtraction @param b the subtrahend of the modular subtraction @param m the modulus @return returns a-b (mod m)
[ "Modsub", "takes", "input", "BIGs", "a", "b", "m", "and", "returns", "a", "-", "b", "modulo", "m" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixUtils.java#L272-L274
22,013
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ChaincodeEndorsementPolicy.java
ChaincodeEndorsementPolicy.fromYamlFile
public void fromYamlFile(File yamlPolicyFile) throws IOException, ChaincodeEndorsementPolicyParseException { final Yaml yaml = new Yaml(); final Map<?, ?> load = (Map<?, ?>) yaml.load(new FileInputStream(yamlPolicyFile)); Map<?, ?> mp = (Map<?, ?>) load.get("policy"); if (null == mp) { throw new ChaincodeEndorsementPolicyParseException("The policy file has no policy section"); } IndexedHashMap<String, MSPPrincipal> identities = parseIdentities((Map<?, ?>) load.get("identities")); SignaturePolicy sp = parsePolicy(identities, mp); policyBytes = Policies.SignaturePolicyEnvelope.newBuilder() .setVersion(0) .addAllIdentities(identities.values()) .setRule(sp) .build().toByteArray(); }
java
public void fromYamlFile(File yamlPolicyFile) throws IOException, ChaincodeEndorsementPolicyParseException { final Yaml yaml = new Yaml(); final Map<?, ?> load = (Map<?, ?>) yaml.load(new FileInputStream(yamlPolicyFile)); Map<?, ?> mp = (Map<?, ?>) load.get("policy"); if (null == mp) { throw new ChaincodeEndorsementPolicyParseException("The policy file has no policy section"); } IndexedHashMap<String, MSPPrincipal> identities = parseIdentities((Map<?, ?>) load.get("identities")); SignaturePolicy sp = parsePolicy(identities, mp); policyBytes = Policies.SignaturePolicyEnvelope.newBuilder() .setVersion(0) .addAllIdentities(identities.values()) .setRule(sp) .build().toByteArray(); }
[ "public", "void", "fromYamlFile", "(", "File", "yamlPolicyFile", ")", "throws", "IOException", ",", "ChaincodeEndorsementPolicyParseException", "{", "final", "Yaml", "yaml", "=", "new", "Yaml", "(", ")", ";", "final", "Map", "<", "?", ",", "?", ">", "load", "=", "(", "Map", "<", "?", ",", "?", ">", ")", "yaml", ".", "load", "(", "new", "FileInputStream", "(", "yamlPolicyFile", ")", ")", ";", "Map", "<", "?", ",", "?", ">", "mp", "=", "(", "Map", "<", "?", ",", "?", ">", ")", "load", ".", "get", "(", "\"policy\"", ")", ";", "if", "(", "null", "==", "mp", ")", "{", "throw", "new", "ChaincodeEndorsementPolicyParseException", "(", "\"The policy file has no policy section\"", ")", ";", "}", "IndexedHashMap", "<", "String", ",", "MSPPrincipal", ">", "identities", "=", "parseIdentities", "(", "(", "Map", "<", "?", ",", "?", ">", ")", "load", ".", "get", "(", "\"identities\"", ")", ")", ";", "SignaturePolicy", "sp", "=", "parsePolicy", "(", "identities", ",", "mp", ")", ";", "policyBytes", "=", "Policies", ".", "SignaturePolicyEnvelope", ".", "newBuilder", "(", ")", ".", "setVersion", "(", "0", ")", ".", "addAllIdentities", "(", "identities", ".", "values", "(", ")", ")", ".", "setRule", "(", "sp", ")", ".", "build", "(", ")", ".", "toByteArray", "(", ")", ";", "}" ]
From a yaml file @param yamlPolicyFile File location for the chaincode endorsement policy specification. @throws IOException @throws ChaincodeEndorsementPolicyParseException @deprecated use {@link #fromYamlFile(Path)}
[ "From", "a", "yaml", "file" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ChaincodeEndorsementPolicy.java#L239-L258
22,014
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ChaincodeEndorsementPolicy.java
ChaincodeEndorsementPolicy.fromBytes
public static ChaincodeEndorsementPolicy fromBytes(byte[] policyAsBytes) { ChaincodeEndorsementPolicy ret = new ChaincodeEndorsementPolicy(); ret.policyBytes = new byte[policyAsBytes.length]; System.arraycopy(policyAsBytes, 0, ret.policyBytes, 0, policyAsBytes.length); return ret; }
java
public static ChaincodeEndorsementPolicy fromBytes(byte[] policyAsBytes) { ChaincodeEndorsementPolicy ret = new ChaincodeEndorsementPolicy(); ret.policyBytes = new byte[policyAsBytes.length]; System.arraycopy(policyAsBytes, 0, ret.policyBytes, 0, policyAsBytes.length); return ret; }
[ "public", "static", "ChaincodeEndorsementPolicy", "fromBytes", "(", "byte", "[", "]", "policyAsBytes", ")", "{", "ChaincodeEndorsementPolicy", "ret", "=", "new", "ChaincodeEndorsementPolicy", "(", ")", ";", "ret", ".", "policyBytes", "=", "new", "byte", "[", "policyAsBytes", ".", "length", "]", ";", "System", ".", "arraycopy", "(", "policyAsBytes", ",", "0", ",", "ret", ".", "policyBytes", ",", "0", ",", "policyAsBytes", ".", "length", ")", ";", "return", "ret", ";", "}" ]
sets the ChaincodeEndorsementPolicy from a byte array @param policyAsBytes the byte array containing the serialized policy
[ "sets", "the", "ChaincodeEndorsementPolicy", "from", "a", "byte", "array" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ChaincodeEndorsementPolicy.java#L301-L308
22,015
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java
HFCAAffiliation.read
public int read(User registrar) throws AffiliationException, InvalidArgumentException { if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String readAffURL = ""; try { readAffURL = HFCA_AFFILIATION + "/" + name; logger.debug(format("affiliation url: %s, registrar: %s", readAffURL, registrar.getName())); JsonObject result = client.httpGet(readAffURL, registrar); logger.debug(format("affiliation url: %s, registrar: %s done.", readAffURL, registrar)); HFCAAffiliationResp resp = getResponse(result); this.childHFCAAffiliations = resp.getChildren(); this.identities = resp.getIdentities(); this.deleted = false; return resp.statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while getting affiliation '%s' from url '%s': %s", e.getStatusCode(), this.name, readAffURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } catch (Exception e) { String msg = format("Error while getting affiliation %s url: %s %s ", this.name, readAffURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } }
java
public int read(User registrar) throws AffiliationException, InvalidArgumentException { if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String readAffURL = ""; try { readAffURL = HFCA_AFFILIATION + "/" + name; logger.debug(format("affiliation url: %s, registrar: %s", readAffURL, registrar.getName())); JsonObject result = client.httpGet(readAffURL, registrar); logger.debug(format("affiliation url: %s, registrar: %s done.", readAffURL, registrar)); HFCAAffiliationResp resp = getResponse(result); this.childHFCAAffiliations = resp.getChildren(); this.identities = resp.getIdentities(); this.deleted = false; return resp.statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while getting affiliation '%s' from url '%s': %s", e.getStatusCode(), this.name, readAffURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } catch (Exception e) { String msg = format("Error while getting affiliation %s url: %s %s ", this.name, readAffURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } }
[ "public", "int", "read", "(", "User", "registrar", ")", "throws", "AffiliationException", ",", "InvalidArgumentException", "{", "if", "(", "registrar", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Registrar should be a valid member\"", ")", ";", "}", "String", "readAffURL", "=", "\"\"", ";", "try", "{", "readAffURL", "=", "HFCA_AFFILIATION", "+", "\"/\"", "+", "name", ";", "logger", ".", "debug", "(", "format", "(", "\"affiliation url: %s, registrar: %s\"", ",", "readAffURL", ",", "registrar", ".", "getName", "(", ")", ")", ")", ";", "JsonObject", "result", "=", "client", ".", "httpGet", "(", "readAffURL", ",", "registrar", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"affiliation url: %s, registrar: %s done.\"", ",", "readAffURL", ",", "registrar", ")", ")", ";", "HFCAAffiliationResp", "resp", "=", "getResponse", "(", "result", ")", ";", "this", ".", "childHFCAAffiliations", "=", "resp", ".", "getChildren", "(", ")", ";", "this", ".", "identities", "=", "resp", ".", "getIdentities", "(", ")", ";", "this", ".", "deleted", "=", "false", ";", "return", "resp", ".", "statusCode", ";", "}", "catch", "(", "HTTPException", "e", ")", "{", "String", "msg", "=", "format", "(", "\"[Code: %d] - Error while getting affiliation '%s' from url '%s': %s\"", ",", "e", ".", "getStatusCode", "(", ")", ",", "this", ".", "name", ",", "readAffURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "AffiliationException", "affiliationException", "=", "new", "AffiliationException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "affiliationException", ";", "}", "catch", "(", "Exception", "e", ")", "{", "String", "msg", "=", "format", "(", "\"Error while getting affiliation %s url: %s %s \"", ",", "this", ".", "name", ",", "readAffURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "AffiliationException", "affiliationException", "=", "new", "AffiliationException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "affiliationException", ";", "}", "}" ]
gets a specific affiliation @param registrar The identity of the registrar @return Returns response @throws AffiliationException if getting an affiliation fails. @throws InvalidArgumentException
[ "gets", "a", "specific", "affiliation" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java#L194-L224
22,016
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java
HFCAAffiliation.create
public HFCAAffiliationResp create(User registrar, boolean force) throws AffiliationException, InvalidArgumentException { if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String createURL = ""; try { createURL = client.getURL(HFCA_AFFILIATION); logger.debug(format("affiliation url: %s, registrar: %s", createURL, registrar.getName())); Map<String, String> queryParm = new HashMap<String, String>(); queryParm.put("force", String.valueOf(force)); String body = client.toJson(affToJsonObject()); JsonObject result = client.httpPost(createURL, body, registrar); logger.debug(format("identity url: %s, registrar: %s done.", createURL, registrar)); this.deleted = false; return getResponse(result); } catch (HTTPException e) { String msg = format("[Code: %d] - Error while creating affiliation '%s' from url '%s': %s", e.getStatusCode(), this.name, createURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } catch (Exception e) { String msg = format("Error while creating affiliation %s url: %s %s ", this.name, createURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } }
java
public HFCAAffiliationResp create(User registrar, boolean force) throws AffiliationException, InvalidArgumentException { if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String createURL = ""; try { createURL = client.getURL(HFCA_AFFILIATION); logger.debug(format("affiliation url: %s, registrar: %s", createURL, registrar.getName())); Map<String, String> queryParm = new HashMap<String, String>(); queryParm.put("force", String.valueOf(force)); String body = client.toJson(affToJsonObject()); JsonObject result = client.httpPost(createURL, body, registrar); logger.debug(format("identity url: %s, registrar: %s done.", createURL, registrar)); this.deleted = false; return getResponse(result); } catch (HTTPException e) { String msg = format("[Code: %d] - Error while creating affiliation '%s' from url '%s': %s", e.getStatusCode(), this.name, createURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } catch (Exception e) { String msg = format("Error while creating affiliation %s url: %s %s ", this.name, createURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } }
[ "public", "HFCAAffiliationResp", "create", "(", "User", "registrar", ",", "boolean", "force", ")", "throws", "AffiliationException", ",", "InvalidArgumentException", "{", "if", "(", "registrar", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Registrar should be a valid member\"", ")", ";", "}", "String", "createURL", "=", "\"\"", ";", "try", "{", "createURL", "=", "client", ".", "getURL", "(", "HFCA_AFFILIATION", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"affiliation url: %s, registrar: %s\"", ",", "createURL", ",", "registrar", ".", "getName", "(", ")", ")", ")", ";", "Map", "<", "String", ",", "String", ">", "queryParm", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "queryParm", ".", "put", "(", "\"force\"", ",", "String", ".", "valueOf", "(", "force", ")", ")", ";", "String", "body", "=", "client", ".", "toJson", "(", "affToJsonObject", "(", ")", ")", ";", "JsonObject", "result", "=", "client", ".", "httpPost", "(", "createURL", ",", "body", ",", "registrar", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"identity url: %s, registrar: %s done.\"", ",", "createURL", ",", "registrar", ")", ")", ";", "this", ".", "deleted", "=", "false", ";", "return", "getResponse", "(", "result", ")", ";", "}", "catch", "(", "HTTPException", "e", ")", "{", "String", "msg", "=", "format", "(", "\"[Code: %d] - Error while creating affiliation '%s' from url '%s': %s\"", ",", "e", ".", "getStatusCode", "(", ")", ",", "this", ".", "name", ",", "createURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "AffiliationException", "affiliationException", "=", "new", "AffiliationException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "affiliationException", ";", "}", "catch", "(", "Exception", "e", ")", "{", "String", "msg", "=", "format", "(", "\"Error while creating affiliation %s url: %s %s \"", ",", "this", ".", "name", ",", "createURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "AffiliationException", "affiliationException", "=", "new", "AffiliationException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "affiliationException", ";", "}", "}" ]
create an affiliation @param registrar The identity of the registrar (i.e. who is performing the registration). @param force Forces the creation of parent affiliations @return Response of request @throws AffiliationException if adding an affiliation fails. @throws InvalidArgumentException
[ "create", "an", "affiliation" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java#L248-L277
22,017
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java
HFCAAffiliation.update
public HFCAAffiliationResp update(User registrar, boolean force) throws AffiliationException, InvalidArgumentException { if (this.deleted) { throw new AffiliationException("Affiliation has been deleted"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } if (Utils.isNullOrEmpty(name)) { throw new InvalidArgumentException("Affiliation name cannot be null or empty"); } String updateURL = ""; try { Map<String, String> queryParm = new HashMap<String, String>(); queryParm.put("force", String.valueOf(force)); updateURL = client.getURL(HFCA_AFFILIATION + "/" + this.name, queryParm); logger.debug(format("affiliation url: %s, registrar: %s", updateURL, registrar.getName())); String body = client.toJson(affToJsonObject()); JsonObject result = client.httpPut(updateURL, body, registrar); generateResponse(result); logger.debug(format("identity url: %s, registrar: %s done.", updateURL, registrar)); HFCAAffiliationResp resp = getResponse(result); this.childHFCAAffiliations = resp.childHFCAAffiliations; this.identities = resp.identities; return getResponse(result); } catch (HTTPException e) { String msg = format("[Code: %d] - Error while updating affiliation '%s' from url '%s': %s", e.getStatusCode(), this.name, updateURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } catch (Exception e) { String msg = format("Error while updating affiliation %s url: %s %s ", this.name, updateURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } }
java
public HFCAAffiliationResp update(User registrar, boolean force) throws AffiliationException, InvalidArgumentException { if (this.deleted) { throw new AffiliationException("Affiliation has been deleted"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } if (Utils.isNullOrEmpty(name)) { throw new InvalidArgumentException("Affiliation name cannot be null or empty"); } String updateURL = ""; try { Map<String, String> queryParm = new HashMap<String, String>(); queryParm.put("force", String.valueOf(force)); updateURL = client.getURL(HFCA_AFFILIATION + "/" + this.name, queryParm); logger.debug(format("affiliation url: %s, registrar: %s", updateURL, registrar.getName())); String body = client.toJson(affToJsonObject()); JsonObject result = client.httpPut(updateURL, body, registrar); generateResponse(result); logger.debug(format("identity url: %s, registrar: %s done.", updateURL, registrar)); HFCAAffiliationResp resp = getResponse(result); this.childHFCAAffiliations = resp.childHFCAAffiliations; this.identities = resp.identities; return getResponse(result); } catch (HTTPException e) { String msg = format("[Code: %d] - Error while updating affiliation '%s' from url '%s': %s", e.getStatusCode(), this.name, updateURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } catch (Exception e) { String msg = format("Error while updating affiliation %s url: %s %s ", this.name, updateURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } }
[ "public", "HFCAAffiliationResp", "update", "(", "User", "registrar", ",", "boolean", "force", ")", "throws", "AffiliationException", ",", "InvalidArgumentException", "{", "if", "(", "this", ".", "deleted", ")", "{", "throw", "new", "AffiliationException", "(", "\"Affiliation has been deleted\"", ")", ";", "}", "if", "(", "registrar", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Registrar should be a valid member\"", ")", ";", "}", "if", "(", "Utils", ".", "isNullOrEmpty", "(", "name", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Affiliation name cannot be null or empty\"", ")", ";", "}", "String", "updateURL", "=", "\"\"", ";", "try", "{", "Map", "<", "String", ",", "String", ">", "queryParm", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "queryParm", ".", "put", "(", "\"force\"", ",", "String", ".", "valueOf", "(", "force", ")", ")", ";", "updateURL", "=", "client", ".", "getURL", "(", "HFCA_AFFILIATION", "+", "\"/\"", "+", "this", ".", "name", ",", "queryParm", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"affiliation url: %s, registrar: %s\"", ",", "updateURL", ",", "registrar", ".", "getName", "(", ")", ")", ")", ";", "String", "body", "=", "client", ".", "toJson", "(", "affToJsonObject", "(", ")", ")", ";", "JsonObject", "result", "=", "client", ".", "httpPut", "(", "updateURL", ",", "body", ",", "registrar", ")", ";", "generateResponse", "(", "result", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"identity url: %s, registrar: %s done.\"", ",", "updateURL", ",", "registrar", ")", ")", ";", "HFCAAffiliationResp", "resp", "=", "getResponse", "(", "result", ")", ";", "this", ".", "childHFCAAffiliations", "=", "resp", ".", "childHFCAAffiliations", ";", "this", ".", "identities", "=", "resp", ".", "identities", ";", "return", "getResponse", "(", "result", ")", ";", "}", "catch", "(", "HTTPException", "e", ")", "{", "String", "msg", "=", "format", "(", "\"[Code: %d] - Error while updating affiliation '%s' from url '%s': %s\"", ",", "e", ".", "getStatusCode", "(", ")", ",", "this", ".", "name", ",", "updateURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "AffiliationException", "affiliationException", "=", "new", "AffiliationException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "affiliationException", ";", "}", "catch", "(", "Exception", "e", ")", "{", "String", "msg", "=", "format", "(", "\"Error while updating affiliation %s url: %s %s \"", ",", "this", ".", "name", ",", "updateURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "AffiliationException", "affiliationException", "=", "new", "AffiliationException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "affiliationException", ";", "}", "}" ]
update an affiliation @param registrar The identity of the registrar (i.e. who is performing the registration). @param force Forces updating of child affiliations @return Response of request @throws AffiliationException If updating an affiliation fails @throws InvalidArgumentException
[ "update", "an", "affiliation" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java#L301-L340
22,018
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java
HFCAAffiliation.delete
public HFCAAffiliationResp delete(User registrar, boolean force) throws AffiliationException, InvalidArgumentException { if (this.deleted) { throw new AffiliationException("Affiliation has been deleted"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String deleteURL = ""; try { Map<String, String> queryParm = new HashMap<String, String>(); queryParm.put("force", String.valueOf(force)); deleteURL = client.getURL(HFCA_AFFILIATION + "/" + this.name, queryParm); logger.debug(format("affiliation url: %s, registrar: %s", deleteURL, registrar.getName())); JsonObject result = client.httpDelete(deleteURL, registrar); logger.debug(format("identity url: %s, registrar: %s done.", deleteURL, registrar)); this.deleted = true; return getResponse(result); } catch (HTTPException e) { String msg = format("[Code: %d] - Error while deleting affiliation '%s' from url '%s': %s", e.getStatusCode(), this.name, deleteURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } catch (Exception e) { String msg = format("Error while deleting affiliation %s url: %s %s ", this.name, deleteURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } }
java
public HFCAAffiliationResp delete(User registrar, boolean force) throws AffiliationException, InvalidArgumentException { if (this.deleted) { throw new AffiliationException("Affiliation has been deleted"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String deleteURL = ""; try { Map<String, String> queryParm = new HashMap<String, String>(); queryParm.put("force", String.valueOf(force)); deleteURL = client.getURL(HFCA_AFFILIATION + "/" + this.name, queryParm); logger.debug(format("affiliation url: %s, registrar: %s", deleteURL, registrar.getName())); JsonObject result = client.httpDelete(deleteURL, registrar); logger.debug(format("identity url: %s, registrar: %s done.", deleteURL, registrar)); this.deleted = true; return getResponse(result); } catch (HTTPException e) { String msg = format("[Code: %d] - Error while deleting affiliation '%s' from url '%s': %s", e.getStatusCode(), this.name, deleteURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } catch (Exception e) { String msg = format("Error while deleting affiliation %s url: %s %s ", this.name, deleteURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } }
[ "public", "HFCAAffiliationResp", "delete", "(", "User", "registrar", ",", "boolean", "force", ")", "throws", "AffiliationException", ",", "InvalidArgumentException", "{", "if", "(", "this", ".", "deleted", ")", "{", "throw", "new", "AffiliationException", "(", "\"Affiliation has been deleted\"", ")", ";", "}", "if", "(", "registrar", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Registrar should be a valid member\"", ")", ";", "}", "String", "deleteURL", "=", "\"\"", ";", "try", "{", "Map", "<", "String", ",", "String", ">", "queryParm", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "queryParm", ".", "put", "(", "\"force\"", ",", "String", ".", "valueOf", "(", "force", ")", ")", ";", "deleteURL", "=", "client", ".", "getURL", "(", "HFCA_AFFILIATION", "+", "\"/\"", "+", "this", ".", "name", ",", "queryParm", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"affiliation url: %s, registrar: %s\"", ",", "deleteURL", ",", "registrar", ".", "getName", "(", ")", ")", ")", ";", "JsonObject", "result", "=", "client", ".", "httpDelete", "(", "deleteURL", ",", "registrar", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"identity url: %s, registrar: %s done.\"", ",", "deleteURL", ",", "registrar", ")", ")", ";", "this", ".", "deleted", "=", "true", ";", "return", "getResponse", "(", "result", ")", ";", "}", "catch", "(", "HTTPException", "e", ")", "{", "String", "msg", "=", "format", "(", "\"[Code: %d] - Error while deleting affiliation '%s' from url '%s': %s\"", ",", "e", ".", "getStatusCode", "(", ")", ",", "this", ".", "name", ",", "deleteURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "AffiliationException", "affiliationException", "=", "new", "AffiliationException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "affiliationException", ";", "}", "catch", "(", "Exception", "e", ")", "{", "String", "msg", "=", "format", "(", "\"Error while deleting affiliation %s url: %s %s \"", ",", "this", ".", "name", ",", "deleteURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "AffiliationException", "affiliationException", "=", "new", "AffiliationException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "affiliationException", ";", "}", "}" ]
delete an affiliation @param registrar The identity of the registrar (i.e. who is performing the registration). @param force Forces the deletion of affiliation @return Response of request @throws AffiliationException if deleting an affiliation fails. @throws InvalidArgumentException
[ "delete", "an", "affiliation" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java#L364-L396
22,019
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java
HFCAAffiliation.affToJsonObject
private JsonObject affToJsonObject() { JsonObjectBuilder ob = Json.createObjectBuilder(); if (client.getCAName() != null) { ob.add(HFCAClient.FABRIC_CA_REQPROP, client.getCAName()); } if (this.updateName != null) { ob.add("name", updateName); this.updateName = null; } else { ob.add("name", name); } return ob.build(); }
java
private JsonObject affToJsonObject() { JsonObjectBuilder ob = Json.createObjectBuilder(); if (client.getCAName() != null) { ob.add(HFCAClient.FABRIC_CA_REQPROP, client.getCAName()); } if (this.updateName != null) { ob.add("name", updateName); this.updateName = null; } else { ob.add("name", name); } return ob.build(); }
[ "private", "JsonObject", "affToJsonObject", "(", ")", "{", "JsonObjectBuilder", "ob", "=", "Json", ".", "createObjectBuilder", "(", ")", ";", "if", "(", "client", ".", "getCAName", "(", ")", "!=", "null", ")", "{", "ob", ".", "add", "(", "HFCAClient", ".", "FABRIC_CA_REQPROP", ",", "client", ".", "getCAName", "(", ")", ")", ";", "}", "if", "(", "this", ".", "updateName", "!=", "null", ")", "{", "ob", ".", "add", "(", "\"name\"", ",", "updateName", ")", ";", "this", ".", "updateName", "=", "null", ";", "}", "else", "{", "ob", ".", "add", "(", "\"name\"", ",", "name", ")", ";", "}", "return", "ob", ".", "build", "(", ")", ";", "}" ]
Convert the affiliation request to a JSON object
[ "Convert", "the", "affiliation", "request", "to", "a", "JSON", "object" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java#L498-L511
22,020
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java
HFCAAffiliation.validateAffiliationNames
void validateAffiliationNames(String name) throws InvalidArgumentException { checkFormat(name); if (name.startsWith(".")) { throw new InvalidArgumentException("Affiliation name cannot start with a dot '.'"); } if (name.endsWith(".")) { throw new InvalidArgumentException("Affiliation name cannot end with a dot '.'"); } for (int i = 0; i < name.length(); i++) { if ((name.charAt(i) == '.') && (name.charAt(i) == name.charAt(i - 1))) { throw new InvalidArgumentException("Affiliation name cannot contain multiple consecutive dots '.'"); } } }
java
void validateAffiliationNames(String name) throws InvalidArgumentException { checkFormat(name); if (name.startsWith(".")) { throw new InvalidArgumentException("Affiliation name cannot start with a dot '.'"); } if (name.endsWith(".")) { throw new InvalidArgumentException("Affiliation name cannot end with a dot '.'"); } for (int i = 0; i < name.length(); i++) { if ((name.charAt(i) == '.') && (name.charAt(i) == name.charAt(i - 1))) { throw new InvalidArgumentException("Affiliation name cannot contain multiple consecutive dots '.'"); } } }
[ "void", "validateAffiliationNames", "(", "String", "name", ")", "throws", "InvalidArgumentException", "{", "checkFormat", "(", "name", ")", ";", "if", "(", "name", ".", "startsWith", "(", "\".\"", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Affiliation name cannot start with a dot '.'\"", ")", ";", "}", "if", "(", "name", ".", "endsWith", "(", "\".\"", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Affiliation name cannot end with a dot '.'\"", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "name", ".", "length", "(", ")", ";", "i", "++", ")", "{", "if", "(", "(", "name", ".", "charAt", "(", "i", ")", "==", "'", "'", ")", "&&", "(", "name", ".", "charAt", "(", "i", ")", "==", "name", ".", "charAt", "(", "i", "-", "1", ")", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Affiliation name cannot contain multiple consecutive dots '.'\"", ")", ";", "}", "}", "}" ]
Validate affiliation name for proper formatting @param name the string to test. @throws InvalidArgumentException
[ "Validate", "affiliation", "name", "for", "proper", "formatting" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java#L519-L532
22,021
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/security/HLSDKJCryptoSuiteFactory.java
HLSDKJCryptoSuiteFactory.getDefault
static final synchronized CryptoSuiteFactory getDefault() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException { if (null == theFACTORY) { String cf = config.getDefaultCryptoSuiteFactory(); if (null == cf || cf.isEmpty() || cf.equals(HLSDKJCryptoSuiteFactory.class.getName())) { // Use this class as the factory. theFACTORY = HLSDKJCryptoSuiteFactory.instance(); } else { // Invoke static method instance on factory class specified by config properties. // In this case this class will no longer be used as the factory. Class<?> aClass = Class.forName(cf); Method method = aClass.getMethod("instance"); Object theFACTORYObject = method.invoke(null); if (null == theFACTORYObject) { throw new InstantiationException(String.format("Class specified by %s has instance method returning null. Expected object implementing CryptoSuiteFactory interface.", cf)); } if (!(theFACTORYObject instanceof CryptoSuiteFactory)) { throw new InstantiationException(String.format("Class specified by %s has instance method returning a class %s which does not implement interface CryptoSuiteFactory ", cf, theFACTORYObject.getClass().getName())); } theFACTORY = (CryptoSuiteFactory) theFACTORYObject; } } return theFACTORY; }
java
static final synchronized CryptoSuiteFactory getDefault() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException { if (null == theFACTORY) { String cf = config.getDefaultCryptoSuiteFactory(); if (null == cf || cf.isEmpty() || cf.equals(HLSDKJCryptoSuiteFactory.class.getName())) { // Use this class as the factory. theFACTORY = HLSDKJCryptoSuiteFactory.instance(); } else { // Invoke static method instance on factory class specified by config properties. // In this case this class will no longer be used as the factory. Class<?> aClass = Class.forName(cf); Method method = aClass.getMethod("instance"); Object theFACTORYObject = method.invoke(null); if (null == theFACTORYObject) { throw new InstantiationException(String.format("Class specified by %s has instance method returning null. Expected object implementing CryptoSuiteFactory interface.", cf)); } if (!(theFACTORYObject instanceof CryptoSuiteFactory)) { throw new InstantiationException(String.format("Class specified by %s has instance method returning a class %s which does not implement interface CryptoSuiteFactory ", cf, theFACTORYObject.getClass().getName())); } theFACTORY = (CryptoSuiteFactory) theFACTORYObject; } } return theFACTORY; }
[ "static", "final", "synchronized", "CryptoSuiteFactory", "getDefault", "(", ")", "throws", "ClassNotFoundException", ",", "IllegalAccessException", ",", "InstantiationException", ",", "NoSuchMethodException", ",", "InvocationTargetException", "{", "if", "(", "null", "==", "theFACTORY", ")", "{", "String", "cf", "=", "config", ".", "getDefaultCryptoSuiteFactory", "(", ")", ";", "if", "(", "null", "==", "cf", "||", "cf", ".", "isEmpty", "(", ")", "||", "cf", ".", "equals", "(", "HLSDKJCryptoSuiteFactory", ".", "class", ".", "getName", "(", ")", ")", ")", "{", "// Use this class as the factory.", "theFACTORY", "=", "HLSDKJCryptoSuiteFactory", ".", "instance", "(", ")", ";", "}", "else", "{", "// Invoke static method instance on factory class specified by config properties.", "// In this case this class will no longer be used as the factory.", "Class", "<", "?", ">", "aClass", "=", "Class", ".", "forName", "(", "cf", ")", ";", "Method", "method", "=", "aClass", ".", "getMethod", "(", "\"instance\"", ")", ";", "Object", "theFACTORYObject", "=", "method", ".", "invoke", "(", "null", ")", ";", "if", "(", "null", "==", "theFACTORYObject", ")", "{", "throw", "new", "InstantiationException", "(", "String", ".", "format", "(", "\"Class specified by %s has instance method returning null. Expected object implementing CryptoSuiteFactory interface.\"", ",", "cf", ")", ")", ";", "}", "if", "(", "!", "(", "theFACTORYObject", "instanceof", "CryptoSuiteFactory", ")", ")", "{", "throw", "new", "InstantiationException", "(", "String", ".", "format", "(", "\"Class specified by %s has instance method returning a class %s which does not implement interface CryptoSuiteFactory \"", ",", "cf", ",", "theFACTORYObject", ".", "getClass", "(", ")", ".", "getName", "(", ")", ")", ")", ";", "}", "theFACTORY", "=", "(", "CryptoSuiteFactory", ")", "theFACTORYObject", ";", "}", "}", "return", "theFACTORY", ";", "}" ]
one and only factory.
[ "one", "and", "only", "factory", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/security/HLSDKJCryptoSuiteFactory.java#L82-L117
22,022
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixCredential.java
IdemixCredential.verify
public boolean verify(BIG sk, IdemixIssuerPublicKey ipk) { if (ipk == null || Attrs.length != ipk.getAttributeNames().length) { return false; } for (byte[] attr : Attrs) { if (attr == null) { return false; } } ECP bPrime = new ECP(); bPrime.copy(IdemixUtils.genG1); bPrime.add(ipk.getHsk().mul2(sk, ipk.getHRand(), S)); for (int i = 0; i < Attrs.length / 2; i++) { bPrime.add(ipk.getHAttrs()[2 * i].mul2(BIG.fromBytes(Attrs[2 * i]), ipk.getHAttrs()[2 * i + 1], BIG.fromBytes(Attrs[2 * i + 1]))); } if (Attrs.length % 2 != 0) { bPrime.add(ipk.getHAttrs()[Attrs.length - 1].mul(BIG.fromBytes(Attrs[Attrs.length - 1]))); } if (!B.equals(bPrime)) { return false; } ECP2 a = IdemixUtils.genG2.mul(E); a.add(ipk.getW()); a.affine(); return PAIR.fexp(PAIR.ate(a, A)).equals(PAIR.fexp(PAIR.ate(IdemixUtils.genG2, B))); }
java
public boolean verify(BIG sk, IdemixIssuerPublicKey ipk) { if (ipk == null || Attrs.length != ipk.getAttributeNames().length) { return false; } for (byte[] attr : Attrs) { if (attr == null) { return false; } } ECP bPrime = new ECP(); bPrime.copy(IdemixUtils.genG1); bPrime.add(ipk.getHsk().mul2(sk, ipk.getHRand(), S)); for (int i = 0; i < Attrs.length / 2; i++) { bPrime.add(ipk.getHAttrs()[2 * i].mul2(BIG.fromBytes(Attrs[2 * i]), ipk.getHAttrs()[2 * i + 1], BIG.fromBytes(Attrs[2 * i + 1]))); } if (Attrs.length % 2 != 0) { bPrime.add(ipk.getHAttrs()[Attrs.length - 1].mul(BIG.fromBytes(Attrs[Attrs.length - 1]))); } if (!B.equals(bPrime)) { return false; } ECP2 a = IdemixUtils.genG2.mul(E); a.add(ipk.getW()); a.affine(); return PAIR.fexp(PAIR.ate(a, A)).equals(PAIR.fexp(PAIR.ate(IdemixUtils.genG2, B))); }
[ "public", "boolean", "verify", "(", "BIG", "sk", ",", "IdemixIssuerPublicKey", "ipk", ")", "{", "if", "(", "ipk", "==", "null", "||", "Attrs", ".", "length", "!=", "ipk", ".", "getAttributeNames", "(", ")", ".", "length", ")", "{", "return", "false", ";", "}", "for", "(", "byte", "[", "]", "attr", ":", "Attrs", ")", "{", "if", "(", "attr", "==", "null", ")", "{", "return", "false", ";", "}", "}", "ECP", "bPrime", "=", "new", "ECP", "(", ")", ";", "bPrime", ".", "copy", "(", "IdemixUtils", ".", "genG1", ")", ";", "bPrime", ".", "add", "(", "ipk", ".", "getHsk", "(", ")", ".", "mul2", "(", "sk", ",", "ipk", ".", "getHRand", "(", ")", ",", "S", ")", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "Attrs", ".", "length", "/", "2", ";", "i", "++", ")", "{", "bPrime", ".", "add", "(", "ipk", ".", "getHAttrs", "(", ")", "[", "2", "*", "i", "]", ".", "mul2", "(", "BIG", ".", "fromBytes", "(", "Attrs", "[", "2", "*", "i", "]", ")", ",", "ipk", ".", "getHAttrs", "(", ")", "[", "2", "*", "i", "+", "1", "]", ",", "BIG", ".", "fromBytes", "(", "Attrs", "[", "2", "*", "i", "+", "1", "]", ")", ")", ")", ";", "}", "if", "(", "Attrs", ".", "length", "%", "2", "!=", "0", ")", "{", "bPrime", ".", "add", "(", "ipk", ".", "getHAttrs", "(", ")", "[", "Attrs", ".", "length", "-", "1", "]", ".", "mul", "(", "BIG", ".", "fromBytes", "(", "Attrs", "[", "Attrs", ".", "length", "-", "1", "]", ")", ")", ")", ";", "}", "if", "(", "!", "B", ".", "equals", "(", "bPrime", ")", ")", "{", "return", "false", ";", "}", "ECP2", "a", "=", "IdemixUtils", ".", "genG2", ".", "mul", "(", "E", ")", ";", "a", ".", "add", "(", "ipk", ".", "getW", "(", ")", ")", ";", "a", ".", "affine", "(", ")", ";", "return", "PAIR", ".", "fexp", "(", "PAIR", ".", "ate", "(", "a", ",", "A", ")", ")", ".", "equals", "(", "PAIR", ".", "fexp", "(", "PAIR", ".", "ate", "(", "IdemixUtils", ".", "genG2", ",", "B", ")", ")", ")", ";", "}" ]
verify cryptographically verifies the credential @param sk the secret key of the user @param ipk the public key of the issuer @return true iff valid
[ "verify", "cryptographically", "verifies", "the", "credential" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixCredential.java#L132-L159
22,023
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/BlockInfo.java
BlockInfo.getTransactionCount
public int getTransactionCount() { if (isFiltered()) { int ltransactionCount = transactionCount; if (ltransactionCount < 0) { ltransactionCount = 0; for (int i = filteredBlock.getFilteredTransactionsCount() - 1; i >= 0; --i) { FilteredTransaction filteredTransactions = filteredBlock.getFilteredTransactions(i); Common.HeaderType type = filteredTransactions.getType(); if (type == Common.HeaderType.ENDORSER_TRANSACTION) { ++ltransactionCount; } } transactionCount = ltransactionCount; } return transactionCount; } int ltransactionCount = transactionCount; if (ltransactionCount < 0) { ltransactionCount = 0; for (int i = getEnvelopeCount() - 1; i >= 0; --i) { try { EnvelopeInfo envelopeInfo = getEnvelopeInfo(i); if (envelopeInfo.getType() == TRANSACTION_ENVELOPE) { ++ltransactionCount; } } catch (InvalidProtocolBufferException e) { throw new InvalidProtocolBufferRuntimeException(e); } } transactionCount = ltransactionCount; } return transactionCount; }
java
public int getTransactionCount() { if (isFiltered()) { int ltransactionCount = transactionCount; if (ltransactionCount < 0) { ltransactionCount = 0; for (int i = filteredBlock.getFilteredTransactionsCount() - 1; i >= 0; --i) { FilteredTransaction filteredTransactions = filteredBlock.getFilteredTransactions(i); Common.HeaderType type = filteredTransactions.getType(); if (type == Common.HeaderType.ENDORSER_TRANSACTION) { ++ltransactionCount; } } transactionCount = ltransactionCount; } return transactionCount; } int ltransactionCount = transactionCount; if (ltransactionCount < 0) { ltransactionCount = 0; for (int i = getEnvelopeCount() - 1; i >= 0; --i) { try { EnvelopeInfo envelopeInfo = getEnvelopeInfo(i); if (envelopeInfo.getType() == TRANSACTION_ENVELOPE) { ++ltransactionCount; } } catch (InvalidProtocolBufferException e) { throw new InvalidProtocolBufferRuntimeException(e); } } transactionCount = ltransactionCount; } return transactionCount; }
[ "public", "int", "getTransactionCount", "(", ")", "{", "if", "(", "isFiltered", "(", ")", ")", "{", "int", "ltransactionCount", "=", "transactionCount", ";", "if", "(", "ltransactionCount", "<", "0", ")", "{", "ltransactionCount", "=", "0", ";", "for", "(", "int", "i", "=", "filteredBlock", ".", "getFilteredTransactionsCount", "(", ")", "-", "1", ";", "i", ">=", "0", ";", "--", "i", ")", "{", "FilteredTransaction", "filteredTransactions", "=", "filteredBlock", ".", "getFilteredTransactions", "(", "i", ")", ";", "Common", ".", "HeaderType", "type", "=", "filteredTransactions", ".", "getType", "(", ")", ";", "if", "(", "type", "==", "Common", ".", "HeaderType", ".", "ENDORSER_TRANSACTION", ")", "{", "++", "ltransactionCount", ";", "}", "}", "transactionCount", "=", "ltransactionCount", ";", "}", "return", "transactionCount", ";", "}", "int", "ltransactionCount", "=", "transactionCount", ";", "if", "(", "ltransactionCount", "<", "0", ")", "{", "ltransactionCount", "=", "0", ";", "for", "(", "int", "i", "=", "getEnvelopeCount", "(", ")", "-", "1", ";", "i", ">=", "0", ";", "--", "i", ")", "{", "try", "{", "EnvelopeInfo", "envelopeInfo", "=", "getEnvelopeInfo", "(", "i", ")", ";", "if", "(", "envelopeInfo", ".", "getType", "(", ")", "==", "TRANSACTION_ENVELOPE", ")", "{", "++", "ltransactionCount", ";", "}", "}", "catch", "(", "InvalidProtocolBufferException", "e", ")", "{", "throw", "new", "InvalidProtocolBufferRuntimeException", "(", "e", ")", ";", "}", "}", "transactionCount", "=", "ltransactionCount", ";", "}", "return", "transactionCount", ";", "}" ]
Number of endorser transaction found in the block. @return Number of endorser transaction found in the block.
[ "Number", "of", "endorser", "transaction", "found", "in", "the", "block", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/BlockInfo.java#L153-L189
22,024
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/BlockInfo.java
BlockInfo.getEnvelopeInfo
public EnvelopeInfo getEnvelopeInfo(int envelopeIndex) throws InvalidProtocolBufferException { try { EnvelopeInfo ret; if (isFiltered()) { switch (filteredBlock.getFilteredTransactions(envelopeIndex).getType().getNumber()) { case Common.HeaderType.ENDORSER_TRANSACTION_VALUE: ret = new TransactionEnvelopeInfo(this.filteredBlock.getFilteredTransactions(envelopeIndex)); break; default: //just assume base properties. ret = new EnvelopeInfo(this.filteredBlock.getFilteredTransactions(envelopeIndex)); break; } } else { EnvelopeDeserializer ed = EnvelopeDeserializer.newInstance(block.getBlock().getData().getData(envelopeIndex), block.getTransActionsMetaData()[envelopeIndex]); switch (ed.getType()) { case Common.HeaderType.ENDORSER_TRANSACTION_VALUE: ret = new TransactionEnvelopeInfo((EndorserTransactionEnvDeserializer) ed); break; default: //just assume base properties. ret = new EnvelopeInfo(ed); break; } } return ret; } catch (InvalidProtocolBufferRuntimeException e) { throw e.getCause(); } }
java
public EnvelopeInfo getEnvelopeInfo(int envelopeIndex) throws InvalidProtocolBufferException { try { EnvelopeInfo ret; if (isFiltered()) { switch (filteredBlock.getFilteredTransactions(envelopeIndex).getType().getNumber()) { case Common.HeaderType.ENDORSER_TRANSACTION_VALUE: ret = new TransactionEnvelopeInfo(this.filteredBlock.getFilteredTransactions(envelopeIndex)); break; default: //just assume base properties. ret = new EnvelopeInfo(this.filteredBlock.getFilteredTransactions(envelopeIndex)); break; } } else { EnvelopeDeserializer ed = EnvelopeDeserializer.newInstance(block.getBlock().getData().getData(envelopeIndex), block.getTransActionsMetaData()[envelopeIndex]); switch (ed.getType()) { case Common.HeaderType.ENDORSER_TRANSACTION_VALUE: ret = new TransactionEnvelopeInfo((EndorserTransactionEnvDeserializer) ed); break; default: //just assume base properties. ret = new EnvelopeInfo(ed); break; } } return ret; } catch (InvalidProtocolBufferRuntimeException e) { throw e.getCause(); } }
[ "public", "EnvelopeInfo", "getEnvelopeInfo", "(", "int", "envelopeIndex", ")", "throws", "InvalidProtocolBufferException", "{", "try", "{", "EnvelopeInfo", "ret", ";", "if", "(", "isFiltered", "(", ")", ")", "{", "switch", "(", "filteredBlock", ".", "getFilteredTransactions", "(", "envelopeIndex", ")", ".", "getType", "(", ")", ".", "getNumber", "(", ")", ")", "{", "case", "Common", ".", "HeaderType", ".", "ENDORSER_TRANSACTION_VALUE", ":", "ret", "=", "new", "TransactionEnvelopeInfo", "(", "this", ".", "filteredBlock", ".", "getFilteredTransactions", "(", "envelopeIndex", ")", ")", ";", "break", ";", "default", ":", "//just assume base properties.", "ret", "=", "new", "EnvelopeInfo", "(", "this", ".", "filteredBlock", ".", "getFilteredTransactions", "(", "envelopeIndex", ")", ")", ";", "break", ";", "}", "}", "else", "{", "EnvelopeDeserializer", "ed", "=", "EnvelopeDeserializer", ".", "newInstance", "(", "block", ".", "getBlock", "(", ")", ".", "getData", "(", ")", ".", "getData", "(", "envelopeIndex", ")", ",", "block", ".", "getTransActionsMetaData", "(", ")", "[", "envelopeIndex", "]", ")", ";", "switch", "(", "ed", ".", "getType", "(", ")", ")", "{", "case", "Common", ".", "HeaderType", ".", "ENDORSER_TRANSACTION_VALUE", ":", "ret", "=", "new", "TransactionEnvelopeInfo", "(", "(", "EndorserTransactionEnvDeserializer", ")", "ed", ")", ";", "break", ";", "default", ":", "//just assume base properties.", "ret", "=", "new", "EnvelopeInfo", "(", "ed", ")", ";", "break", ";", "}", "}", "return", "ret", ";", "}", "catch", "(", "InvalidProtocolBufferRuntimeException", "e", ")", "{", "throw", "e", ".", "getCause", "(", ")", ";", "}", "}" ]
Return a specific envelope in the block by it's index. @param envelopeIndex the index into list. @return envelopeIndex the index @throws InvalidProtocolBufferException
[ "Return", "a", "specific", "envelope", "in", "the", "block", "by", "it", "s", "index", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/BlockInfo.java#L371-L409
22,025
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/Orderer.java
Orderer.sendTransaction
Ab.BroadcastResponse sendTransaction(Common.Envelope transaction) throws Exception { if (shutdown) { throw new TransactionException(format("Orderer %s was shutdown.", name)); } logger.debug(format("Orderer.sendTransaction %s", toString())); OrdererClient localOrdererClient = getOrdererClient(); try { return localOrdererClient.sendTransaction(transaction); } catch (Throwable t) { removeOrdererClient(true); throw t; } }
java
Ab.BroadcastResponse sendTransaction(Common.Envelope transaction) throws Exception { if (shutdown) { throw new TransactionException(format("Orderer %s was shutdown.", name)); } logger.debug(format("Orderer.sendTransaction %s", toString())); OrdererClient localOrdererClient = getOrdererClient(); try { return localOrdererClient.sendTransaction(transaction); } catch (Throwable t) { removeOrdererClient(true); throw t; } }
[ "Ab", ".", "BroadcastResponse", "sendTransaction", "(", "Common", ".", "Envelope", "transaction", ")", "throws", "Exception", "{", "if", "(", "shutdown", ")", "{", "throw", "new", "TransactionException", "(", "format", "(", "\"Orderer %s was shutdown.\"", ",", "name", ")", ")", ";", "}", "logger", ".", "debug", "(", "format", "(", "\"Orderer.sendTransaction %s\"", ",", "toString", "(", ")", ")", ")", ";", "OrdererClient", "localOrdererClient", "=", "getOrdererClient", "(", ")", ";", "try", "{", "return", "localOrdererClient", ".", "sendTransaction", "(", "transaction", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "removeOrdererClient", "(", "true", ")", ";", "throw", "t", ";", "}", "}" ]
Send transaction to Order @param transaction transaction to be sent
[ "Send", "transaction", "to", "Order" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/Orderer.java#L151-L168
22,026
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ChaincodeCollectionConfiguration.java
ChaincodeCollectionConfiguration.fromYamlFile
public static ChaincodeCollectionConfiguration fromYamlFile(File configFile) throws InvalidArgumentException, IOException, ChaincodeCollectionConfigurationException { return fromFile(configFile, false); }
java
public static ChaincodeCollectionConfiguration fromYamlFile(File configFile) throws InvalidArgumentException, IOException, ChaincodeCollectionConfigurationException { return fromFile(configFile, false); }
[ "public", "static", "ChaincodeCollectionConfiguration", "fromYamlFile", "(", "File", "configFile", ")", "throws", "InvalidArgumentException", ",", "IOException", ",", "ChaincodeCollectionConfigurationException", "{", "return", "fromFile", "(", "configFile", ",", "false", ")", ";", "}" ]
Creates a new ChaincodeCollectionConfiguration instance configured with details supplied in a YAML file. @param configFile The file containing the network configuration @return A new ChaincodeCollectionConfiguration instance @throws InvalidArgumentException @throws IOException
[ "Creates", "a", "new", "ChaincodeCollectionConfiguration", "instance", "configured", "with", "details", "supplied", "in", "a", "YAML", "file", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ChaincodeCollectionConfiguration.java#L88-L90
22,027
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ChaincodeCollectionConfiguration.java
ChaincodeCollectionConfiguration.fromJsonFile
public static ChaincodeCollectionConfiguration fromJsonFile(File configFile) throws InvalidArgumentException, IOException, ChaincodeCollectionConfigurationException { return fromFile(configFile, true); }
java
public static ChaincodeCollectionConfiguration fromJsonFile(File configFile) throws InvalidArgumentException, IOException, ChaincodeCollectionConfigurationException { return fromFile(configFile, true); }
[ "public", "static", "ChaincodeCollectionConfiguration", "fromJsonFile", "(", "File", "configFile", ")", "throws", "InvalidArgumentException", ",", "IOException", ",", "ChaincodeCollectionConfigurationException", "{", "return", "fromFile", "(", "configFile", ",", "true", ")", ";", "}" ]
Creates a new ChaincodeCollectionConfiguration instance configured with details supplied in a JSON file. @param configFile The file containing the network configuration @return A new ChaincodeCollectionConfiguration instance @throws InvalidArgumentException @throws IOException
[ "Creates", "a", "new", "ChaincodeCollectionConfiguration", "instance", "configured", "with", "details", "supplied", "in", "a", "JSON", "file", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ChaincodeCollectionConfiguration.java#L100-L102
22,028
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ChaincodeCollectionConfiguration.java
ChaincodeCollectionConfiguration.fromYamlStream
public static ChaincodeCollectionConfiguration fromYamlStream(InputStream configStream) throws InvalidArgumentException, ChaincodeCollectionConfigurationException { logger.trace("ChaincodeCollectionConfiguration.fromYamlStream..."); // Sanity check if (configStream == null) { throw new InvalidArgumentException("ConfigStream must be specified"); } Yaml yaml = new Yaml(); @SuppressWarnings ("unchecked") List<Object> map = yaml.load(configStream); JsonArrayBuilder builder = Json.createArrayBuilder(map); JsonArray jsonConfig = builder.build(); return fromJsonObject(jsonConfig); }
java
public static ChaincodeCollectionConfiguration fromYamlStream(InputStream configStream) throws InvalidArgumentException, ChaincodeCollectionConfigurationException { logger.trace("ChaincodeCollectionConfiguration.fromYamlStream..."); // Sanity check if (configStream == null) { throw new InvalidArgumentException("ConfigStream must be specified"); } Yaml yaml = new Yaml(); @SuppressWarnings ("unchecked") List<Object> map = yaml.load(configStream); JsonArrayBuilder builder = Json.createArrayBuilder(map); JsonArray jsonConfig = builder.build(); return fromJsonObject(jsonConfig); }
[ "public", "static", "ChaincodeCollectionConfiguration", "fromYamlStream", "(", "InputStream", "configStream", ")", "throws", "InvalidArgumentException", ",", "ChaincodeCollectionConfigurationException", "{", "logger", ".", "trace", "(", "\"ChaincodeCollectionConfiguration.fromYamlStream...\"", ")", ";", "// Sanity check", "if", "(", "configStream", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"ConfigStream must be specified\"", ")", ";", "}", "Yaml", "yaml", "=", "new", "Yaml", "(", ")", ";", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "List", "<", "Object", ">", "map", "=", "yaml", ".", "load", "(", "configStream", ")", ";", "JsonArrayBuilder", "builder", "=", "Json", ".", "createArrayBuilder", "(", "map", ")", ";", "JsonArray", "jsonConfig", "=", "builder", ".", "build", "(", ")", ";", "return", "fromJsonObject", "(", "jsonConfig", ")", ";", "}" ]
Creates a new ChaincodeCollectionConfiguration instance configured with details supplied in YAML format @param configStream A stream opened on a YAML document containing network configuration details @return A new ChaincodeCollectionConfiguration instance @throws InvalidArgumentException
[ "Creates", "a", "new", "ChaincodeCollectionConfiguration", "instance", "configured", "with", "details", "supplied", "in", "YAML", "format" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ChaincodeCollectionConfiguration.java#L111-L129
22,029
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ChaincodeCollectionConfiguration.java
ChaincodeCollectionConfiguration.fromJsonStream
public static ChaincodeCollectionConfiguration fromJsonStream(InputStream configStream) throws InvalidArgumentException, ChaincodeCollectionConfigurationException { logger.trace("ChaincodeCollectionConfiguration.fromJsonStream..."); // Sanity check if (configStream == null) { throw new InvalidArgumentException("configStream must be specified"); } // Read the input stream and convert to JSON try (JsonReader reader = Json.createReader(configStream)) { return fromJsonObject((JsonArray) reader.read()); } }
java
public static ChaincodeCollectionConfiguration fromJsonStream(InputStream configStream) throws InvalidArgumentException, ChaincodeCollectionConfigurationException { logger.trace("ChaincodeCollectionConfiguration.fromJsonStream..."); // Sanity check if (configStream == null) { throw new InvalidArgumentException("configStream must be specified"); } // Read the input stream and convert to JSON try (JsonReader reader = Json.createReader(configStream)) { return fromJsonObject((JsonArray) reader.read()); } }
[ "public", "static", "ChaincodeCollectionConfiguration", "fromJsonStream", "(", "InputStream", "configStream", ")", "throws", "InvalidArgumentException", ",", "ChaincodeCollectionConfigurationException", "{", "logger", ".", "trace", "(", "\"ChaincodeCollectionConfiguration.fromJsonStream...\"", ")", ";", "// Sanity check", "if", "(", "configStream", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"configStream must be specified\"", ")", ";", "}", "// Read the input stream and convert to JSON", "try", "(", "JsonReader", "reader", "=", "Json", ".", "createReader", "(", "configStream", ")", ")", "{", "return", "fromJsonObject", "(", "(", "JsonArray", ")", "reader", ".", "read", "(", ")", ")", ";", "}", "}" ]
Creates a new ChaincodeCollectionConfiguration instance configured with details supplied in JSON format @param configStream A stream opened on a JSON document containing network configuration details @return A new ChaincodeCollectionConfiguration instance @throws InvalidArgumentException
[ "Creates", "a", "new", "ChaincodeCollectionConfiguration", "instance", "configured", "with", "details", "supplied", "in", "JSON", "format" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ChaincodeCollectionConfiguration.java#L138-L154
22,030
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ChaincodeCollectionConfiguration.java
ChaincodeCollectionConfiguration.fromJsonObject
public static ChaincodeCollectionConfiguration fromJsonObject(JsonArray jsonConfig) throws InvalidArgumentException, ChaincodeCollectionConfigurationException { // Sanity check if (jsonConfig == null) { throw new InvalidArgumentException("jsonConfig must be specified"); } if (logger.isTraceEnabled()) { logger.trace(format("ChaincodeCollectionConfiguration.fromJsonObject: %s", jsonConfig.toString())); } return load(jsonConfig); }
java
public static ChaincodeCollectionConfiguration fromJsonObject(JsonArray jsonConfig) throws InvalidArgumentException, ChaincodeCollectionConfigurationException { // Sanity check if (jsonConfig == null) { throw new InvalidArgumentException("jsonConfig must be specified"); } if (logger.isTraceEnabled()) { logger.trace(format("ChaincodeCollectionConfiguration.fromJsonObject: %s", jsonConfig.toString())); } return load(jsonConfig); }
[ "public", "static", "ChaincodeCollectionConfiguration", "fromJsonObject", "(", "JsonArray", "jsonConfig", ")", "throws", "InvalidArgumentException", ",", "ChaincodeCollectionConfigurationException", "{", "// Sanity check", "if", "(", "jsonConfig", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"jsonConfig must be specified\"", ")", ";", "}", "if", "(", "logger", ".", "isTraceEnabled", "(", ")", ")", "{", "logger", ".", "trace", "(", "format", "(", "\"ChaincodeCollectionConfiguration.fromJsonObject: %s\"", ",", "jsonConfig", ".", "toString", "(", ")", ")", ")", ";", "}", "return", "load", "(", "jsonConfig", ")", ";", "}" ]
Creates a new ChaincodeCollectionConfiguration instance configured with details supplied in a JSON object @param jsonConfig JSON object containing network configuration details @return A new ChaincodeCollectionConfiguration instance @throws InvalidArgumentException
[ "Creates", "a", "new", "ChaincodeCollectionConfiguration", "instance", "configured", "with", "details", "supplied", "in", "a", "JSON", "object" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ChaincodeCollectionConfiguration.java#L163-L175
22,031
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ChaincodeCollectionConfiguration.java
ChaincodeCollectionConfiguration.fromFile
private static ChaincodeCollectionConfiguration fromFile(File configFile, boolean isJson) throws InvalidArgumentException, IOException, ChaincodeCollectionConfigurationException { // Sanity check if (configFile == null) { throw new InvalidArgumentException("configFile must be specified"); } if (logger.isTraceEnabled()) { logger.trace(format("ChaincodeCollectionConfiguration.fromFile: %s isJson = %b", configFile.getAbsolutePath(), isJson)); } // Json file try (InputStream stream = new FileInputStream(configFile)) { return isJson ? fromJsonStream(stream) : fromYamlStream(stream); } }
java
private static ChaincodeCollectionConfiguration fromFile(File configFile, boolean isJson) throws InvalidArgumentException, IOException, ChaincodeCollectionConfigurationException { // Sanity check if (configFile == null) { throw new InvalidArgumentException("configFile must be specified"); } if (logger.isTraceEnabled()) { logger.trace(format("ChaincodeCollectionConfiguration.fromFile: %s isJson = %b", configFile.getAbsolutePath(), isJson)); } // Json file try (InputStream stream = new FileInputStream(configFile)) { return isJson ? fromJsonStream(stream) : fromYamlStream(stream); } }
[ "private", "static", "ChaincodeCollectionConfiguration", "fromFile", "(", "File", "configFile", ",", "boolean", "isJson", ")", "throws", "InvalidArgumentException", ",", "IOException", ",", "ChaincodeCollectionConfigurationException", "{", "// Sanity check", "if", "(", "configFile", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"configFile must be specified\"", ")", ";", "}", "if", "(", "logger", ".", "isTraceEnabled", "(", ")", ")", "{", "logger", ".", "trace", "(", "format", "(", "\"ChaincodeCollectionConfiguration.fromFile: %s isJson = %b\"", ",", "configFile", ".", "getAbsolutePath", "(", ")", ",", "isJson", ")", ")", ";", "}", "// Json file", "try", "(", "InputStream", "stream", "=", "new", "FileInputStream", "(", "configFile", ")", ")", "{", "return", "isJson", "?", "fromJsonStream", "(", "stream", ")", ":", "fromYamlStream", "(", "stream", ")", ";", "}", "}" ]
Loads a ChaincodeCollectionConfiguration object from a Json or Yaml file
[ "Loads", "a", "ChaincodeCollectionConfiguration", "object", "from", "a", "Json", "or", "Yaml", "file" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ChaincodeCollectionConfiguration.java#L193-L209
22,032
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ChaincodeCollectionConfiguration.java
ChaincodeCollectionConfiguration.load
private static ChaincodeCollectionConfiguration load(JsonArray jsonConfig) throws InvalidArgumentException, ChaincodeCollectionConfigurationException { // Sanity check if (jsonConfig == null) { throw new InvalidArgumentException("jsonConfig must be specified"); } return new ChaincodeCollectionConfiguration(jsonConfig); }
java
private static ChaincodeCollectionConfiguration load(JsonArray jsonConfig) throws InvalidArgumentException, ChaincodeCollectionConfigurationException { // Sanity check if (jsonConfig == null) { throw new InvalidArgumentException("jsonConfig must be specified"); } return new ChaincodeCollectionConfiguration(jsonConfig); }
[ "private", "static", "ChaincodeCollectionConfiguration", "load", "(", "JsonArray", "jsonConfig", ")", "throws", "InvalidArgumentException", ",", "ChaincodeCollectionConfigurationException", "{", "// Sanity check", "if", "(", "jsonConfig", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"jsonConfig must be specified\"", ")", ";", "}", "return", "new", "ChaincodeCollectionConfiguration", "(", "jsonConfig", ")", ";", "}" ]
Returns a new ChaincodeCollectionConfiguration instance and populates it from the specified JSON object @param jsonConfig The JSON object containing the config details @return A populated ChaincodeCollectionConfiguration instance @throws InvalidArgumentException
[ "Returns", "a", "new", "ChaincodeCollectionConfiguration", "instance", "and", "populates", "it", "from", "the", "specified", "JSON", "object" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ChaincodeCollectionConfiguration.java#L218-L226
22,033
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryChaincodeDefinitionProposalResponse.java
LifecycleQueryChaincodeDefinitionProposalResponse.getValidationParameter
public byte[] getValidationParameter() throws ProposalException { ByteString payloadBytes = parsePayload().getValidationParameter(); if (null == payloadBytes) { return null; } return payloadBytes.toByteArray(); }
java
public byte[] getValidationParameter() throws ProposalException { ByteString payloadBytes = parsePayload().getValidationParameter(); if (null == payloadBytes) { return null; } return payloadBytes.toByteArray(); }
[ "public", "byte", "[", "]", "getValidationParameter", "(", ")", "throws", "ProposalException", "{", "ByteString", "payloadBytes", "=", "parsePayload", "(", ")", ".", "getValidationParameter", "(", ")", ";", "if", "(", "null", "==", "payloadBytes", ")", "{", "return", "null", ";", "}", "return", "payloadBytes", ".", "toByteArray", "(", ")", ";", "}" ]
The validation parameter bytes that were set when the chaincode was defined. @return validation parameter. @throws ProposalException
[ "The", "validation", "parameter", "bytes", "that", "were", "set", "when", "the", "chaincode", "was", "defined", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryChaincodeDefinitionProposalResponse.java#L75-L82
22,034
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryChaincodeDefinitionProposalResponse.java
LifecycleQueryChaincodeDefinitionProposalResponse.getChaincodeCollectionConfiguration
public ChaincodeCollectionConfiguration getChaincodeCollectionConfiguration() throws ProposalException { Collection.CollectionConfigPackage collections = parsePayload().getCollections(); if (null == collections || !parsePayload().hasCollections()) { return null; } try { return ChaincodeCollectionConfiguration.fromCollectionConfigPackage(collections); } catch (InvalidArgumentException e) { throw new ProposalException(e); } }
java
public ChaincodeCollectionConfiguration getChaincodeCollectionConfiguration() throws ProposalException { Collection.CollectionConfigPackage collections = parsePayload().getCollections(); if (null == collections || !parsePayload().hasCollections()) { return null; } try { return ChaincodeCollectionConfiguration.fromCollectionConfigPackage(collections); } catch (InvalidArgumentException e) { throw new ProposalException(e); } }
[ "public", "ChaincodeCollectionConfiguration", "getChaincodeCollectionConfiguration", "(", ")", "throws", "ProposalException", "{", "Collection", ".", "CollectionConfigPackage", "collections", "=", "parsePayload", "(", ")", ".", "getCollections", "(", ")", ";", "if", "(", "null", "==", "collections", "||", "!", "parsePayload", "(", ")", ".", "hasCollections", "(", ")", ")", "{", "return", "null", ";", "}", "try", "{", "return", "ChaincodeCollectionConfiguration", ".", "fromCollectionConfigPackage", "(", "collections", ")", ";", "}", "catch", "(", "InvalidArgumentException", "e", ")", "{", "throw", "new", "ProposalException", "(", "e", ")", ";", "}", "}" ]
The collection configuration this chaincode was defined. @return chaincode collection @throws ProposalException
[ "The", "collection", "configuration", "this", "chaincode", "was", "defined", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryChaincodeDefinitionProposalResponse.java#L120-L131
22,035
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixPseudonymSignature.java
IdemixPseudonymSignature.verify
public boolean verify(ECP nym, IdemixIssuerPublicKey ipk, byte[] msg) { if (nym == null || ipk == null || msg == null) { return false; } ECP t = ipk.getHsk().mul2(proofSSk, ipk.getHRand(), proofSRNym); t.sub(nym.mul(proofC)); // create array for proof data that will contain the sign label, 2 ECPs (each of length 2* FIELD_BYTES + 1), the ipk hash and the message byte[] proofData = new byte[0]; proofData = IdemixUtils.append(proofData, NYM_SIGN_LABEL.getBytes()); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(t)); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(nym)); proofData = IdemixUtils.append(proofData, ipk.getHash()); proofData = IdemixUtils.append(proofData, msg); BIG cvalue = IdemixUtils.hashModOrder(proofData); byte[] finalProofData = new byte[0]; finalProofData = IdemixUtils.append(finalProofData, IdemixUtils.bigToBytes(cvalue)); finalProofData = IdemixUtils.append(finalProofData, IdemixUtils.bigToBytes(nonce)); byte[] hashedProofData = IdemixUtils.bigToBytes(IdemixUtils.hashModOrder(finalProofData)); return Arrays.equals(IdemixUtils.bigToBytes(proofC), hashedProofData); }
java
public boolean verify(ECP nym, IdemixIssuerPublicKey ipk, byte[] msg) { if (nym == null || ipk == null || msg == null) { return false; } ECP t = ipk.getHsk().mul2(proofSSk, ipk.getHRand(), proofSRNym); t.sub(nym.mul(proofC)); // create array for proof data that will contain the sign label, 2 ECPs (each of length 2* FIELD_BYTES + 1), the ipk hash and the message byte[] proofData = new byte[0]; proofData = IdemixUtils.append(proofData, NYM_SIGN_LABEL.getBytes()); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(t)); proofData = IdemixUtils.append(proofData, IdemixUtils.ecpToBytes(nym)); proofData = IdemixUtils.append(proofData, ipk.getHash()); proofData = IdemixUtils.append(proofData, msg); BIG cvalue = IdemixUtils.hashModOrder(proofData); byte[] finalProofData = new byte[0]; finalProofData = IdemixUtils.append(finalProofData, IdemixUtils.bigToBytes(cvalue)); finalProofData = IdemixUtils.append(finalProofData, IdemixUtils.bigToBytes(nonce)); byte[] hashedProofData = IdemixUtils.bigToBytes(IdemixUtils.hashModOrder(finalProofData)); return Arrays.equals(IdemixUtils.bigToBytes(proofC), hashedProofData); }
[ "public", "boolean", "verify", "(", "ECP", "nym", ",", "IdemixIssuerPublicKey", "ipk", ",", "byte", "[", "]", "msg", ")", "{", "if", "(", "nym", "==", "null", "||", "ipk", "==", "null", "||", "msg", "==", "null", ")", "{", "return", "false", ";", "}", "ECP", "t", "=", "ipk", ".", "getHsk", "(", ")", ".", "mul2", "(", "proofSSk", ",", "ipk", ".", "getHRand", "(", ")", ",", "proofSRNym", ")", ";", "t", ".", "sub", "(", "nym", ".", "mul", "(", "proofC", ")", ")", ";", "// create array for proof data that will contain the sign label, 2 ECPs (each of length 2* FIELD_BYTES + 1), the ipk hash and the message", "byte", "[", "]", "proofData", "=", "new", "byte", "[", "0", "]", ";", "proofData", "=", "IdemixUtils", ".", "append", "(", "proofData", ",", "NYM_SIGN_LABEL", ".", "getBytes", "(", ")", ")", ";", "proofData", "=", "IdemixUtils", ".", "append", "(", "proofData", ",", "IdemixUtils", ".", "ecpToBytes", "(", "t", ")", ")", ";", "proofData", "=", "IdemixUtils", ".", "append", "(", "proofData", ",", "IdemixUtils", ".", "ecpToBytes", "(", "nym", ")", ")", ";", "proofData", "=", "IdemixUtils", ".", "append", "(", "proofData", ",", "ipk", ".", "getHash", "(", ")", ")", ";", "proofData", "=", "IdemixUtils", ".", "append", "(", "proofData", ",", "msg", ")", ";", "BIG", "cvalue", "=", "IdemixUtils", ".", "hashModOrder", "(", "proofData", ")", ";", "byte", "[", "]", "finalProofData", "=", "new", "byte", "[", "0", "]", ";", "finalProofData", "=", "IdemixUtils", ".", "append", "(", "finalProofData", ",", "IdemixUtils", ".", "bigToBytes", "(", "cvalue", ")", ")", ";", "finalProofData", "=", "IdemixUtils", ".", "append", "(", "finalProofData", ",", "IdemixUtils", ".", "bigToBytes", "(", "nonce", ")", ")", ";", "byte", "[", "]", "hashedProofData", "=", "IdemixUtils", ".", "bigToBytes", "(", "IdemixUtils", ".", "hashModOrder", "(", "finalProofData", ")", ")", ";", "return", "Arrays", ".", "equals", "(", "IdemixUtils", ".", "bigToBytes", "(", "proofC", ")", ",", "hashedProofData", ")", ";", "}" ]
Verify this IdemixPseudonymSignature @param nym the pseudonym with respect to which the signature is verified @param ipk the issuer public key @param msg the message that should be signed in this signature @return true iff valid
[ "Verify", "this", "IdemixPseudonymSignature" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixPseudonymSignature.java#L105-L129
22,036
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixSignature.java
IdemixSignature.toProto
public Idemix.Signature toProto() { Idemix.Signature.Builder builder = Idemix.Signature.newBuilder() .setAPrime(IdemixUtils.transformToProto(aPrime)) .setABar(IdemixUtils.transformToProto(aBar)) .setBPrime(IdemixUtils.transformToProto(bPrime)) .setNym(IdemixUtils.transformToProto(nym)) .setProofC(ByteString.copyFrom(IdemixUtils.bigToBytes(proofC))) .setProofSSk(ByteString.copyFrom(IdemixUtils.bigToBytes(proofSSk))) .setProofSE(ByteString.copyFrom(IdemixUtils.bigToBytes(proofSE))) .setProofSR2(ByteString.copyFrom(IdemixUtils.bigToBytes(proofSR2))) .setProofSR3(ByteString.copyFrom(IdemixUtils.bigToBytes(proofSR3))) .setProofSRNym(ByteString.copyFrom(IdemixUtils.bigToBytes(proofSRNym))) .setProofSSPrime(ByteString.copyFrom(IdemixUtils.bigToBytes(proofSSPrime))) .setNonce(ByteString.copyFrom(IdemixUtils.bigToBytes(nonce))) .setRevocationEpochPk(revocationPk) .setRevocationPkSig(ByteString.copyFrom(revocationPKSig)) .setEpoch(epoch) .setNonRevocationProof(nonRevocationProof); for (BIG attr : proofSAttrs) { builder.addProofSAttrs(ByteString.copyFrom(IdemixUtils.bigToBytes(attr))); } return builder.build(); }
java
public Idemix.Signature toProto() { Idemix.Signature.Builder builder = Idemix.Signature.newBuilder() .setAPrime(IdemixUtils.transformToProto(aPrime)) .setABar(IdemixUtils.transformToProto(aBar)) .setBPrime(IdemixUtils.transformToProto(bPrime)) .setNym(IdemixUtils.transformToProto(nym)) .setProofC(ByteString.copyFrom(IdemixUtils.bigToBytes(proofC))) .setProofSSk(ByteString.copyFrom(IdemixUtils.bigToBytes(proofSSk))) .setProofSE(ByteString.copyFrom(IdemixUtils.bigToBytes(proofSE))) .setProofSR2(ByteString.copyFrom(IdemixUtils.bigToBytes(proofSR2))) .setProofSR3(ByteString.copyFrom(IdemixUtils.bigToBytes(proofSR3))) .setProofSRNym(ByteString.copyFrom(IdemixUtils.bigToBytes(proofSRNym))) .setProofSSPrime(ByteString.copyFrom(IdemixUtils.bigToBytes(proofSSPrime))) .setNonce(ByteString.copyFrom(IdemixUtils.bigToBytes(nonce))) .setRevocationEpochPk(revocationPk) .setRevocationPkSig(ByteString.copyFrom(revocationPKSig)) .setEpoch(epoch) .setNonRevocationProof(nonRevocationProof); for (BIG attr : proofSAttrs) { builder.addProofSAttrs(ByteString.copyFrom(IdemixUtils.bigToBytes(attr))); } return builder.build(); }
[ "public", "Idemix", ".", "Signature", "toProto", "(", ")", "{", "Idemix", ".", "Signature", ".", "Builder", "builder", "=", "Idemix", ".", "Signature", ".", "newBuilder", "(", ")", ".", "setAPrime", "(", "IdemixUtils", ".", "transformToProto", "(", "aPrime", ")", ")", ".", "setABar", "(", "IdemixUtils", ".", "transformToProto", "(", "aBar", ")", ")", ".", "setBPrime", "(", "IdemixUtils", ".", "transformToProto", "(", "bPrime", ")", ")", ".", "setNym", "(", "IdemixUtils", ".", "transformToProto", "(", "nym", ")", ")", ".", "setProofC", "(", "ByteString", ".", "copyFrom", "(", "IdemixUtils", ".", "bigToBytes", "(", "proofC", ")", ")", ")", ".", "setProofSSk", "(", "ByteString", ".", "copyFrom", "(", "IdemixUtils", ".", "bigToBytes", "(", "proofSSk", ")", ")", ")", ".", "setProofSE", "(", "ByteString", ".", "copyFrom", "(", "IdemixUtils", ".", "bigToBytes", "(", "proofSE", ")", ")", ")", ".", "setProofSR2", "(", "ByteString", ".", "copyFrom", "(", "IdemixUtils", ".", "bigToBytes", "(", "proofSR2", ")", ")", ")", ".", "setProofSR3", "(", "ByteString", ".", "copyFrom", "(", "IdemixUtils", ".", "bigToBytes", "(", "proofSR3", ")", ")", ")", ".", "setProofSRNym", "(", "ByteString", ".", "copyFrom", "(", "IdemixUtils", ".", "bigToBytes", "(", "proofSRNym", ")", ")", ")", ".", "setProofSSPrime", "(", "ByteString", ".", "copyFrom", "(", "IdemixUtils", ".", "bigToBytes", "(", "proofSSPrime", ")", ")", ")", ".", "setNonce", "(", "ByteString", ".", "copyFrom", "(", "IdemixUtils", ".", "bigToBytes", "(", "nonce", ")", ")", ")", ".", "setRevocationEpochPk", "(", "revocationPk", ")", ".", "setRevocationPkSig", "(", "ByteString", ".", "copyFrom", "(", "revocationPKSig", ")", ")", ".", "setEpoch", "(", "epoch", ")", ".", "setNonRevocationProof", "(", "nonRevocationProof", ")", ";", "for", "(", "BIG", "attr", ":", "proofSAttrs", ")", "{", "builder", ".", "addProofSAttrs", "(", "ByteString", ".", "copyFrom", "(", "IdemixUtils", ".", "bigToBytes", "(", "attr", ")", ")", ")", ";", "}", "return", "builder", ".", "build", "(", ")", ";", "}" ]
Convert this signature to a proto @return a protobuf object representing this IdemixSignature
[ "Convert", "this", "signature", "to", "a", "proto" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixSignature.java#L352-L376
22,037
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixSignature.java
IdemixSignature.hiddenIndices
private int[] hiddenIndices(boolean[] disclosure) { if (disclosure == null) { throw new IllegalArgumentException("cannot compute hidden indices of null disclosure"); } List<Integer> hiddenIndicesList = new ArrayList<>(); for (int i = 0; i < disclosure.length; i++) { if (!disclosure[i]) { hiddenIndicesList.add(i); } } int[] hiddenIndices = new int[hiddenIndicesList.size()]; for (int i = 0; i < hiddenIndicesList.size(); i++) { hiddenIndices[i] = hiddenIndicesList.get(i); } return hiddenIndices; }
java
private int[] hiddenIndices(boolean[] disclosure) { if (disclosure == null) { throw new IllegalArgumentException("cannot compute hidden indices of null disclosure"); } List<Integer> hiddenIndicesList = new ArrayList<>(); for (int i = 0; i < disclosure.length; i++) { if (!disclosure[i]) { hiddenIndicesList.add(i); } } int[] hiddenIndices = new int[hiddenIndicesList.size()]; for (int i = 0; i < hiddenIndicesList.size(); i++) { hiddenIndices[i] = hiddenIndicesList.get(i); } return hiddenIndices; }
[ "private", "int", "[", "]", "hiddenIndices", "(", "boolean", "[", "]", "disclosure", ")", "{", "if", "(", "disclosure", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"cannot compute hidden indices of null disclosure\"", ")", ";", "}", "List", "<", "Integer", ">", "hiddenIndicesList", "=", "new", "ArrayList", "<>", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "disclosure", ".", "length", ";", "i", "++", ")", "{", "if", "(", "!", "disclosure", "[", "i", "]", ")", "{", "hiddenIndicesList", ".", "add", "(", "i", ")", ";", "}", "}", "int", "[", "]", "hiddenIndices", "=", "new", "int", "[", "hiddenIndicesList", ".", "size", "(", ")", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "hiddenIndicesList", ".", "size", "(", ")", ";", "i", "++", ")", "{", "hiddenIndices", "[", "i", "]", "=", "hiddenIndicesList", ".", "get", "(", "i", ")", ";", "}", "return", "hiddenIndices", ";", "}" ]
Some attributes may be hidden, some disclosed. The indices of the hidden attributes will be passed. @param disclosure an array where the i-th value indicates whether or not the i-th attribute should be disclosed @return an integer array of the hidden indices
[ "Some", "attributes", "may", "be", "hidden", "some", "disclosed", ".", "The", "indices", "of", "the", "hidden", "attributes", "will", "be", "passed", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/idemix/IdemixSignature.java#L384-L400
22,038
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/HFClient.java
HFClient.setExecutorService
public synchronized void setExecutorService(ExecutorService executorService) throws InvalidArgumentException { if (executorService == null) { throw new InvalidArgumentException("Executor service can not be null."); } if (this.executorService != null && this.executorService != executorService) { throw new InvalidArgumentException("Executor service has already been set."); } this.executorService = executorService; }
java
public synchronized void setExecutorService(ExecutorService executorService) throws InvalidArgumentException { if (executorService == null) { throw new InvalidArgumentException("Executor service can not be null."); } if (this.executorService != null && this.executorService != executorService) { throw new InvalidArgumentException("Executor service has already been set."); } this.executorService = executorService; }
[ "public", "synchronized", "void", "setExecutorService", "(", "ExecutorService", "executorService", ")", "throws", "InvalidArgumentException", "{", "if", "(", "executorService", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Executor service can not be null.\"", ")", ";", "}", "if", "(", "this", ".", "executorService", "!=", "null", "&&", "this", ".", "executorService", "!=", "executorService", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Executor service has already been set.\"", ")", ";", "}", "this", ".", "executorService", "=", "executorService", ";", "}" ]
Set executor service Applications need to set the executor service prior to doing any other operations on the client. @param executorService The executor service the application wants to use. @throws InvalidArgumentException if executor service has been set already.
[ "Set", "executor", "service", "Applications", "need", "to", "set", "the", "executor", "service", "prior", "to", "doing", "any", "other", "operations", "on", "the", "client", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/HFClient.java#L132-L143
22,039
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/HFClient.java
HFClient.newChannel
public Channel newChannel(String name) throws InvalidArgumentException { clientCheck(); if (Utils.isNullOrEmpty(name)) { throw new InvalidArgumentException("Channel name can not be null or empty string."); } synchronized (channels) { if (channels.containsKey(name)) { throw new InvalidArgumentException(format("Channel by the name %s already exists", name)); } logger.trace("Creating channel :" + name); Channel newChannel = Channel.createNewInstance(name, this); channels.put(name, newChannel); return newChannel; } }
java
public Channel newChannel(String name) throws InvalidArgumentException { clientCheck(); if (Utils.isNullOrEmpty(name)) { throw new InvalidArgumentException("Channel name can not be null or empty string."); } synchronized (channels) { if (channels.containsKey(name)) { throw new InvalidArgumentException(format("Channel by the name %s already exists", name)); } logger.trace("Creating channel :" + name); Channel newChannel = Channel.createNewInstance(name, this); channels.put(name, newChannel); return newChannel; } }
[ "public", "Channel", "newChannel", "(", "String", "name", ")", "throws", "InvalidArgumentException", "{", "clientCheck", "(", ")", ";", "if", "(", "Utils", ".", "isNullOrEmpty", "(", "name", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Channel name can not be null or empty string.\"", ")", ";", "}", "synchronized", "(", "channels", ")", "{", "if", "(", "channels", ".", "containsKey", "(", "name", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "format", "(", "\"Channel by the name %s already exists\"", ",", "name", ")", ")", ";", "}", "logger", ".", "trace", "(", "\"Creating channel :\"", "+", "name", ")", ";", "Channel", "newChannel", "=", "Channel", ".", "createNewInstance", "(", "name", ",", "this", ")", ";", "channels", ".", "put", "(", "name", ",", "newChannel", ")", ";", "return", "newChannel", ";", "}", "}" ]
newChannel - already configured channel. @param name @return a new channel. @throws InvalidArgumentException
[ "newChannel", "-", "already", "configured", "channel", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/HFClient.java#L230-L249
22,040
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/HFClient.java
HFClient.newChannel
public Channel newChannel(String name, Orderer orderer, ChannelConfiguration channelConfiguration, byte[]... channelConfigurationSignatures) throws TransactionException, InvalidArgumentException { clientCheck(); if (Utils.isNullOrEmpty(name)) { throw new InvalidArgumentException("Channel name can not be null or empty string."); } synchronized (channels) { if (channels.containsKey(name)) { throw new InvalidArgumentException(format("Channel by the name %s already exits", name)); } logger.trace("Creating channel :" + name); Channel newChannel = Channel.createNewInstance(name, this, orderer, channelConfiguration, channelConfigurationSignatures); channels.put(name, newChannel); return newChannel; } }
java
public Channel newChannel(String name, Orderer orderer, ChannelConfiguration channelConfiguration, byte[]... channelConfigurationSignatures) throws TransactionException, InvalidArgumentException { clientCheck(); if (Utils.isNullOrEmpty(name)) { throw new InvalidArgumentException("Channel name can not be null or empty string."); } synchronized (channels) { if (channels.containsKey(name)) { throw new InvalidArgumentException(format("Channel by the name %s already exits", name)); } logger.trace("Creating channel :" + name); Channel newChannel = Channel.createNewInstance(name, this, orderer, channelConfiguration, channelConfigurationSignatures); channels.put(name, newChannel); return newChannel; } }
[ "public", "Channel", "newChannel", "(", "String", "name", ",", "Orderer", "orderer", ",", "ChannelConfiguration", "channelConfiguration", ",", "byte", "[", "]", "...", "channelConfigurationSignatures", ")", "throws", "TransactionException", ",", "InvalidArgumentException", "{", "clientCheck", "(", ")", ";", "if", "(", "Utils", ".", "isNullOrEmpty", "(", "name", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Channel name can not be null or empty string.\"", ")", ";", "}", "synchronized", "(", "channels", ")", "{", "if", "(", "channels", ".", "containsKey", "(", "name", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "format", "(", "\"Channel by the name %s already exits\"", ",", "name", ")", ")", ";", "}", "logger", ".", "trace", "(", "\"Creating channel :\"", "+", "name", ")", ";", "Channel", "newChannel", "=", "Channel", ".", "createNewInstance", "(", "name", ",", "this", ",", "orderer", ",", "channelConfiguration", ",", "channelConfigurationSignatures", ")", ";", "channels", ".", "put", "(", "name", ",", "newChannel", ")", ";", "return", "newChannel", ";", "}", "}" ]
Create a new channel @param name The channel's name @param orderer Orderer to create the channel with. @param channelConfiguration Channel configuration data. @param channelConfigurationSignatures byte arrays containing ConfigSignature's proto serialized. See {@link Channel#getChannelConfigurationSignature} on how to create @return a new channel. @throws TransactionException @throws InvalidArgumentException
[ "Create", "a", "new", "channel" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/HFClient.java#L264-L288
22,041
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/HFClient.java
HFClient.newPeer
public Peer newPeer(String name, String grpcURL) throws InvalidArgumentException { clientCheck(); return Peer.createNewInstance(name, grpcURL, null); }
java
public Peer newPeer(String name, String grpcURL) throws InvalidArgumentException { clientCheck(); return Peer.createNewInstance(name, grpcURL, null); }
[ "public", "Peer", "newPeer", "(", "String", "name", ",", "String", "grpcURL", ")", "throws", "InvalidArgumentException", "{", "clientCheck", "(", ")", ";", "return", "Peer", ".", "createNewInstance", "(", "name", ",", "grpcURL", ",", "null", ")", ";", "}" ]
newPeer create a new peer @param name @param grpcURL to the peer's location @return Peer @throws InvalidArgumentException
[ "newPeer", "create", "a", "new", "peer" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/HFClient.java#L406-L409
22,042
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/HFClient.java
HFClient.sendLifecycleQueryInstalledChaincode
public Collection<LifecycleQueryInstalledChaincodeProposalResponse> sendLifecycleQueryInstalledChaincode(LifecycleQueryInstalledChaincodeRequest lifecycleQueryInstalledChaincodeRequest, Collection<Peer> peers) throws InvalidArgumentException, ProposalException { if (null == lifecycleQueryInstalledChaincodeRequest) { throw new InvalidArgumentException("The lifecycleQueryInstalledChaincodeRequest parameter can not be null."); } clientCheck(); if (null == peers) { throw new InvalidArgumentException("The parameter peers set to null"); } if (peers.isEmpty()) { throw new InvalidArgumentException("Peers to query is empty."); } if (lifecycleQueryInstalledChaincodeRequest == null) { throw new InvalidArgumentException("The lifecycleQueryInstalledChaincoded parameter must not be null."); } if (Utils.isNullOrEmpty(lifecycleQueryInstalledChaincodeRequest.getPackageId())) { throw new InvalidArgumentException("The lifecycleQueryInstalledChaincoded packageID parameter must not be null."); } try { //Run this on a system channel. Channel systemChannel = Channel.newSystemChannel(this); return systemChannel.lifecycleQueryInstalledChaincode(lifecycleQueryInstalledChaincodeRequest, peers); } catch (ProposalException e) { logger.error(format("lifecycleQueryInstalledChaincodeRequest for failed. %s", e.getMessage()), e); throw e; } }
java
public Collection<LifecycleQueryInstalledChaincodeProposalResponse> sendLifecycleQueryInstalledChaincode(LifecycleQueryInstalledChaincodeRequest lifecycleQueryInstalledChaincodeRequest, Collection<Peer> peers) throws InvalidArgumentException, ProposalException { if (null == lifecycleQueryInstalledChaincodeRequest) { throw new InvalidArgumentException("The lifecycleQueryInstalledChaincodeRequest parameter can not be null."); } clientCheck(); if (null == peers) { throw new InvalidArgumentException("The parameter peers set to null"); } if (peers.isEmpty()) { throw new InvalidArgumentException("Peers to query is empty."); } if (lifecycleQueryInstalledChaincodeRequest == null) { throw new InvalidArgumentException("The lifecycleQueryInstalledChaincoded parameter must not be null."); } if (Utils.isNullOrEmpty(lifecycleQueryInstalledChaincodeRequest.getPackageId())) { throw new InvalidArgumentException("The lifecycleQueryInstalledChaincoded packageID parameter must not be null."); } try { //Run this on a system channel. Channel systemChannel = Channel.newSystemChannel(this); return systemChannel.lifecycleQueryInstalledChaincode(lifecycleQueryInstalledChaincodeRequest, peers); } catch (ProposalException e) { logger.error(format("lifecycleQueryInstalledChaincodeRequest for failed. %s", e.getMessage()), e); throw e; } }
[ "public", "Collection", "<", "LifecycleQueryInstalledChaincodeProposalResponse", ">", "sendLifecycleQueryInstalledChaincode", "(", "LifecycleQueryInstalledChaincodeRequest", "lifecycleQueryInstalledChaincodeRequest", ",", "Collection", "<", "Peer", ">", "peers", ")", "throws", "InvalidArgumentException", ",", "ProposalException", "{", "if", "(", "null", "==", "lifecycleQueryInstalledChaincodeRequest", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The lifecycleQueryInstalledChaincodeRequest parameter can not be null.\"", ")", ";", "}", "clientCheck", "(", ")", ";", "if", "(", "null", "==", "peers", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The parameter peers set to null\"", ")", ";", "}", "if", "(", "peers", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Peers to query is empty.\"", ")", ";", "}", "if", "(", "lifecycleQueryInstalledChaincodeRequest", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The lifecycleQueryInstalledChaincoded parameter must not be null.\"", ")", ";", "}", "if", "(", "Utils", ".", "isNullOrEmpty", "(", "lifecycleQueryInstalledChaincodeRequest", ".", "getPackageId", "(", ")", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The lifecycleQueryInstalledChaincoded packageID parameter must not be null.\"", ")", ";", "}", "try", "{", "//Run this on a system channel.", "Channel", "systemChannel", "=", "Channel", ".", "newSystemChannel", "(", "this", ")", ";", "return", "systemChannel", ".", "lifecycleQueryInstalledChaincode", "(", "lifecycleQueryInstalledChaincodeRequest", ",", "peers", ")", ";", "}", "catch", "(", "ProposalException", "e", ")", "{", "logger", ".", "error", "(", "format", "(", "\"lifecycleQueryInstalledChaincodeRequest for failed. %s\"", ",", "e", ".", "getMessage", "(", ")", ")", ",", "e", ")", ";", "throw", "e", ";", "}", "}" ]
Query installed chaincode on a peer. @param lifecycleQueryInstalledChaincodeRequest The request {@link LifecycleQueryInstalledChaincodeRequest} @param peers the peer to send the request to. @return LifecycleQueryInstalledChaincodeProposalResponse @throws InvalidArgumentException @throws ProposalException
[ "Query", "installed", "chaincode", "on", "a", "peer", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/HFClient.java#L539-L578
22,043
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/HFClient.java
HFClient.sendLifecycleQueryInstalledChaincodes
public Collection<LifecycleQueryInstalledChaincodesProposalResponse> sendLifecycleQueryInstalledChaincodes(LifecycleQueryInstalledChaincodesRequest lifecycleQueryInstalledChaincodesRequest, Collection<Peer> peers) throws InvalidArgumentException, ProposalException { if (null == lifecycleQueryInstalledChaincodesRequest) { throw new InvalidArgumentException("The lifecycleQueryInstalledChaincodesRequest parameter can not be null."); } clientCheck(); if (null == peers) { throw new InvalidArgumentException("The peers set to null"); } if (peers.isEmpty()) { throw new InvalidArgumentException("The peers parameter is empty."); } try { //Run this on a system channel. Channel systemChannel = Channel.newSystemChannel(this); return systemChannel.lifecycleQueryInstalledChaincodes(lifecycleQueryInstalledChaincodesRequest, peers); } catch (ProposalException e) { logger.error(e); throw e; } }
java
public Collection<LifecycleQueryInstalledChaincodesProposalResponse> sendLifecycleQueryInstalledChaincodes(LifecycleQueryInstalledChaincodesRequest lifecycleQueryInstalledChaincodesRequest, Collection<Peer> peers) throws InvalidArgumentException, ProposalException { if (null == lifecycleQueryInstalledChaincodesRequest) { throw new InvalidArgumentException("The lifecycleQueryInstalledChaincodesRequest parameter can not be null."); } clientCheck(); if (null == peers) { throw new InvalidArgumentException("The peers set to null"); } if (peers.isEmpty()) { throw new InvalidArgumentException("The peers parameter is empty."); } try { //Run this on a system channel. Channel systemChannel = Channel.newSystemChannel(this); return systemChannel.lifecycleQueryInstalledChaincodes(lifecycleQueryInstalledChaincodesRequest, peers); } catch (ProposalException e) { logger.error(e); throw e; } }
[ "public", "Collection", "<", "LifecycleQueryInstalledChaincodesProposalResponse", ">", "sendLifecycleQueryInstalledChaincodes", "(", "LifecycleQueryInstalledChaincodesRequest", "lifecycleQueryInstalledChaincodesRequest", ",", "Collection", "<", "Peer", ">", "peers", ")", "throws", "InvalidArgumentException", ",", "ProposalException", "{", "if", "(", "null", "==", "lifecycleQueryInstalledChaincodesRequest", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The lifecycleQueryInstalledChaincodesRequest parameter can not be null.\"", ")", ";", "}", "clientCheck", "(", ")", ";", "if", "(", "null", "==", "peers", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The peers set to null\"", ")", ";", "}", "if", "(", "peers", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The peers parameter is empty.\"", ")", ";", "}", "try", "{", "//Run this on a system channel.", "Channel", "systemChannel", "=", "Channel", ".", "newSystemChannel", "(", "this", ")", ";", "return", "systemChannel", ".", "lifecycleQueryInstalledChaincodes", "(", "lifecycleQueryInstalledChaincodesRequest", ",", "peers", ")", ";", "}", "catch", "(", "ProposalException", "e", ")", "{", "logger", ".", "error", "(", "e", ")", ";", "throw", "e", ";", "}", "}" ]
Query the peer for installed chaincodes information @param lifecycleQueryInstalledChaincodesRequest the request {@link LifecycleQueryInstalledChaincodesRequest} @param peers The peer to query. @return Collection of ChaincodeInfo on installed chaincode @see {@link LifecycleQueryInstalledChaincodesProposalResponse} @throws InvalidArgumentException @throws ProposalException
[ "Query", "the", "peer", "for", "installed", "chaincodes", "information" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/HFClient.java#L590-L618
22,044
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/HFClient.java
HFClient.setUserContext
public User setUserContext(User userContext) throws InvalidArgumentException { if (null == cryptoSuite) { throw new InvalidArgumentException("No cryptoSuite has been set."); } userContextCheck(userContext); User ret = this.userContext; this.userContext = userContext; logger.debug( format("Setting user context to MSPID: %s user: %s", userContext.getMspId(), userContext.getName())); return ret; }
java
public User setUserContext(User userContext) throws InvalidArgumentException { if (null == cryptoSuite) { throw new InvalidArgumentException("No cryptoSuite has been set."); } userContextCheck(userContext); User ret = this.userContext; this.userContext = userContext; logger.debug( format("Setting user context to MSPID: %s user: %s", userContext.getMspId(), userContext.getName())); return ret; }
[ "public", "User", "setUserContext", "(", "User", "userContext", ")", "throws", "InvalidArgumentException", "{", "if", "(", "null", "==", "cryptoSuite", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"No cryptoSuite has been set.\"", ")", ";", "}", "userContextCheck", "(", "userContext", ")", ";", "User", "ret", "=", "this", ".", "userContext", ";", "this", ".", "userContext", "=", "userContext", ";", "logger", ".", "debug", "(", "format", "(", "\"Setting user context to MSPID: %s user: %s\"", ",", "userContext", ".", "getMspId", "(", ")", ",", "userContext", ".", "getName", "(", ")", ")", ")", ";", "return", "ret", ";", "}" ]
Set the User context for this client. @param userContext @return the old user context. Maybe null if never set! @throws InvalidArgumentException
[ "Set", "the", "User", "context", "for", "this", "client", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/HFClient.java#L669-L683
22,045
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/HFClient.java
HFClient.newOrderer
public Orderer newOrderer(String name, String grpcURL) throws InvalidArgumentException { clientCheck(); return newOrderer(name, grpcURL, null); }
java
public Orderer newOrderer(String name, String grpcURL) throws InvalidArgumentException { clientCheck(); return newOrderer(name, grpcURL, null); }
[ "public", "Orderer", "newOrderer", "(", "String", "name", ",", "String", "grpcURL", ")", "throws", "InvalidArgumentException", "{", "clientCheck", "(", ")", ";", "return", "newOrderer", "(", "name", ",", "grpcURL", ",", "null", ")", ";", "}" ]
Create a new urlOrderer. @param name name of the orderer. @param grpcURL url location of orderer grpc or grpcs protocol. @return a new Orderer. @throws InvalidArgumentException
[ "Create", "a", "new", "urlOrderer", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/HFClient.java#L694-L697
22,046
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/HFClient.java
HFClient.newOrderer
public Orderer newOrderer(String name, String grpcURL, Properties properties) throws InvalidArgumentException { clientCheck(); return Orderer.createNewInstance(name, grpcURL, properties); }
java
public Orderer newOrderer(String name, String grpcURL, Properties properties) throws InvalidArgumentException { clientCheck(); return Orderer.createNewInstance(name, grpcURL, properties); }
[ "public", "Orderer", "newOrderer", "(", "String", "name", ",", "String", "grpcURL", ",", "Properties", "properties", ")", "throws", "InvalidArgumentException", "{", "clientCheck", "(", ")", ";", "return", "Orderer", ".", "createNewInstance", "(", "name", ",", "grpcURL", ",", "properties", ")", ";", "}" ]
Create a new orderer. @param name name of Orderer. @param grpcURL url location of orderer grpc or grpcs protocol. @param properties <p> Supported properties <ul> <li>pemFile - File location for x509 pem certificate for SSL.</li> <li>pemBytes - byte array for x509 pem certificates for SSL</li> <li>trustServerCertificate - boolean(true/false) override CN to match pemFile certificate -- for development only. If the pemFile has the target server's certificate (instead of a CA Root certificate), instruct the TLS client to trust the CN value of the certificate in the pemFile, useful in development to get past default server hostname verification during TLS handshake, when the server host name does not match the certificate. </li> <li>clientKeyFile - File location for private key pem for mutual TLS</li> <li>clientCertFile - File location for x509 pem certificate for mutual TLS</li> <li>clientKeyBytes - Private key pem bytes for mutual TLS</li> <li>clientCertBytes - x509 pem certificate bytes for mutual TLS</li> <li>sslProvider - Specify the SSL provider, openSSL or JDK.</li> <li>negotiationType - Specify the type of negotiation, TLS or plainText.</li> <li>hostnameOverride - Specify the certificates CN -- for development only. If the pemFile does not represent the server certificate, use this property to specify the URI authority (a.k.a hostname) expected in the target server's certificate. This is required to get past default server hostname verifications during TLS handshake. </li> <li> grpc.NettyChannelBuilderOption.&lt;methodName&gt; where methodName is any method on grpc ManagedChannelBuilder. If more than one argument to the method is needed then the parameters need to be supplied in an array of Objects. </li> <li> ordererWaitTimeMilliSecs Time to wait in milliseconds for the Orderer to accept requests before timing out. The default is two seconds. </li> </ul> @return The orderer. @throws InvalidArgumentException
[ "Create", "a", "new", "orderer", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/HFClient.java#L740-L743
22,047
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/HFClient.java
HFClient.queryChannels
public Set<String> queryChannels(Peer peer) throws InvalidArgumentException, ProposalException { clientCheck(); if (null == peer) { throw new InvalidArgumentException("peer set to null"); } //Run this on a system channel. try { Channel systemChannel = Channel.newSystemChannel(this); return systemChannel.queryChannels(peer); } catch (InvalidArgumentException e) { throw e; //dont log } catch (ProposalException e) { logger.error(format("queryChannels for peer %s failed." + e.getMessage(), peer.getName()), e); throw e; } }
java
public Set<String> queryChannels(Peer peer) throws InvalidArgumentException, ProposalException { clientCheck(); if (null == peer) { throw new InvalidArgumentException("peer set to null"); } //Run this on a system channel. try { Channel systemChannel = Channel.newSystemChannel(this); return systemChannel.queryChannels(peer); } catch (InvalidArgumentException e) { throw e; //dont log } catch (ProposalException e) { logger.error(format("queryChannels for peer %s failed." + e.getMessage(), peer.getName()), e); throw e; } }
[ "public", "Set", "<", "String", ">", "queryChannels", "(", "Peer", "peer", ")", "throws", "InvalidArgumentException", ",", "ProposalException", "{", "clientCheck", "(", ")", ";", "if", "(", "null", "==", "peer", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"peer set to null\"", ")", ";", "}", "//Run this on a system channel.", "try", "{", "Channel", "systemChannel", "=", "Channel", ".", "newSystemChannel", "(", "this", ")", ";", "return", "systemChannel", ".", "queryChannels", "(", "peer", ")", ";", "}", "catch", "(", "InvalidArgumentException", "e", ")", "{", "throw", "e", ";", "//dont log", "}", "catch", "(", "ProposalException", "e", ")", "{", "logger", ".", "error", "(", "format", "(", "\"queryChannels for peer %s failed.\"", "+", "e", ".", "getMessage", "(", ")", ",", "peer", ".", "getName", "(", ")", ")", ",", "e", ")", ";", "throw", "e", ";", "}", "}" ]
Query the joined channels for peers @param peer the peer to query @return A set of strings with the names of the channels the peer has joined. @throws InvalidArgumentException @throws ProposalException
[ "Query", "the", "joined", "channels", "for", "peers" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/HFClient.java#L753-L776
22,048
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/HFClient.java
HFClient.queryInstalledChaincodes
public List<ChaincodeInfo> queryInstalledChaincodes(Peer peer) throws InvalidArgumentException, ProposalException { clientCheck(); if (null == peer) { throw new InvalidArgumentException("peer set to null"); } try { //Run this on a system channel. Channel systemChannel = Channel.newSystemChannel(this); return systemChannel.queryInstalledChaincodes(peer); } catch (ProposalException e) { logger.error(format("queryInstalledChaincodes for peer %s failed." + e.getMessage(), peer.getName()), e); throw e; } }
java
public List<ChaincodeInfo> queryInstalledChaincodes(Peer peer) throws InvalidArgumentException, ProposalException { clientCheck(); if (null == peer) { throw new InvalidArgumentException("peer set to null"); } try { //Run this on a system channel. Channel systemChannel = Channel.newSystemChannel(this); return systemChannel.queryInstalledChaincodes(peer); } catch (ProposalException e) { logger.error(format("queryInstalledChaincodes for peer %s failed." + e.getMessage(), peer.getName()), e); throw e; } }
[ "public", "List", "<", "ChaincodeInfo", ">", "queryInstalledChaincodes", "(", "Peer", "peer", ")", "throws", "InvalidArgumentException", ",", "ProposalException", "{", "clientCheck", "(", ")", ";", "if", "(", "null", "==", "peer", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"peer set to null\"", ")", ";", "}", "try", "{", "//Run this on a system channel.", "Channel", "systemChannel", "=", "Channel", ".", "newSystemChannel", "(", "this", ")", ";", "return", "systemChannel", ".", "queryInstalledChaincodes", "(", "peer", ")", ";", "}", "catch", "(", "ProposalException", "e", ")", "{", "logger", ".", "error", "(", "format", "(", "\"queryInstalledChaincodes for peer %s failed.\"", "+", "e", ".", "getMessage", "(", ")", ",", "peer", ".", "getName", "(", ")", ")", ",", "e", ")", ";", "throw", "e", ";", "}", "}" ]
Query the peer for installed chaincode information @param peer The peer to query. @return List of ChaincodeInfo on installed chaincode @see {@link ChaincodeInfo} @throws InvalidArgumentException @throws ProposalException @deprecated See {@link LifecycleQueryInstalledChaincodesRequest}
[ "Query", "the", "peer", "for", "installed", "chaincode", "information" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/HFClient.java#L788-L809
22,049
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/HFClient.java
HFClient.getChannelConfigurationSignature
public byte[] getChannelConfigurationSignature(ChannelConfiguration channelConfiguration, User signer) throws InvalidArgumentException { clientCheck(); Channel systemChannel = Channel.newSystemChannel(this); return systemChannel.getChannelConfigurationSignature(channelConfiguration, signer); }
java
public byte[] getChannelConfigurationSignature(ChannelConfiguration channelConfiguration, User signer) throws InvalidArgumentException { clientCheck(); Channel systemChannel = Channel.newSystemChannel(this); return systemChannel.getChannelConfigurationSignature(channelConfiguration, signer); }
[ "public", "byte", "[", "]", "getChannelConfigurationSignature", "(", "ChannelConfiguration", "channelConfiguration", ",", "User", "signer", ")", "throws", "InvalidArgumentException", "{", "clientCheck", "(", ")", ";", "Channel", "systemChannel", "=", "Channel", ".", "newSystemChannel", "(", "this", ")", ";", "return", "systemChannel", ".", "getChannelConfigurationSignature", "(", "channelConfiguration", ",", "signer", ")", ";", "}" ]
Get signature for channel configuration @param channelConfiguration @param signer @return byte array with the signature @throws InvalidArgumentException
[ "Get", "signature", "for", "channel", "configuration" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/HFClient.java#L820-L828
22,050
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/HFClient.java
HFClient.getUpdateChannelConfigurationSignature
public byte[] getUpdateChannelConfigurationSignature(UpdateChannelConfiguration updateChannelConfiguration, User signer) throws InvalidArgumentException { clientCheck(); Channel systemChannel = Channel.newSystemChannel(this); return systemChannel.getUpdateChannelConfigurationSignature(updateChannelConfiguration, signer); }
java
public byte[] getUpdateChannelConfigurationSignature(UpdateChannelConfiguration updateChannelConfiguration, User signer) throws InvalidArgumentException { clientCheck(); Channel systemChannel = Channel.newSystemChannel(this); return systemChannel.getUpdateChannelConfigurationSignature(updateChannelConfiguration, signer); }
[ "public", "byte", "[", "]", "getUpdateChannelConfigurationSignature", "(", "UpdateChannelConfiguration", "updateChannelConfiguration", ",", "User", "signer", ")", "throws", "InvalidArgumentException", "{", "clientCheck", "(", ")", ";", "Channel", "systemChannel", "=", "Channel", ".", "newSystemChannel", "(", "this", ")", ";", "return", "systemChannel", ".", "getUpdateChannelConfigurationSignature", "(", "updateChannelConfiguration", ",", "signer", ")", ";", "}" ]
Get signature for update channel configuration @param updateChannelConfiguration @param signer @return byte array with the signature @throws InvalidArgumentException
[ "Get", "signature", "for", "update", "channel", "configuration" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/HFClient.java#L839-L847
22,051
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/helper/Config.java
Config.getProperty
private String getProperty(String property) { String ret = sdkProperties.getProperty(property); if (null == ret) { logger.warn(String.format("No configuration value found for '%s'", property)); } return ret; }
java
private String getProperty(String property) { String ret = sdkProperties.getProperty(property); if (null == ret) { logger.warn(String.format("No configuration value found for '%s'", property)); } return ret; }
[ "private", "String", "getProperty", "(", "String", "property", ")", "{", "String", "ret", "=", "sdkProperties", ".", "getProperty", "(", "property", ")", ";", "if", "(", "null", "==", "ret", ")", "{", "logger", ".", "warn", "(", "String", ".", "format", "(", "\"No configuration value found for '%s'\"", ",", "property", ")", ")", ";", "}", "return", "ret", ";", "}" ]
getProperty return back property for the given value. @param property @return String value for the property
[ "getProperty", "return", "back", "property", "for", "the", "given", "value", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/helper/Config.java#L170-L178
22,052
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ChaincodeEvent.java
ChaincodeEvent.getPayload
public byte[] getPayload() { ByteString ret = getChaincodeEvent().getPayload(); if (null == ret) { return null; } return ret.toByteArray(); }
java
public byte[] getPayload() { ByteString ret = getChaincodeEvent().getPayload(); if (null == ret) { return null; } return ret.toByteArray(); }
[ "public", "byte", "[", "]", "getPayload", "(", ")", "{", "ByteString", "ret", "=", "getChaincodeEvent", "(", ")", ".", "getPayload", "(", ")", ";", "if", "(", "null", "==", "ret", ")", "{", "return", "null", ";", "}", "return", "ret", ".", "toByteArray", "(", ")", ";", "}" ]
Binary data associated with this event. @return binary data set by the chaincode for this event. This may return null.
[ "Binary", "data", "associated", "with", "this", "event", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ChaincodeEvent.java#L99-L108
22,053
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/LifecycleChaincodePackage.java
LifecycleChaincodePackage.fromStream
public static LifecycleChaincodePackage fromStream(InputStream inputStream) throws IOException, InvalidArgumentException { if (null == inputStream) { throw new InvalidArgumentException("The parameter inputStream may not be null."); } byte[] packageBytes = IOUtils.toByteArray(inputStream); return fromBytes(packageBytes); }
java
public static LifecycleChaincodePackage fromStream(InputStream inputStream) throws IOException, InvalidArgumentException { if (null == inputStream) { throw new InvalidArgumentException("The parameter inputStream may not be null."); } byte[] packageBytes = IOUtils.toByteArray(inputStream); return fromBytes(packageBytes); }
[ "public", "static", "LifecycleChaincodePackage", "fromStream", "(", "InputStream", "inputStream", ")", "throws", "IOException", ",", "InvalidArgumentException", "{", "if", "(", "null", "==", "inputStream", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The parameter inputStream may not be null.\"", ")", ";", "}", "byte", "[", "]", "packageBytes", "=", "IOUtils", ".", "toByteArray", "(", "inputStream", ")", ";", "return", "fromBytes", "(", "packageBytes", ")", ";", "}" ]
Construct a LifecycleChaincodePackage from a stream. @param inputStream The stream containing the lifecycle chaincode package. This stream is NOT closed. @throws IOException
[ "Construct", "a", "LifecycleChaincodePackage", "from", "a", "stream", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/LifecycleChaincodePackage.java#L98-L104
22,054
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/LifecycleChaincodePackage.java
LifecycleChaincodePackage.getAsBytes
public byte[] getAsBytes() { byte[] ret = new byte[pBytes.length]; System.arraycopy(pBytes, 0, ret, 0, pBytes.length); //make sure we keep our own copy. return ret; }
java
public byte[] getAsBytes() { byte[] ret = new byte[pBytes.length]; System.arraycopy(pBytes, 0, ret, 0, pBytes.length); //make sure we keep our own copy. return ret; }
[ "public", "byte", "[", "]", "getAsBytes", "(", ")", "{", "byte", "[", "]", "ret", "=", "new", "byte", "[", "pBytes", ".", "length", "]", ";", "System", ".", "arraycopy", "(", "pBytes", ",", "0", ",", "ret", ",", "0", ",", "pBytes", ".", "length", ")", ";", "//make sure we keep our own copy.", "return", "ret", ";", "}" ]
Lifecycle chaincode package as bytes @return Lifecycle chaincode package as bytes.
[ "Lifecycle", "chaincode", "package", "as", "bytes" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/LifecycleChaincodePackage.java#L123-L128
22,055
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/LifecycleChaincodePackage.java
LifecycleChaincodePackage.toFile
public void toFile(Path path, OpenOption... options) throws IOException { Files.write(path, pBytes, options); }
java
public void toFile(Path path, OpenOption... options) throws IOException { Files.write(path, pBytes, options); }
[ "public", "void", "toFile", "(", "Path", "path", ",", "OpenOption", "...", "options", ")", "throws", "IOException", "{", "Files", ".", "write", "(", "path", ",", "pBytes", ",", "options", ")", ";", "}" ]
Write Lifecycle chaincode package bytes to file. @param path of the file to write to. @param options Options on creating file. @throws IOException
[ "Write", "Lifecycle", "chaincode", "package", "bytes", "to", "file", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/LifecycleChaincodePackage.java#L138-L141
22,056
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/CollectionConfigPackage.java
CollectionConfigPackage.getCollectionConfigPackage
public org.hyperledger.fabric.protos.common.Collection.CollectionConfigPackage getCollectionConfigPackage() throws InvalidProtocolBufferException { if (null == cp) { cp = org.hyperledger.fabric.protos.common.Collection.CollectionConfigPackage.parseFrom(collectionConfigBytes); } return cp; }
java
public org.hyperledger.fabric.protos.common.Collection.CollectionConfigPackage getCollectionConfigPackage() throws InvalidProtocolBufferException { if (null == cp) { cp = org.hyperledger.fabric.protos.common.Collection.CollectionConfigPackage.parseFrom(collectionConfigBytes); } return cp; }
[ "public", "org", ".", "hyperledger", ".", "fabric", ".", "protos", ".", "common", ".", "Collection", ".", "CollectionConfigPackage", "getCollectionConfigPackage", "(", ")", "throws", "InvalidProtocolBufferException", "{", "if", "(", "null", "==", "cp", ")", "{", "cp", "=", "org", ".", "hyperledger", ".", "fabric", ".", "protos", ".", "common", ".", "Collection", ".", "CollectionConfigPackage", ".", "parseFrom", "(", "collectionConfigBytes", ")", ";", "}", "return", "cp", ";", "}" ]
The raw collection information returned from the peer. @return The raw collection information returned from the peer. @throws InvalidProtocolBufferException
[ "The", "raw", "collection", "information", "returned", "from", "the", "peer", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/CollectionConfigPackage.java#L46-L53
22,057
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/CollectionConfigPackage.java
CollectionConfigPackage.getCollectionConfigs
public Collection<CollectionConfig> getCollectionConfigs() throws InvalidProtocolBufferException { List<CollectionConfig> ret = new LinkedList<>(); for (org.hyperledger.fabric.protos.common.Collection.CollectionConfig collectionConfig : getCollectionConfigPackage().getConfigList()) { ret.add(new CollectionConfig(collectionConfig)); } return ret; }
java
public Collection<CollectionConfig> getCollectionConfigs() throws InvalidProtocolBufferException { List<CollectionConfig> ret = new LinkedList<>(); for (org.hyperledger.fabric.protos.common.Collection.CollectionConfig collectionConfig : getCollectionConfigPackage().getConfigList()) { ret.add(new CollectionConfig(collectionConfig)); } return ret; }
[ "public", "Collection", "<", "CollectionConfig", ">", "getCollectionConfigs", "(", ")", "throws", "InvalidProtocolBufferException", "{", "List", "<", "CollectionConfig", ">", "ret", "=", "new", "LinkedList", "<>", "(", ")", ";", "for", "(", "org", ".", "hyperledger", ".", "fabric", ".", "protos", ".", "common", ".", "Collection", ".", "CollectionConfig", "collectionConfig", ":", "getCollectionConfigPackage", "(", ")", ".", "getConfigList", "(", ")", ")", "{", "ret", ".", "add", "(", "new", "CollectionConfig", "(", "collectionConfig", ")", ")", ";", "}", "return", "ret", ";", "}" ]
Collection of the chaincode collections. @return Collection of the chaincode collection @throws InvalidProtocolBufferException
[ "Collection", "of", "the", "chaincode", "collections", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/CollectionConfigPackage.java#L61-L69
22,058
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCACertificateRequest.java
HFCACertificateRequest.setRevokedStart
public void setRevokedStart(Date revokedStart) throws InvalidArgumentException { if (revokedStart == null) { throw new InvalidArgumentException("Date can't be null"); } queryParms.put("revoked_start", Util.dateToString(revokedStart)); }
java
public void setRevokedStart(Date revokedStart) throws InvalidArgumentException { if (revokedStart == null) { throw new InvalidArgumentException("Date can't be null"); } queryParms.put("revoked_start", Util.dateToString(revokedStart)); }
[ "public", "void", "setRevokedStart", "(", "Date", "revokedStart", ")", "throws", "InvalidArgumentException", "{", "if", "(", "revokedStart", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Date can't be null\"", ")", ";", "}", "queryParms", ".", "put", "(", "\"revoked_start\"", ",", "Util", ".", "dateToString", "(", "revokedStart", ")", ")", ";", "}" ]
Get certificates that have been revoked after this date @param revokedStart Revoked after date @throws InvalidArgumentException Date can't be null
[ "Get", "certificates", "that", "have", "been", "revoked", "after", "this", "date" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCACertificateRequest.java#L57-L62
22,059
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCACertificateRequest.java
HFCACertificateRequest.setRevokedEnd
public void setRevokedEnd(Date revokedEnd) throws InvalidArgumentException { if (revokedEnd == null) { throw new InvalidArgumentException("Date can't be null"); } queryParms.put("revoked_end", Util.dateToString(revokedEnd)); }
java
public void setRevokedEnd(Date revokedEnd) throws InvalidArgumentException { if (revokedEnd == null) { throw new InvalidArgumentException("Date can't be null"); } queryParms.put("revoked_end", Util.dateToString(revokedEnd)); }
[ "public", "void", "setRevokedEnd", "(", "Date", "revokedEnd", ")", "throws", "InvalidArgumentException", "{", "if", "(", "revokedEnd", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Date can't be null\"", ")", ";", "}", "queryParms", ".", "put", "(", "\"revoked_end\"", ",", "Util", ".", "dateToString", "(", "revokedEnd", ")", ")", ";", "}" ]
Get certificates that have been revoked before this date @param revokedEnd Revoked before date @throws InvalidArgumentException Date can't be null
[ "Get", "certificates", "that", "have", "been", "revoked", "before", "this", "date" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCACertificateRequest.java#L70-L75
22,060
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCACertificateRequest.java
HFCACertificateRequest.setExpiredStart
public void setExpiredStart(Date expiredStart) throws InvalidArgumentException { if (expiredStart == null) { throw new InvalidArgumentException("Date can't be null"); } queryParms.put("expired_start", Util.dateToString(expiredStart)); }
java
public void setExpiredStart(Date expiredStart) throws InvalidArgumentException { if (expiredStart == null) { throw new InvalidArgumentException("Date can't be null"); } queryParms.put("expired_start", Util.dateToString(expiredStart)); }
[ "public", "void", "setExpiredStart", "(", "Date", "expiredStart", ")", "throws", "InvalidArgumentException", "{", "if", "(", "expiredStart", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Date can't be null\"", ")", ";", "}", "queryParms", ".", "put", "(", "\"expired_start\"", ",", "Util", ".", "dateToString", "(", "expiredStart", ")", ")", ";", "}" ]
Get certificates that have expired after this date @param expiredStart Expired after date @throws InvalidArgumentException Date can't be null
[ "Get", "certificates", "that", "have", "expired", "after", "this", "date" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCACertificateRequest.java#L83-L88
22,061
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCACertificateRequest.java
HFCACertificateRequest.setExpiredEnd
public void setExpiredEnd(Date expiredEnd) throws InvalidArgumentException { if (expiredEnd == null) { throw new InvalidArgumentException("Date can't be null"); } queryParms.put("expired_end", Util.dateToString(expiredEnd)); }
java
public void setExpiredEnd(Date expiredEnd) throws InvalidArgumentException { if (expiredEnd == null) { throw new InvalidArgumentException("Date can't be null"); } queryParms.put("expired_end", Util.dateToString(expiredEnd)); }
[ "public", "void", "setExpiredEnd", "(", "Date", "expiredEnd", ")", "throws", "InvalidArgumentException", "{", "if", "(", "expiredEnd", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Date can't be null\"", ")", ";", "}", "queryParms", ".", "put", "(", "\"expired_end\"", ",", "Util", ".", "dateToString", "(", "expiredEnd", ")", ")", ";", "}" ]
Get certificates that have expired before this date @param expiredEnd Expired end date @throws InvalidArgumentException Date can't be null
[ "Get", "certificates", "that", "have", "expired", "before", "this", "date" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCACertificateRequest.java#L96-L101
22,062
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/SDKUtils.java
SDKUtils.calculateBlockHash
public static byte[] calculateBlockHash(HFClient client, long blockNumber, byte[] previousHash, byte[] dataHash) throws IOException, InvalidArgumentException { if (previousHash == null) { throw new InvalidArgumentException("previousHash parameter is null."); } if (dataHash == null) { throw new InvalidArgumentException("dataHash parameter is null."); } if (null == client) { throw new InvalidArgumentException("client parameter is null."); } CryptoSuite cryptoSuite = client.getCryptoSuite(); if (null == cryptoSuite) { throw new InvalidArgumentException("Client crypto suite has not been set."); } ByteArrayOutputStream s = new ByteArrayOutputStream(); DERSequenceGenerator seq = new DERSequenceGenerator(s); seq.addObject(new ASN1Integer(blockNumber)); seq.addObject(new DEROctetString(previousHash)); seq.addObject(new DEROctetString(dataHash)); seq.close(); return cryptoSuite.hash(s.toByteArray()); }
java
public static byte[] calculateBlockHash(HFClient client, long blockNumber, byte[] previousHash, byte[] dataHash) throws IOException, InvalidArgumentException { if (previousHash == null) { throw new InvalidArgumentException("previousHash parameter is null."); } if (dataHash == null) { throw new InvalidArgumentException("dataHash parameter is null."); } if (null == client) { throw new InvalidArgumentException("client parameter is null."); } CryptoSuite cryptoSuite = client.getCryptoSuite(); if (null == cryptoSuite) { throw new InvalidArgumentException("Client crypto suite has not been set."); } ByteArrayOutputStream s = new ByteArrayOutputStream(); DERSequenceGenerator seq = new DERSequenceGenerator(s); seq.addObject(new ASN1Integer(blockNumber)); seq.addObject(new DEROctetString(previousHash)); seq.addObject(new DEROctetString(dataHash)); seq.close(); return cryptoSuite.hash(s.toByteArray()); }
[ "public", "static", "byte", "[", "]", "calculateBlockHash", "(", "HFClient", "client", ",", "long", "blockNumber", ",", "byte", "[", "]", "previousHash", ",", "byte", "[", "]", "dataHash", ")", "throws", "IOException", ",", "InvalidArgumentException", "{", "if", "(", "previousHash", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"previousHash parameter is null.\"", ")", ";", "}", "if", "(", "dataHash", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"dataHash parameter is null.\"", ")", ";", "}", "if", "(", "null", "==", "client", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"client parameter is null.\"", ")", ";", "}", "CryptoSuite", "cryptoSuite", "=", "client", ".", "getCryptoSuite", "(", ")", ";", "if", "(", "null", "==", "cryptoSuite", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Client crypto suite has not been set.\"", ")", ";", "}", "ByteArrayOutputStream", "s", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "DERSequenceGenerator", "seq", "=", "new", "DERSequenceGenerator", "(", "s", ")", ";", "seq", ".", "addObject", "(", "new", "ASN1Integer", "(", "blockNumber", ")", ")", ";", "seq", ".", "addObject", "(", "new", "DEROctetString", "(", "previousHash", ")", ")", ";", "seq", ".", "addObject", "(", "new", "DEROctetString", "(", "dataHash", ")", ")", ";", "seq", ".", "close", "(", ")", ";", "return", "cryptoSuite", ".", "hash", "(", "s", ".", "toByteArray", "(", ")", ")", ";", "}" ]
used asn1 and get hash @param blockNumber @param previousHash @param dataHash @return byte[] @throws IOException @throws InvalidArgumentException
[ "used", "asn1", "and", "get", "hash" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/SDKUtils.java#L59-L84
22,063
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/RevocationRequest.java
RevocationRequest.toJsonObject
private JsonObject toJsonObject() { JsonObjectBuilder factory = Json.createObjectBuilder(); if (enrollmentID != null) { // revoke all enrollments of this user, serial and aki are ignored in this case factory.add("id", enrollmentID); } else { // revoke one particular enrollment factory.add("serial", serial); factory.add("aki", aki); } if (null != reason) { factory.add("reason", reason); } if (caName != null) { factory.add(HFCAClient.FABRIC_CA_REQPROP, caName); } if (genCRL != null) { factory.add("gencrl", genCRL); } return factory.build(); }
java
private JsonObject toJsonObject() { JsonObjectBuilder factory = Json.createObjectBuilder(); if (enrollmentID != null) { // revoke all enrollments of this user, serial and aki are ignored in this case factory.add("id", enrollmentID); } else { // revoke one particular enrollment factory.add("serial", serial); factory.add("aki", aki); } if (null != reason) { factory.add("reason", reason); } if (caName != null) { factory.add(HFCAClient.FABRIC_CA_REQPROP, caName); } if (genCRL != null) { factory.add("gencrl", genCRL); } return factory.build(); }
[ "private", "JsonObject", "toJsonObject", "(", ")", "{", "JsonObjectBuilder", "factory", "=", "Json", ".", "createObjectBuilder", "(", ")", ";", "if", "(", "enrollmentID", "!=", "null", ")", "{", "// revoke all enrollments of this user, serial and aki are ignored in this case", "factory", ".", "add", "(", "\"id\"", ",", "enrollmentID", ")", ";", "}", "else", "{", "// revoke one particular enrollment", "factory", ".", "add", "(", "\"serial\"", ",", "serial", ")", ";", "factory", ".", "add", "(", "\"aki\"", ",", "aki", ")", ";", "}", "if", "(", "null", "!=", "reason", ")", "{", "factory", ".", "add", "(", "\"reason\"", ",", "reason", ")", ";", "}", "if", "(", "caName", "!=", "null", ")", "{", "factory", ".", "add", "(", "HFCAClient", ".", "FABRIC_CA_REQPROP", ",", "caName", ")", ";", "}", "if", "(", "genCRL", "!=", "null", ")", "{", "factory", ".", "add", "(", "\"gencrl\"", ",", "genCRL", ")", ";", "}", "return", "factory", ".", "build", "(", ")", ";", "}" ]
Convert the revocation request to a JSON object
[ "Convert", "the", "revocation", "request", "to", "a", "JSON", "object" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/RevocationRequest.java#L114-L137
22,064
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/transaction/ProtoUtils.java
ProtoUtils.computeUpdate
public static boolean computeUpdate(String channelId, Configtx.Config original, Configtx.Config update, Configtx.ConfigUpdate.Builder configUpdateBuilder) { Configtx.ConfigGroup.Builder readSetBuilder = Configtx.ConfigGroup.newBuilder(); Configtx.ConfigGroup.Builder writeSetBuilder = Configtx.ConfigGroup.newBuilder(); if (computeGroupUpdate(original.getChannelGroup(), update.getChannelGroup(), readSetBuilder, writeSetBuilder)) { configUpdateBuilder.setReadSet(readSetBuilder.build()) .setWriteSet(writeSetBuilder.build()) .setChannelId(channelId); return true; } return false; }
java
public static boolean computeUpdate(String channelId, Configtx.Config original, Configtx.Config update, Configtx.ConfigUpdate.Builder configUpdateBuilder) { Configtx.ConfigGroup.Builder readSetBuilder = Configtx.ConfigGroup.newBuilder(); Configtx.ConfigGroup.Builder writeSetBuilder = Configtx.ConfigGroup.newBuilder(); if (computeGroupUpdate(original.getChannelGroup(), update.getChannelGroup(), readSetBuilder, writeSetBuilder)) { configUpdateBuilder.setReadSet(readSetBuilder.build()) .setWriteSet(writeSetBuilder.build()) .setChannelId(channelId); return true; } return false; }
[ "public", "static", "boolean", "computeUpdate", "(", "String", "channelId", ",", "Configtx", ".", "Config", "original", ",", "Configtx", ".", "Config", "update", ",", "Configtx", ".", "ConfigUpdate", ".", "Builder", "configUpdateBuilder", ")", "{", "Configtx", ".", "ConfigGroup", ".", "Builder", "readSetBuilder", "=", "Configtx", ".", "ConfigGroup", ".", "newBuilder", "(", ")", ";", "Configtx", ".", "ConfigGroup", ".", "Builder", "writeSetBuilder", "=", "Configtx", ".", "ConfigGroup", ".", "newBuilder", "(", ")", ";", "if", "(", "computeGroupUpdate", "(", "original", ".", "getChannelGroup", "(", ")", ",", "update", ".", "getChannelGroup", "(", ")", ",", "readSetBuilder", ",", "writeSetBuilder", ")", ")", "{", "configUpdateBuilder", ".", "setReadSet", "(", "readSetBuilder", ".", "build", "(", ")", ")", ".", "setWriteSet", "(", "writeSetBuilder", ".", "build", "(", ")", ")", ".", "setChannelId", "(", "channelId", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
not an api
[ "not", "an", "api" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/transaction/ProtoUtils.java#L308-L323
22,065
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java
ProposalResponse.getChaincodeID
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); } }
java
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); } }
[ "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", ")", ";", "}", "}" ]
Chaincode ID that was executed. @return See {@link ChaincodeID} @throws InvalidArgumentException
[ "Chaincode", "ID", "that", "was", "executed", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java#L243-L260
22,066
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java
ProposalResponse.getChaincodeActionResponsePayload
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); } }
java
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); } }
[ "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", ")", ";", "}", "}" ]
ChaincodeActionResponsePayload is the result of the executing chaincode. @return the result of the executing chaincode. @throws InvalidArgumentException
[ "ChaincodeActionResponsePayload", "is", "the", "result", "of", "the", "executing", "chaincode", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java#L269-L288
22,067
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java
ProposalResponse.getChaincodeActionResponseStatus
public int getChaincodeActionResponseStatus() throws InvalidArgumentException { if (statusReturnCode != -1) { return statusReturnCode; } try { final ProposalResponsePayloadDeserializer proposalResponsePayloadDeserializer = getProposalResponsePayloadDeserializer(); statusReturnCode = proposalResponsePayloadDeserializer.getExtension().getResponseStatus(); return statusReturnCode; } catch (InvalidArgumentException e) { throw e; } catch (Exception e) { throw new InvalidArgumentException(e); } }
java
public int getChaincodeActionResponseStatus() throws InvalidArgumentException { if (statusReturnCode != -1) { return statusReturnCode; } try { final ProposalResponsePayloadDeserializer proposalResponsePayloadDeserializer = getProposalResponsePayloadDeserializer(); statusReturnCode = proposalResponsePayloadDeserializer.getExtension().getResponseStatus(); return statusReturnCode; } catch (InvalidArgumentException e) { throw e; } catch (Exception e) { throw new InvalidArgumentException(e); } }
[ "public", "int", "getChaincodeActionResponseStatus", "(", ")", "throws", "InvalidArgumentException", "{", "if", "(", "statusReturnCode", "!=", "-", "1", ")", "{", "return", "statusReturnCode", ";", "}", "try", "{", "final", "ProposalResponsePayloadDeserializer", "proposalResponsePayloadDeserializer", "=", "getProposalResponsePayloadDeserializer", "(", ")", ";", "statusReturnCode", "=", "proposalResponsePayloadDeserializer", ".", "getExtension", "(", ")", ".", "getResponseStatus", "(", ")", ";", "return", "statusReturnCode", ";", "}", "catch", "(", "InvalidArgumentException", "e", ")", "{", "throw", "e", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "InvalidArgumentException", "(", "e", ")", ";", "}", "}" ]
getChaincodeActionResponseStatus returns the what chaincode executions set as the return status. @return status code. @throws InvalidArgumentException
[ "getChaincodeActionResponseStatus", "returns", "the", "what", "chaincode", "executions", "set", "as", "the", "return", "status", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java#L297-L315
22,068
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java
ProposalResponse.getChaincodeActionResponseReadWriteSetInfo
public TxReadWriteSetInfo getChaincodeActionResponseReadWriteSetInfo() throws InvalidArgumentException { if (isInvalid()) { throw new InvalidArgumentException("Proposal response is invalid."); } try { final ProposalResponsePayloadDeserializer proposalResponsePayloadDeserializer = getProposalResponsePayloadDeserializer(); TxReadWriteSet txReadWriteSet = proposalResponsePayloadDeserializer.getExtension().getResults(); if (txReadWriteSet == null) { return null; } return new TxReadWriteSetInfo(txReadWriteSet); } catch (Exception e) { throw new InvalidArgumentException(e); } }
java
public TxReadWriteSetInfo getChaincodeActionResponseReadWriteSetInfo() throws InvalidArgumentException { if (isInvalid()) { throw new InvalidArgumentException("Proposal response is invalid."); } try { final ProposalResponsePayloadDeserializer proposalResponsePayloadDeserializer = getProposalResponsePayloadDeserializer(); TxReadWriteSet txReadWriteSet = proposalResponsePayloadDeserializer.getExtension().getResults(); if (txReadWriteSet == null) { return null; } return new TxReadWriteSetInfo(txReadWriteSet); } catch (Exception e) { throw new InvalidArgumentException(e); } }
[ "public", "TxReadWriteSetInfo", "getChaincodeActionResponseReadWriteSetInfo", "(", ")", "throws", "InvalidArgumentException", "{", "if", "(", "isInvalid", "(", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Proposal response is invalid.\"", ")", ";", "}", "try", "{", "final", "ProposalResponsePayloadDeserializer", "proposalResponsePayloadDeserializer", "=", "getProposalResponsePayloadDeserializer", "(", ")", ";", "TxReadWriteSet", "txReadWriteSet", "=", "proposalResponsePayloadDeserializer", ".", "getExtension", "(", ")", ".", "getResults", "(", ")", ";", "if", "(", "txReadWriteSet", "==", "null", ")", "{", "return", "null", ";", "}", "return", "new", "TxReadWriteSetInfo", "(", "txReadWriteSet", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "InvalidArgumentException", "(", "e", ")", ";", "}", "}" ]
getChaincodeActionResponseReadWriteSetInfo get this proposals read write set. @return The read write set. See {@link TxReadWriteSetInfo} @throws InvalidArgumentException
[ "getChaincodeActionResponseReadWriteSetInfo", "get", "this", "proposals", "read", "write", "set", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java#L324-L346
22,069
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java
CryptoPrimitives.bytesToPrivateKey
public PrivateKey bytesToPrivateKey(byte[] pemKey) throws CryptoException { PrivateKey pk = null; CryptoException ce = null; try { PemReader pr = new PemReader(new StringReader(new String(pemKey))); PemObject po = pr.readPemObject(); PEMParser pem = new PEMParser(new StringReader(new String(pemKey))); if (po.getType().equals("PRIVATE KEY")) { pk = new JcaPEMKeyConverter().getPrivateKey((PrivateKeyInfo) pem.readObject()); } else { logger.trace("Found private key with type " + po.getType()); PEMKeyPair kp = (PEMKeyPair) pem.readObject(); pk = new JcaPEMKeyConverter().getPrivateKey(kp.getPrivateKeyInfo()); } } catch (Exception e) { throw new CryptoException("Failed to convert private key bytes", e); } return pk; }
java
public PrivateKey bytesToPrivateKey(byte[] pemKey) throws CryptoException { PrivateKey pk = null; CryptoException ce = null; try { PemReader pr = new PemReader(new StringReader(new String(pemKey))); PemObject po = pr.readPemObject(); PEMParser pem = new PEMParser(new StringReader(new String(pemKey))); if (po.getType().equals("PRIVATE KEY")) { pk = new JcaPEMKeyConverter().getPrivateKey((PrivateKeyInfo) pem.readObject()); } else { logger.trace("Found private key with type " + po.getType()); PEMKeyPair kp = (PEMKeyPair) pem.readObject(); pk = new JcaPEMKeyConverter().getPrivateKey(kp.getPrivateKeyInfo()); } } catch (Exception e) { throw new CryptoException("Failed to convert private key bytes", e); } return pk; }
[ "public", "PrivateKey", "bytesToPrivateKey", "(", "byte", "[", "]", "pemKey", ")", "throws", "CryptoException", "{", "PrivateKey", "pk", "=", "null", ";", "CryptoException", "ce", "=", "null", ";", "try", "{", "PemReader", "pr", "=", "new", "PemReader", "(", "new", "StringReader", "(", "new", "String", "(", "pemKey", ")", ")", ")", ";", "PemObject", "po", "=", "pr", ".", "readPemObject", "(", ")", ";", "PEMParser", "pem", "=", "new", "PEMParser", "(", "new", "StringReader", "(", "new", "String", "(", "pemKey", ")", ")", ")", ";", "if", "(", "po", ".", "getType", "(", ")", ".", "equals", "(", "\"PRIVATE KEY\"", ")", ")", "{", "pk", "=", "new", "JcaPEMKeyConverter", "(", ")", ".", "getPrivateKey", "(", "(", "PrivateKeyInfo", ")", "pem", ".", "readObject", "(", ")", ")", ";", "}", "else", "{", "logger", ".", "trace", "(", "\"Found private key with type \"", "+", "po", ".", "getType", "(", ")", ")", ";", "PEMKeyPair", "kp", "=", "(", "PEMKeyPair", ")", "pem", ".", "readObject", "(", ")", ";", "pk", "=", "new", "JcaPEMKeyConverter", "(", ")", ".", "getPrivateKey", "(", "kp", ".", "getPrivateKeyInfo", "(", ")", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "CryptoException", "(", "\"Failed to convert private key bytes\"", ",", "e", ")", ";", "}", "return", "pk", ";", "}" ]
Return PrivateKey from pem bytes. @param pemKey pem-encoded private key @return
[ "Return", "PrivateKey", "from", "pem", "bytes", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java#L273-L293
22,070
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java
CryptoPrimitives.addCACertificatesToTrustStore
public void addCACertificatesToTrustStore(BufferedInputStream bis) throws CryptoException, InvalidArgumentException { if (bis == null) { throw new InvalidArgumentException("The certificate stream bis cannot be null"); } try { final Collection<? extends Certificate> certificates = cf.generateCertificates(bis); for (Certificate certificate : certificates) { addCACertificateToTrustStore(certificate); } } catch (CertificateException e) { throw new CryptoException("Unable to add CA certificate to trust store. Error: " + e.getMessage(), e); } }
java
public void addCACertificatesToTrustStore(BufferedInputStream bis) throws CryptoException, InvalidArgumentException { if (bis == null) { throw new InvalidArgumentException("The certificate stream bis cannot be null"); } try { final Collection<? extends Certificate> certificates = cf.generateCertificates(bis); for (Certificate certificate : certificates) { addCACertificateToTrustStore(certificate); } } catch (CertificateException e) { throw new CryptoException("Unable to add CA certificate to trust store. Error: " + e.getMessage(), e); } }
[ "public", "void", "addCACertificatesToTrustStore", "(", "BufferedInputStream", "bis", ")", "throws", "CryptoException", ",", "InvalidArgumentException", "{", "if", "(", "bis", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The certificate stream bis cannot be null\"", ")", ";", "}", "try", "{", "final", "Collection", "<", "?", "extends", "Certificate", ">", "certificates", "=", "cf", ".", "generateCertificates", "(", "bis", ")", ";", "for", "(", "Certificate", "certificate", ":", "certificates", ")", "{", "addCACertificateToTrustStore", "(", "certificate", ")", ";", "}", "}", "catch", "(", "CertificateException", "e", ")", "{", "throw", "new", "CryptoException", "(", "\"Unable to add CA certificate to trust store. Error: \"", "+", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "}" ]
addCACertificatesToTrustStore adds a CA certs in a stream to the trust store used for signature validation @param bis an X.509 certificate stream in PEM format in bytes @throws CryptoException @throws InvalidArgumentException
[ "addCACertificatesToTrustStore", "adds", "a", "CA", "certs", "in", "a", "stream", "to", "the", "trust", "store", "used", "for", "signature", "validation" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java#L427-L442
22,071
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java
CryptoPrimitives.validateCertificate
boolean validateCertificate(byte[] certPEM) { if (certPEM == null) { return false; } try { X509Certificate certificate = getX509Certificate(certPEM); if (null == certificate) { throw new Exception("Certificate transformation returned null"); } return validateCertificate(certificate); } catch (Exception e) { logger.error("Cannot validate certificate. Error is: " + e.getMessage() + "\r\nCertificate (PEM, hex): " + DatatypeConverter.printHexBinary(certPEM)); return false; } }
java
boolean validateCertificate(byte[] certPEM) { if (certPEM == null) { return false; } try { X509Certificate certificate = getX509Certificate(certPEM); if (null == certificate) { throw new Exception("Certificate transformation returned null"); } return validateCertificate(certificate); } catch (Exception e) { logger.error("Cannot validate certificate. Error is: " + e.getMessage() + "\r\nCertificate (PEM, hex): " + DatatypeConverter.printHexBinary(certPEM)); return false; } }
[ "boolean", "validateCertificate", "(", "byte", "[", "]", "certPEM", ")", "{", "if", "(", "certPEM", "==", "null", ")", "{", "return", "false", ";", "}", "try", "{", "X509Certificate", "certificate", "=", "getX509Certificate", "(", "certPEM", ")", ";", "if", "(", "null", "==", "certificate", ")", "{", "throw", "new", "Exception", "(", "\"Certificate transformation returned null\"", ")", ";", "}", "return", "validateCertificate", "(", "certificate", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "error", "(", "\"Cannot validate certificate. Error is: \"", "+", "e", ".", "getMessage", "(", ")", "+", "\"\\r\\nCertificate (PEM, hex): \"", "+", "DatatypeConverter", ".", "printHexBinary", "(", "certPEM", ")", ")", ";", "return", "false", ";", "}", "}" ]
validateCertificate checks whether the given certificate is trusted. It checks if the certificate is signed by one of the trusted certs in the trust store. @param certPEM the certificate in PEM format @return true if the certificate is trusted
[ "validateCertificate", "checks", "whether", "the", "given", "certificate", "is", "trusted", ".", "It", "checks", "if", "the", "certificate", "is", "signed", "by", "one", "of", "the", "trusted", "certs", "in", "the", "trust", "store", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java#L539-L558
22,072
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java
CryptoPrimitives.setSecurityLevel
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; }
java
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; }
[ "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", ";", "}" ]
Security Level determines the elliptic curve used in key generation @param securityLevel currently 256 or 384 @throws InvalidArgumentException
[ "Security", "Level", "determines", "the", "elliptic", "curve", "used", "in", "key", "generation" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java#L598-L635
22,073
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java
CryptoPrimitives.decodeECDSASignature
private static BigInteger[] decodeECDSASignature(byte[] signature) throws Exception { try (ByteArrayInputStream inStream = new ByteArrayInputStream(signature)) { ASN1InputStream asnInputStream = new ASN1InputStream(inStream); ASN1Primitive asn1 = asnInputStream.readObject(); BigInteger[] sigs = new BigInteger[2]; int count = 0; if (asn1 instanceof ASN1Sequence) { ASN1Sequence asn1Sequence = (ASN1Sequence) asn1; ASN1Encodable[] asn1Encodables = asn1Sequence.toArray(); for (ASN1Encodable asn1Encodable : asn1Encodables) { ASN1Primitive asn1Primitive = asn1Encodable.toASN1Primitive(); if (asn1Primitive instanceof ASN1Integer) { ASN1Integer asn1Integer = (ASN1Integer) asn1Primitive; BigInteger integer = asn1Integer.getValue(); if (count < 2) { sigs[count] = integer; } count++; } } } if (count != 2) { throw new CryptoException(format("Invalid ECDSA signature. Expected count of 2 but got: %d. Signature is: %s", count, DatatypeConverter.printHexBinary(signature))); } return sigs; } }
java
private static BigInteger[] decodeECDSASignature(byte[] signature) throws Exception { try (ByteArrayInputStream inStream = new ByteArrayInputStream(signature)) { ASN1InputStream asnInputStream = new ASN1InputStream(inStream); ASN1Primitive asn1 = asnInputStream.readObject(); BigInteger[] sigs = new BigInteger[2]; int count = 0; if (asn1 instanceof ASN1Sequence) { ASN1Sequence asn1Sequence = (ASN1Sequence) asn1; ASN1Encodable[] asn1Encodables = asn1Sequence.toArray(); for (ASN1Encodable asn1Encodable : asn1Encodables) { ASN1Primitive asn1Primitive = asn1Encodable.toASN1Primitive(); if (asn1Primitive instanceof ASN1Integer) { ASN1Integer asn1Integer = (ASN1Integer) asn1Primitive; BigInteger integer = asn1Integer.getValue(); if (count < 2) { sigs[count] = integer; } count++; } } } if (count != 2) { throw new CryptoException(format("Invalid ECDSA signature. Expected count of 2 but got: %d. Signature is: %s", count, DatatypeConverter.printHexBinary(signature))); } return sigs; } }
[ "private", "static", "BigInteger", "[", "]", "decodeECDSASignature", "(", "byte", "[", "]", "signature", ")", "throws", "Exception", "{", "try", "(", "ByteArrayInputStream", "inStream", "=", "new", "ByteArrayInputStream", "(", "signature", ")", ")", "{", "ASN1InputStream", "asnInputStream", "=", "new", "ASN1InputStream", "(", "inStream", ")", ";", "ASN1Primitive", "asn1", "=", "asnInputStream", ".", "readObject", "(", ")", ";", "BigInteger", "[", "]", "sigs", "=", "new", "BigInteger", "[", "2", "]", ";", "int", "count", "=", "0", ";", "if", "(", "asn1", "instanceof", "ASN1Sequence", ")", "{", "ASN1Sequence", "asn1Sequence", "=", "(", "ASN1Sequence", ")", "asn1", ";", "ASN1Encodable", "[", "]", "asn1Encodables", "=", "asn1Sequence", ".", "toArray", "(", ")", ";", "for", "(", "ASN1Encodable", "asn1Encodable", ":", "asn1Encodables", ")", "{", "ASN1Primitive", "asn1Primitive", "=", "asn1Encodable", ".", "toASN1Primitive", "(", ")", ";", "if", "(", "asn1Primitive", "instanceof", "ASN1Integer", ")", "{", "ASN1Integer", "asn1Integer", "=", "(", "ASN1Integer", ")", "asn1Primitive", ";", "BigInteger", "integer", "=", "asn1Integer", ".", "getValue", "(", ")", ";", "if", "(", "count", "<", "2", ")", "{", "sigs", "[", "count", "]", "=", "integer", ";", "}", "count", "++", ";", "}", "}", "}", "if", "(", "count", "!=", "2", ")", "{", "throw", "new", "CryptoException", "(", "format", "(", "\"Invalid ECDSA signature. Expected count of 2 but got: %d. Signature is: %s\"", ",", "count", ",", "DatatypeConverter", ".", "printHexBinary", "(", "signature", ")", ")", ")", ";", "}", "return", "sigs", ";", "}", "}" ]
Decodes an ECDSA signature and returns a two element BigInteger array. @param signature ECDSA signature bytes. @return BigInteger array for the signature's r and s values @throws Exception
[ "Decodes", "an", "ECDSA", "signature", "and", "returns", "a", "two", "element", "BigInteger", "array", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java#L675-L705
22,074
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java
CryptoPrimitives.ecdsaSignToBytes
private byte[] ecdsaSignToBytes(ECPrivateKey privateKey, byte[] data) throws CryptoException { if (data == null) { throw new CryptoException("Data that to be signed is null."); } if (data.length == 0) { throw new CryptoException("Data to be signed was empty."); } try { X9ECParameters params = ECNamedCurveTable.getByName(curveName); BigInteger curveN = params.getN(); Signature sig = SECURITY_PROVIDER == null ? Signature.getInstance(DEFAULT_SIGNATURE_ALGORITHM) : Signature.getInstance(DEFAULT_SIGNATURE_ALGORITHM, SECURITY_PROVIDER); sig.initSign(privateKey); sig.update(data); byte[] signature = sig.sign(); BigInteger[] sigs = decodeECDSASignature(signature); sigs = preventMalleability(sigs, curveN); try (ByteArrayOutputStream s = new ByteArrayOutputStream()) { DERSequenceGenerator seq = new DERSequenceGenerator(s); seq.addObject(new ASN1Integer(sigs[0])); seq.addObject(new ASN1Integer(sigs[1])); seq.close(); return s.toByteArray(); } } catch (Exception e) { throw new CryptoException("Could not sign the message using private key", e); } }
java
private byte[] ecdsaSignToBytes(ECPrivateKey privateKey, byte[] data) throws CryptoException { if (data == null) { throw new CryptoException("Data that to be signed is null."); } if (data.length == 0) { throw new CryptoException("Data to be signed was empty."); } try { X9ECParameters params = ECNamedCurveTable.getByName(curveName); BigInteger curveN = params.getN(); Signature sig = SECURITY_PROVIDER == null ? Signature.getInstance(DEFAULT_SIGNATURE_ALGORITHM) : Signature.getInstance(DEFAULT_SIGNATURE_ALGORITHM, SECURITY_PROVIDER); sig.initSign(privateKey); sig.update(data); byte[] signature = sig.sign(); BigInteger[] sigs = decodeECDSASignature(signature); sigs = preventMalleability(sigs, curveN); try (ByteArrayOutputStream s = new ByteArrayOutputStream()) { DERSequenceGenerator seq = new DERSequenceGenerator(s); seq.addObject(new ASN1Integer(sigs[0])); seq.addObject(new ASN1Integer(sigs[1])); seq.close(); return s.toByteArray(); } } catch (Exception e) { throw new CryptoException("Could not sign the message using private key", e); } }
[ "private", "byte", "[", "]", "ecdsaSignToBytes", "(", "ECPrivateKey", "privateKey", ",", "byte", "[", "]", "data", ")", "throws", "CryptoException", "{", "if", "(", "data", "==", "null", ")", "{", "throw", "new", "CryptoException", "(", "\"Data that to be signed is null.\"", ")", ";", "}", "if", "(", "data", ".", "length", "==", "0", ")", "{", "throw", "new", "CryptoException", "(", "\"Data to be signed was empty.\"", ")", ";", "}", "try", "{", "X9ECParameters", "params", "=", "ECNamedCurveTable", ".", "getByName", "(", "curveName", ")", ";", "BigInteger", "curveN", "=", "params", ".", "getN", "(", ")", ";", "Signature", "sig", "=", "SECURITY_PROVIDER", "==", "null", "?", "Signature", ".", "getInstance", "(", "DEFAULT_SIGNATURE_ALGORITHM", ")", ":", "Signature", ".", "getInstance", "(", "DEFAULT_SIGNATURE_ALGORITHM", ",", "SECURITY_PROVIDER", ")", ";", "sig", ".", "initSign", "(", "privateKey", ")", ";", "sig", ".", "update", "(", "data", ")", ";", "byte", "[", "]", "signature", "=", "sig", ".", "sign", "(", ")", ";", "BigInteger", "[", "]", "sigs", "=", "decodeECDSASignature", "(", "signature", ")", ";", "sigs", "=", "preventMalleability", "(", "sigs", ",", "curveN", ")", ";", "try", "(", "ByteArrayOutputStream", "s", "=", "new", "ByteArrayOutputStream", "(", ")", ")", "{", "DERSequenceGenerator", "seq", "=", "new", "DERSequenceGenerator", "(", "s", ")", ";", "seq", ".", "addObject", "(", "new", "ASN1Integer", "(", "sigs", "[", "0", "]", ")", ")", ";", "seq", ".", "addObject", "(", "new", "ASN1Integer", "(", "sigs", "[", "1", "]", ")", ")", ";", "seq", ".", "close", "(", ")", ";", "return", "s", ".", "toByteArray", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "CryptoException", "(", "\"Could not sign the message using private key\"", ",", "e", ")", ";", "}", "}" ]
Sign data with the specified elliptic curve private key. @param privateKey elliptic curve private key. @param data data to sign @return the signed data. @throws CryptoException
[ "Sign", "data", "with", "the", "specified", "elliptic", "curve", "private", "key", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java#L715-L750
22,075
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java
CryptoPrimitives.certificationRequestToPEM
private String certificationRequestToPEM(PKCS10CertificationRequest csr) throws IOException { PemObject pemCSR = new PemObject("CERTIFICATE REQUEST", csr.getEncoded()); StringWriter str = new StringWriter(); JcaPEMWriter pemWriter = new JcaPEMWriter(str); pemWriter.writeObject(pemCSR); pemWriter.close(); str.close(); return str.toString(); }
java
private String certificationRequestToPEM(PKCS10CertificationRequest csr) throws IOException { PemObject pemCSR = new PemObject("CERTIFICATE REQUEST", csr.getEncoded()); StringWriter str = new StringWriter(); JcaPEMWriter pemWriter = new JcaPEMWriter(str); pemWriter.writeObject(pemCSR); pemWriter.close(); str.close(); return str.toString(); }
[ "private", "String", "certificationRequestToPEM", "(", "PKCS10CertificationRequest", "csr", ")", "throws", "IOException", "{", "PemObject", "pemCSR", "=", "new", "PemObject", "(", "\"CERTIFICATE REQUEST\"", ",", "csr", ".", "getEncoded", "(", ")", ")", ";", "StringWriter", "str", "=", "new", "StringWriter", "(", ")", ";", "JcaPEMWriter", "pemWriter", "=", "new", "JcaPEMWriter", "(", "str", ")", ";", "pemWriter", ".", "writeObject", "(", "pemCSR", ")", ";", "pemWriter", ".", "close", "(", ")", ";", "str", ".", "close", "(", ")", ";", "return", "str", ".", "toString", "(", ")", ";", "}" ]
certificationRequestToPEM - Convert a PKCS10CertificationRequest to PEM format. @param csr The Certificate to convert @return An equivalent PEM format certificate. @throws IOException
[ "certificationRequestToPEM", "-", "Convert", "a", "PKCS10CertificationRequest", "to", "PEM", "format", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java#L815-L824
22,076
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java
CryptoPrimitives.resetConfiguration
private void resetConfiguration() throws CryptoException, InvalidArgumentException { setSecurityLevel(securityLevel); setHashAlgorithm(hashAlgorithm); try { cf = CertificateFactory.getInstance(CERTIFICATE_FORMAT); } catch (CertificateException e) { CryptoException ex = new CryptoException("Cannot initialize " + CERTIFICATE_FORMAT + " certificate factory. Error = " + e.getMessage(), e); logger.error(ex.getMessage(), ex); throw ex; } }
java
private void resetConfiguration() throws CryptoException, InvalidArgumentException { setSecurityLevel(securityLevel); setHashAlgorithm(hashAlgorithm); try { cf = CertificateFactory.getInstance(CERTIFICATE_FORMAT); } catch (CertificateException e) { CryptoException ex = new CryptoException("Cannot initialize " + CERTIFICATE_FORMAT + " certificate factory. Error = " + e.getMessage(), e); logger.error(ex.getMessage(), ex); throw ex; } }
[ "private", "void", "resetConfiguration", "(", ")", "throws", "CryptoException", ",", "InvalidArgumentException", "{", "setSecurityLevel", "(", "securityLevel", ")", ";", "setHashAlgorithm", "(", "hashAlgorithm", ")", ";", "try", "{", "cf", "=", "CertificateFactory", ".", "getInstance", "(", "CERTIFICATE_FORMAT", ")", ";", "}", "catch", "(", "CertificateException", "e", ")", "{", "CryptoException", "ex", "=", "new", "CryptoException", "(", "\"Cannot initialize \"", "+", "CERTIFICATE_FORMAT", "+", "\" certificate factory. Error = \"", "+", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "logger", ".", "error", "(", "ex", ".", "getMessage", "(", ")", ",", "ex", ")", ";", "throw", "ex", ";", "}", "}" ]
Resets curve name, hash algorithm and cert factory. Call this method when a config value changes @throws CryptoException @throws InvalidArgumentException
[ "Resets", "curve", "name", "hash", "algorithm", "and", "cert", "factory", ".", "Call", "this", "method", "when", "a", "config", "value", "changes" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java#L907-L920
22,077
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryInstalledChaincodeProposalResponse.java
LifecycleQueryInstalledChaincodeProposalResponse.getPackageId
public String getPackageId() throws ProposalException { Lifecycle.QueryInstalledChaincodeResult queryInstalledChaincodeResult = parsePayload(); if (queryInstalledChaincodeResult == null) { return null; } return queryInstalledChaincodeResult.getPackageId(); }
java
public String getPackageId() throws ProposalException { Lifecycle.QueryInstalledChaincodeResult queryInstalledChaincodeResult = parsePayload(); if (queryInstalledChaincodeResult == null) { return null; } return queryInstalledChaincodeResult.getPackageId(); }
[ "public", "String", "getPackageId", "(", ")", "throws", "ProposalException", "{", "Lifecycle", ".", "QueryInstalledChaincodeResult", "queryInstalledChaincodeResult", "=", "parsePayload", "(", ")", ";", "if", "(", "queryInstalledChaincodeResult", "==", "null", ")", "{", "return", "null", ";", "}", "return", "queryInstalledChaincodeResult", ".", "getPackageId", "(", ")", ";", "}" ]
The packageId for this chaincode. @return the packageId @throws ProposalException
[ "The", "packageId", "for", "this", "chaincode", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryInstalledChaincodeProposalResponse.java#L70-L79
22,078
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java
HFCAClient.createNewInstance
public static HFCAClient createNewInstance(NetworkConfig.CAInfo caInfo) throws MalformedURLException, InvalidArgumentException { try { return createNewInstance(caInfo, CryptoSuite.Factory.getCryptoSuite()); } catch (MalformedURLException e) { throw e; } catch (Exception e) { throw new InvalidArgumentException(e); } }
java
public static HFCAClient createNewInstance(NetworkConfig.CAInfo caInfo) throws MalformedURLException, InvalidArgumentException { try { return createNewInstance(caInfo, CryptoSuite.Factory.getCryptoSuite()); } catch (MalformedURLException e) { throw e; } catch (Exception e) { throw new InvalidArgumentException(e); } }
[ "public", "static", "HFCAClient", "createNewInstance", "(", "NetworkConfig", ".", "CAInfo", "caInfo", ")", "throws", "MalformedURLException", ",", "InvalidArgumentException", "{", "try", "{", "return", "createNewInstance", "(", "caInfo", ",", "CryptoSuite", ".", "Factory", ".", "getCryptoSuite", "(", ")", ")", ";", "}", "catch", "(", "MalformedURLException", "e", ")", "{", "throw", "e", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "InvalidArgumentException", "(", "e", ")", ";", "}", "}" ]
Create HFCAClient from a NetworkConfig.CAInfo using default crypto suite. @param caInfo created from NetworkConfig.getOrganizationInfo("org_name").getCertificateAuthorities() @return HFCAClient @throws MalformedURLException @throws InvalidArgumentException
[ "Create", "HFCAClient", "from", "a", "NetworkConfig", ".", "CAInfo", "using", "default", "crypto", "suite", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java#L322-L331
22,079
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java
HFCAClient.createNewInstance
public static HFCAClient createNewInstance(NetworkConfig.CAInfo caInfo, CryptoSuite cryptoSuite) throws MalformedURLException, InvalidArgumentException { if (null == caInfo) { throw new InvalidArgumentException("The caInfo parameter can not be null."); } if (null == cryptoSuite) { throw new InvalidArgumentException("The cryptoSuite parameter can not be null."); } HFCAClient ret = new HFCAClient(caInfo.getCAName(), caInfo.getUrl(), caInfo.getProperties()); ret.setCryptoSuite(cryptoSuite); return ret; }
java
public static HFCAClient createNewInstance(NetworkConfig.CAInfo caInfo, CryptoSuite cryptoSuite) throws MalformedURLException, InvalidArgumentException { if (null == caInfo) { throw new InvalidArgumentException("The caInfo parameter can not be null."); } if (null == cryptoSuite) { throw new InvalidArgumentException("The cryptoSuite parameter can not be null."); } HFCAClient ret = new HFCAClient(caInfo.getCAName(), caInfo.getUrl(), caInfo.getProperties()); ret.setCryptoSuite(cryptoSuite); return ret; }
[ "public", "static", "HFCAClient", "createNewInstance", "(", "NetworkConfig", ".", "CAInfo", "caInfo", ",", "CryptoSuite", "cryptoSuite", ")", "throws", "MalformedURLException", ",", "InvalidArgumentException", "{", "if", "(", "null", "==", "caInfo", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The caInfo parameter can not be null.\"", ")", ";", "}", "if", "(", "null", "==", "cryptoSuite", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The cryptoSuite parameter can not be null.\"", ")", ";", "}", "HFCAClient", "ret", "=", "new", "HFCAClient", "(", "caInfo", ".", "getCAName", "(", ")", ",", "caInfo", ".", "getUrl", "(", ")", ",", "caInfo", ".", "getProperties", "(", ")", ")", ";", "ret", ".", "setCryptoSuite", "(", "cryptoSuite", ")", ";", "return", "ret", ";", "}" ]
Create HFCAClient from a NetworkConfig.CAInfo @param caInfo created from NetworkConfig.getOrganizationInfo("org_name").getCertificateAuthorities() @param cryptoSuite the specific cryptosuite to use. @return HFCAClient @throws MalformedURLException @throws InvalidArgumentException
[ "Create", "HFCAClient", "from", "a", "NetworkConfig", ".", "CAInfo" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java#L343-L356
22,080
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java
HFCAClient.register
public String register(RegistrationRequest request, User registrar) throws RegistrationException, InvalidArgumentException { if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); } if (Utils.isNullOrEmpty(request.getEnrollmentID())) { throw new InvalidArgumentException("EntrollmentID cannot be null or empty"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } logger.debug(format("register url: %s, registrar: %s", url, registrar.getName())); setUpSSL(); try { String body = request.toJson(); JsonObject resp = httpPost(url + HFCA_REGISTER, body, registrar); String secret = resp.getString("secret"); if (secret == null) { throw new Exception("secret was not found in response"); } logger.debug(format("register url: %s, registrar: %s done.", url, registrar)); return secret; } catch (Exception e) { RegistrationException registrationException = new RegistrationException(format("Error while registering the user %s url: %s %s ", registrar, url, e.getMessage()), e); logger.error(registrar); throw registrationException; } }
java
public String register(RegistrationRequest request, User registrar) throws RegistrationException, InvalidArgumentException { if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); } if (Utils.isNullOrEmpty(request.getEnrollmentID())) { throw new InvalidArgumentException("EntrollmentID cannot be null or empty"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } logger.debug(format("register url: %s, registrar: %s", url, registrar.getName())); setUpSSL(); try { String body = request.toJson(); JsonObject resp = httpPost(url + HFCA_REGISTER, body, registrar); String secret = resp.getString("secret"); if (secret == null) { throw new Exception("secret was not found in response"); } logger.debug(format("register url: %s, registrar: %s done.", url, registrar)); return secret; } catch (Exception e) { RegistrationException registrationException = new RegistrationException(format("Error while registering the user %s url: %s %s ", registrar, url, e.getMessage()), e); logger.error(registrar); throw registrationException; } }
[ "public", "String", "register", "(", "RegistrationRequest", "request", ",", "User", "registrar", ")", "throws", "RegistrationException", ",", "InvalidArgumentException", "{", "if", "(", "cryptoSuite", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Crypto primitives not set.\"", ")", ";", "}", "if", "(", "Utils", ".", "isNullOrEmpty", "(", "request", ".", "getEnrollmentID", "(", ")", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"EntrollmentID cannot be null or empty\"", ")", ";", "}", "if", "(", "registrar", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Registrar should be a valid member\"", ")", ";", "}", "logger", ".", "debug", "(", "format", "(", "\"register url: %s, registrar: %s\"", ",", "url", ",", "registrar", ".", "getName", "(", ")", ")", ")", ";", "setUpSSL", "(", ")", ";", "try", "{", "String", "body", "=", "request", ".", "toJson", "(", ")", ";", "JsonObject", "resp", "=", "httpPost", "(", "url", "+", "HFCA_REGISTER", ",", "body", ",", "registrar", ")", ";", "String", "secret", "=", "resp", ".", "getString", "(", "\"secret\"", ")", ";", "if", "(", "secret", "==", "null", ")", "{", "throw", "new", "Exception", "(", "\"secret was not found in response\"", ")", ";", "}", "logger", ".", "debug", "(", "format", "(", "\"register url: %s, registrar: %s done.\"", ",", "url", ",", "registrar", ")", ")", ";", "return", "secret", ";", "}", "catch", "(", "Exception", "e", ")", "{", "RegistrationException", "registrationException", "=", "new", "RegistrationException", "(", "format", "(", "\"Error while registering the user %s url: %s %s \"", ",", "registrar", ",", "url", ",", "e", ".", "getMessage", "(", ")", ")", ",", "e", ")", ";", "logger", ".", "error", "(", "registrar", ")", ";", "throw", "registrationException", ";", "}", "}" ]
Register a user. @param request Registration request with the following fields: name, role. @param registrar The identity of the registrar (i.e. who is performing the registration). @return the enrollment secret. @throws RegistrationException if registration fails. @throws InvalidArgumentException
[ "Register", "a", "user", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java#L376-L410
22,081
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java
HFCAClient.info
public HFCAInfo info() throws InfoException, InvalidArgumentException { logger.debug(format("info url:%s", url)); if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); } setUpSSL(); try { JsonObjectBuilder factory = Json.createObjectBuilder(); if (caName != null) { factory.add(HFCAClient.FABRIC_CA_REQPROP, caName); } JsonObject body = factory.build(); String responseBody = httpPost(url + HFCA_INFO, body.toString(), (UsernamePasswordCredentials) null); logger.debug("response:" + responseBody); JsonReader reader = Json.createReader(new StringReader(responseBody)); JsonObject jsonst = (JsonObject) reader.read(); boolean success = jsonst.getBoolean("success"); logger.debug(format("[HFCAClient] enroll success:[%s]", success)); if (!success) { throw new EnrollmentException(format("FabricCA failed info %s", url)); } JsonObject result = jsonst.getJsonObject("result"); if (result == null) { throw new InfoException(format("FabricCA info error - response did not contain a result url %s", url)); } String caName = result.getString("CAName"); String caChain = result.getString("CAChain"); String version = null; if (result.containsKey("Version")) { version = result.getString("Version"); } String issuerPublicKey = null; if (result.containsKey("IssuerPublicKey")) { issuerPublicKey = result.getString("IssuerPublicKey"); } String issuerRevocationPublicKey = null; if (result.containsKey("IssuerRevocationPublicKey")) { issuerRevocationPublicKey = result.getString("IssuerRevocationPublicKey"); } logger.info(format("CA Name: %s, Version: %s, issuerPublicKey: %s, issuerRevocationPublicKey: %s", caName, caChain, issuerPublicKey, issuerRevocationPublicKey)); return new HFCAInfo(caName, caChain, version, issuerPublicKey, issuerRevocationPublicKey); } catch (Exception e) { InfoException ee = new InfoException(format("Url:%s, Failed to get info", url), e); logger.error(e.getMessage(), e); throw ee; } }
java
public HFCAInfo info() throws InfoException, InvalidArgumentException { logger.debug(format("info url:%s", url)); if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); } setUpSSL(); try { JsonObjectBuilder factory = Json.createObjectBuilder(); if (caName != null) { factory.add(HFCAClient.FABRIC_CA_REQPROP, caName); } JsonObject body = factory.build(); String responseBody = httpPost(url + HFCA_INFO, body.toString(), (UsernamePasswordCredentials) null); logger.debug("response:" + responseBody); JsonReader reader = Json.createReader(new StringReader(responseBody)); JsonObject jsonst = (JsonObject) reader.read(); boolean success = jsonst.getBoolean("success"); logger.debug(format("[HFCAClient] enroll success:[%s]", success)); if (!success) { throw new EnrollmentException(format("FabricCA failed info %s", url)); } JsonObject result = jsonst.getJsonObject("result"); if (result == null) { throw new InfoException(format("FabricCA info error - response did not contain a result url %s", url)); } String caName = result.getString("CAName"); String caChain = result.getString("CAChain"); String version = null; if (result.containsKey("Version")) { version = result.getString("Version"); } String issuerPublicKey = null; if (result.containsKey("IssuerPublicKey")) { issuerPublicKey = result.getString("IssuerPublicKey"); } String issuerRevocationPublicKey = null; if (result.containsKey("IssuerRevocationPublicKey")) { issuerRevocationPublicKey = result.getString("IssuerRevocationPublicKey"); } logger.info(format("CA Name: %s, Version: %s, issuerPublicKey: %s, issuerRevocationPublicKey: %s", caName, caChain, issuerPublicKey, issuerRevocationPublicKey)); return new HFCAInfo(caName, caChain, version, issuerPublicKey, issuerRevocationPublicKey); } catch (Exception e) { InfoException ee = new InfoException(format("Url:%s, Failed to get info", url), e); logger.error(e.getMessage(), e); throw ee; } }
[ "public", "HFCAInfo", "info", "(", ")", "throws", "InfoException", ",", "InvalidArgumentException", "{", "logger", ".", "debug", "(", "format", "(", "\"info url:%s\"", ",", "url", ")", ")", ";", "if", "(", "cryptoSuite", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Crypto primitives not set.\"", ")", ";", "}", "setUpSSL", "(", ")", ";", "try", "{", "JsonObjectBuilder", "factory", "=", "Json", ".", "createObjectBuilder", "(", ")", ";", "if", "(", "caName", "!=", "null", ")", "{", "factory", ".", "add", "(", "HFCAClient", ".", "FABRIC_CA_REQPROP", ",", "caName", ")", ";", "}", "JsonObject", "body", "=", "factory", ".", "build", "(", ")", ";", "String", "responseBody", "=", "httpPost", "(", "url", "+", "HFCA_INFO", ",", "body", ".", "toString", "(", ")", ",", "(", "UsernamePasswordCredentials", ")", "null", ")", ";", "logger", ".", "debug", "(", "\"response:\"", "+", "responseBody", ")", ";", "JsonReader", "reader", "=", "Json", ".", "createReader", "(", "new", "StringReader", "(", "responseBody", ")", ")", ";", "JsonObject", "jsonst", "=", "(", "JsonObject", ")", "reader", ".", "read", "(", ")", ";", "boolean", "success", "=", "jsonst", ".", "getBoolean", "(", "\"success\"", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"[HFCAClient] enroll success:[%s]\"", ",", "success", ")", ")", ";", "if", "(", "!", "success", ")", "{", "throw", "new", "EnrollmentException", "(", "format", "(", "\"FabricCA failed info %s\"", ",", "url", ")", ")", ";", "}", "JsonObject", "result", "=", "jsonst", ".", "getJsonObject", "(", "\"result\"", ")", ";", "if", "(", "result", "==", "null", ")", "{", "throw", "new", "InfoException", "(", "format", "(", "\"FabricCA info error - response did not contain a result url %s\"", ",", "url", ")", ")", ";", "}", "String", "caName", "=", "result", ".", "getString", "(", "\"CAName\"", ")", ";", "String", "caChain", "=", "result", ".", "getString", "(", "\"CAChain\"", ")", ";", "String", "version", "=", "null", ";", "if", "(", "result", ".", "containsKey", "(", "\"Version\"", ")", ")", "{", "version", "=", "result", ".", "getString", "(", "\"Version\"", ")", ";", "}", "String", "issuerPublicKey", "=", "null", ";", "if", "(", "result", ".", "containsKey", "(", "\"IssuerPublicKey\"", ")", ")", "{", "issuerPublicKey", "=", "result", ".", "getString", "(", "\"IssuerPublicKey\"", ")", ";", "}", "String", "issuerRevocationPublicKey", "=", "null", ";", "if", "(", "result", ".", "containsKey", "(", "\"IssuerRevocationPublicKey\"", ")", ")", "{", "issuerRevocationPublicKey", "=", "result", ".", "getString", "(", "\"IssuerRevocationPublicKey\"", ")", ";", "}", "logger", ".", "info", "(", "format", "(", "\"CA Name: %s, Version: %s, issuerPublicKey: %s, issuerRevocationPublicKey: %s\"", ",", "caName", ",", "caChain", ",", "issuerPublicKey", ",", "issuerRevocationPublicKey", ")", ")", ";", "return", "new", "HFCAInfo", "(", "caName", ",", "caChain", ",", "version", ",", "issuerPublicKey", ",", "issuerRevocationPublicKey", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "InfoException", "ee", "=", "new", "InfoException", "(", "format", "(", "\"Url:%s, Failed to get info\"", ",", "url", ")", ",", "e", ")", ";", "logger", ".", "error", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "throw", "ee", ";", "}", "}" ]
Return information on the Fabric Certificate Authority. No credentials are needed for this API. @return {@link HFCAInfo} @throws InfoException @throws InvalidArgumentException
[ "Return", "information", "on", "the", "Fabric", "Certificate", "Authority", ".", "No", "credentials", "are", "needed", "for", "this", "API", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java#L534-L596
22,082
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java
HFCAClient.reenroll
public Enrollment reenroll(User user, EnrollmentRequest req) throws EnrollmentException, InvalidArgumentException { if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); } if (user == null) { throw new InvalidArgumentException("reenrollment user is missing"); } if (user.getEnrollment() == null) { throw new InvalidArgumentException("reenrollment user is not a valid user object"); } logger.debug(format("re-enroll user: %s, url: %s", user.getName(), url)); try { setUpSSL(); PublicKey publicKey = cryptoSuite.bytesToCertificate(user.getEnrollment().getCert() .getBytes(StandardCharsets.UTF_8)).getPublicKey(); KeyPair keypair = new KeyPair(publicKey, user.getEnrollment().getKey()); // generate CSR String pem = cryptoSuite.generateCertificationRequest(user.getName(), keypair); // build request body req.setCSR(pem); if (caName != null && !caName.isEmpty()) { req.setCAName(caName); } String body = req.toJson(); // build authentication header JsonObject result = httpPost(url + HFCA_REENROLL, body, user); // get new cert from response Base64.Decoder b64dec = Base64.getDecoder(); String signedPem = new String(b64dec.decode(result.getString("Cert").getBytes(UTF_8))); logger.debug(format("[HFCAClient] re-enroll returned pem:[%s]", signedPem)); logger.debug(format("reenroll user %s done.", user.getName())); return new X509Enrollment(keypair, signedPem); } catch (EnrollmentException ee) { logger.error(ee.getMessage(), ee); throw ee; } catch (Exception e) { EnrollmentException ee = new EnrollmentException(format("Failed to re-enroll user %s", user), e); logger.error(e.getMessage(), e); throw ee; } }
java
public Enrollment reenroll(User user, EnrollmentRequest req) throws EnrollmentException, InvalidArgumentException { if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); } if (user == null) { throw new InvalidArgumentException("reenrollment user is missing"); } if (user.getEnrollment() == null) { throw new InvalidArgumentException("reenrollment user is not a valid user object"); } logger.debug(format("re-enroll user: %s, url: %s", user.getName(), url)); try { setUpSSL(); PublicKey publicKey = cryptoSuite.bytesToCertificate(user.getEnrollment().getCert() .getBytes(StandardCharsets.UTF_8)).getPublicKey(); KeyPair keypair = new KeyPair(publicKey, user.getEnrollment().getKey()); // generate CSR String pem = cryptoSuite.generateCertificationRequest(user.getName(), keypair); // build request body req.setCSR(pem); if (caName != null && !caName.isEmpty()) { req.setCAName(caName); } String body = req.toJson(); // build authentication header JsonObject result = httpPost(url + HFCA_REENROLL, body, user); // get new cert from response Base64.Decoder b64dec = Base64.getDecoder(); String signedPem = new String(b64dec.decode(result.getString("Cert").getBytes(UTF_8))); logger.debug(format("[HFCAClient] re-enroll returned pem:[%s]", signedPem)); logger.debug(format("reenroll user %s done.", user.getName())); return new X509Enrollment(keypair, signedPem); } catch (EnrollmentException ee) { logger.error(ee.getMessage(), ee); throw ee; } catch (Exception e) { EnrollmentException ee = new EnrollmentException(format("Failed to re-enroll user %s", user), e); logger.error(e.getMessage(), e); throw ee; } }
[ "public", "Enrollment", "reenroll", "(", "User", "user", ",", "EnrollmentRequest", "req", ")", "throws", "EnrollmentException", ",", "InvalidArgumentException", "{", "if", "(", "cryptoSuite", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Crypto primitives not set.\"", ")", ";", "}", "if", "(", "user", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"reenrollment user is missing\"", ")", ";", "}", "if", "(", "user", ".", "getEnrollment", "(", ")", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"reenrollment user is not a valid user object\"", ")", ";", "}", "logger", ".", "debug", "(", "format", "(", "\"re-enroll user: %s, url: %s\"", ",", "user", ".", "getName", "(", ")", ",", "url", ")", ")", ";", "try", "{", "setUpSSL", "(", ")", ";", "PublicKey", "publicKey", "=", "cryptoSuite", ".", "bytesToCertificate", "(", "user", ".", "getEnrollment", "(", ")", ".", "getCert", "(", ")", ".", "getBytes", "(", "StandardCharsets", ".", "UTF_8", ")", ")", ".", "getPublicKey", "(", ")", ";", "KeyPair", "keypair", "=", "new", "KeyPair", "(", "publicKey", ",", "user", ".", "getEnrollment", "(", ")", ".", "getKey", "(", ")", ")", ";", "// generate CSR", "String", "pem", "=", "cryptoSuite", ".", "generateCertificationRequest", "(", "user", ".", "getName", "(", ")", ",", "keypair", ")", ";", "// build request body", "req", ".", "setCSR", "(", "pem", ")", ";", "if", "(", "caName", "!=", "null", "&&", "!", "caName", ".", "isEmpty", "(", ")", ")", "{", "req", ".", "setCAName", "(", "caName", ")", ";", "}", "String", "body", "=", "req", ".", "toJson", "(", ")", ";", "// build authentication header", "JsonObject", "result", "=", "httpPost", "(", "url", "+", "HFCA_REENROLL", ",", "body", ",", "user", ")", ";", "// get new cert from response", "Base64", ".", "Decoder", "b64dec", "=", "Base64", ".", "getDecoder", "(", ")", ";", "String", "signedPem", "=", "new", "String", "(", "b64dec", ".", "decode", "(", "result", ".", "getString", "(", "\"Cert\"", ")", ".", "getBytes", "(", "UTF_8", ")", ")", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"[HFCAClient] re-enroll returned pem:[%s]\"", ",", "signedPem", ")", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"reenroll user %s done.\"", ",", "user", ".", "getName", "(", ")", ")", ")", ";", "return", "new", "X509Enrollment", "(", "keypair", ",", "signedPem", ")", ";", "}", "catch", "(", "EnrollmentException", "ee", ")", "{", "logger", ".", "error", "(", "ee", ".", "getMessage", "(", ")", ",", "ee", ")", ";", "throw", "ee", ";", "}", "catch", "(", "Exception", "e", ")", "{", "EnrollmentException", "ee", "=", "new", "EnrollmentException", "(", "format", "(", "\"Failed to re-enroll user %s\"", ",", "user", ")", ",", "e", ")", ";", "logger", ".", "error", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "throw", "ee", ";", "}", "}" ]
Re-Enroll the user with member service @param user User to be re-enrolled @param req Enrollment request with the following fields: hosts, profile, csr, label @return enrollment @throws EnrollmentException @throws InvalidArgumentException
[ "Re", "-", "Enroll", "the", "user", "with", "member", "service" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java#L620-L673
22,083
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java
HFCAClient.revoke
public void revoke(User revoker, Enrollment enrollment, String reason) throws RevocationException, InvalidArgumentException { revokeInternal(revoker, enrollment, reason, false); }
java
public void revoke(User revoker, Enrollment enrollment, String reason) throws RevocationException, InvalidArgumentException { revokeInternal(revoker, enrollment, reason, false); }
[ "public", "void", "revoke", "(", "User", "revoker", ",", "Enrollment", "enrollment", ",", "String", "reason", ")", "throws", "RevocationException", ",", "InvalidArgumentException", "{", "revokeInternal", "(", "revoker", ",", "enrollment", ",", "reason", ",", "false", ")", ";", "}" ]
revoke one enrollment of user @param revoker admin user who has revoker attribute configured in CA-server @param enrollment the user enrollment to be revoked @param reason revoke reason, see RFC 5280 @throws RevocationException @throws InvalidArgumentException
[ "revoke", "one", "enrollment", "of", "user" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java#L685-L687
22,084
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java
HFCAClient.revoke
public void revoke(User revoker, String serial, String aki, String reason) throws RevocationException, InvalidArgumentException { revokeInternal(revoker, serial, aki, reason, false); }
java
public void revoke(User revoker, String serial, String aki, String reason) throws RevocationException, InvalidArgumentException { revokeInternal(revoker, serial, aki, reason, false); }
[ "public", "void", "revoke", "(", "User", "revoker", ",", "String", "serial", ",", "String", "aki", ",", "String", "reason", ")", "throws", "RevocationException", ",", "InvalidArgumentException", "{", "revokeInternal", "(", "revoker", ",", "serial", ",", "aki", ",", "reason", ",", "false", ")", ";", "}" ]
revoke one certificate @param revoker admin user who has revoker attribute configured in CA-server @param serial serial number of the certificate to be revoked @param aki aki of the certificate to be revoke @param reason revoke reason, see RFC 5280 @throws RevocationException @throws InvalidArgumentException
[ "revoke", "one", "certificate" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java#L847-L849
22,085
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java
HFCAClient.generateCRL
public String generateCRL(User registrar, Date revokedBefore, Date revokedAfter, Date expireBefore, Date expireAfter) throws InvalidArgumentException, GenerateCRLException { if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); } if (registrar == null) { throw new InvalidArgumentException("registrar is not set"); } try { setUpSSL(); //--------------------------------------- JsonObjectBuilder factory = Json.createObjectBuilder(); if (revokedBefore != null) { factory.add("revokedBefore", Util.dateToString(revokedBefore)); } if (revokedAfter != null) { factory.add("revokedAfter", Util.dateToString(revokedAfter)); } if (expireBefore != null) { factory.add("expireBefore", Util.dateToString(expireBefore)); } if (expireAfter != null) { factory.add("expireAfter", Util.dateToString(expireAfter)); } if (caName != null) { factory.add(HFCAClient.FABRIC_CA_REQPROP, caName); } JsonObject jsonObject = factory.build(); StringWriter stringWriter = new StringWriter(); JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter)); jsonWriter.writeObject(jsonObject); jsonWriter.close(); String body = stringWriter.toString(); //--------------------------------------- // send revoke request JsonObject ret = httpPost(url + HFCA_GENCRL, body, registrar); return ret.getString("CRL"); } catch (Exception e) { logger.error(e.getMessage(), e); throw new GenerateCRLException(e.getMessage(), e); } }
java
public String generateCRL(User registrar, Date revokedBefore, Date revokedAfter, Date expireBefore, Date expireAfter) throws InvalidArgumentException, GenerateCRLException { if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); } if (registrar == null) { throw new InvalidArgumentException("registrar is not set"); } try { setUpSSL(); //--------------------------------------- JsonObjectBuilder factory = Json.createObjectBuilder(); if (revokedBefore != null) { factory.add("revokedBefore", Util.dateToString(revokedBefore)); } if (revokedAfter != null) { factory.add("revokedAfter", Util.dateToString(revokedAfter)); } if (expireBefore != null) { factory.add("expireBefore", Util.dateToString(expireBefore)); } if (expireAfter != null) { factory.add("expireAfter", Util.dateToString(expireAfter)); } if (caName != null) { factory.add(HFCAClient.FABRIC_CA_REQPROP, caName); } JsonObject jsonObject = factory.build(); StringWriter stringWriter = new StringWriter(); JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter)); jsonWriter.writeObject(jsonObject); jsonWriter.close(); String body = stringWriter.toString(); //--------------------------------------- // send revoke request JsonObject ret = httpPost(url + HFCA_GENCRL, body, registrar); return ret.getString("CRL"); } catch (Exception e) { logger.error(e.getMessage(), e); throw new GenerateCRLException(e.getMessage(), e); } }
[ "public", "String", "generateCRL", "(", "User", "registrar", ",", "Date", "revokedBefore", ",", "Date", "revokedAfter", ",", "Date", "expireBefore", ",", "Date", "expireAfter", ")", "throws", "InvalidArgumentException", ",", "GenerateCRLException", "{", "if", "(", "cryptoSuite", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Crypto primitives not set.\"", ")", ";", "}", "if", "(", "registrar", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"registrar is not set\"", ")", ";", "}", "try", "{", "setUpSSL", "(", ")", ";", "//---------------------------------------", "JsonObjectBuilder", "factory", "=", "Json", ".", "createObjectBuilder", "(", ")", ";", "if", "(", "revokedBefore", "!=", "null", ")", "{", "factory", ".", "add", "(", "\"revokedBefore\"", ",", "Util", ".", "dateToString", "(", "revokedBefore", ")", ")", ";", "}", "if", "(", "revokedAfter", "!=", "null", ")", "{", "factory", ".", "add", "(", "\"revokedAfter\"", ",", "Util", ".", "dateToString", "(", "revokedAfter", ")", ")", ";", "}", "if", "(", "expireBefore", "!=", "null", ")", "{", "factory", ".", "add", "(", "\"expireBefore\"", ",", "Util", ".", "dateToString", "(", "expireBefore", ")", ")", ";", "}", "if", "(", "expireAfter", "!=", "null", ")", "{", "factory", ".", "add", "(", "\"expireAfter\"", ",", "Util", ".", "dateToString", "(", "expireAfter", ")", ")", ";", "}", "if", "(", "caName", "!=", "null", ")", "{", "factory", ".", "add", "(", "HFCAClient", ".", "FABRIC_CA_REQPROP", ",", "caName", ")", ";", "}", "JsonObject", "jsonObject", "=", "factory", ".", "build", "(", ")", ";", "StringWriter", "stringWriter", "=", "new", "StringWriter", "(", ")", ";", "JsonWriter", "jsonWriter", "=", "Json", ".", "createWriter", "(", "new", "PrintWriter", "(", "stringWriter", ")", ")", ";", "jsonWriter", ".", "writeObject", "(", "jsonObject", ")", ";", "jsonWriter", ".", "close", "(", ")", ";", "String", "body", "=", "stringWriter", ".", "toString", "(", ")", ";", "//---------------------------------------", "// send revoke request", "JsonObject", "ret", "=", "httpPost", "(", "url", "+", "HFCA_GENCRL", ",", "body", ",", "registrar", ")", ";", "return", "ret", ".", "getString", "(", "\"CRL\"", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "logger", ".", "error", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "throw", "new", "GenerateCRLException", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "}" ]
Generate certificate revocation list. @param registrar admin user configured in CA-server @param revokedBefore Restrict certificates returned to revoked before this date if not null. @param revokedAfter Restrict certificates returned to revoked after this date if not null. @param expireBefore Restrict certificates returned to expired before this date if not null. @param expireAfter Restrict certificates returned to expired after this date if not null. @throws InvalidArgumentException
[ "Generate", "certificate", "revocation", "list", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java#L926-L977
22,086
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java
HFCAClient.getHFCAIdentities
public Collection<HFCAIdentity> getHFCAIdentities(User registrar) throws IdentityException, InvalidArgumentException { if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } logger.debug(format("identity url: %s, registrar: %s", url, registrar.getName())); try { JsonObject result = httpGet(HFCAIdentity.HFCA_IDENTITY, registrar); Collection<HFCAIdentity> allIdentities = new ArrayList<>(); JsonArray identities = result.getJsonArray("identities"); if (identities != null && !identities.isEmpty()) { for (int i = 0; i < identities.size(); i++) { JsonObject identity = identities.getJsonObject(i); HFCAIdentity idObj = new HFCAIdentity(identity); allIdentities.add(idObj); } } logger.debug(format("identity url: %s, registrar: %s done.", url, registrar)); return allIdentities; } catch (HTTPException e) { String msg = format("[HTTP Status Code: %d] - Error while getting all users from url '%s': %s", e.getStatusCode(), url, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while getting all users from url '%s': %s", url, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
java
public Collection<HFCAIdentity> getHFCAIdentities(User registrar) throws IdentityException, InvalidArgumentException { if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } logger.debug(format("identity url: %s, registrar: %s", url, registrar.getName())); try { JsonObject result = httpGet(HFCAIdentity.HFCA_IDENTITY, registrar); Collection<HFCAIdentity> allIdentities = new ArrayList<>(); JsonArray identities = result.getJsonArray("identities"); if (identities != null && !identities.isEmpty()) { for (int i = 0; i < identities.size(); i++) { JsonObject identity = identities.getJsonObject(i); HFCAIdentity idObj = new HFCAIdentity(identity); allIdentities.add(idObj); } } logger.debug(format("identity url: %s, registrar: %s done.", url, registrar)); return allIdentities; } catch (HTTPException e) { String msg = format("[HTTP Status Code: %d] - Error while getting all users from url '%s': %s", e.getStatusCode(), url, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while getting all users from url '%s': %s", url, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
[ "public", "Collection", "<", "HFCAIdentity", ">", "getHFCAIdentities", "(", "User", "registrar", ")", "throws", "IdentityException", ",", "InvalidArgumentException", "{", "if", "(", "registrar", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Registrar should be a valid member\"", ")", ";", "}", "logger", ".", "debug", "(", "format", "(", "\"identity url: %s, registrar: %s\"", ",", "url", ",", "registrar", ".", "getName", "(", ")", ")", ")", ";", "try", "{", "JsonObject", "result", "=", "httpGet", "(", "HFCAIdentity", ".", "HFCA_IDENTITY", ",", "registrar", ")", ";", "Collection", "<", "HFCAIdentity", ">", "allIdentities", "=", "new", "ArrayList", "<>", "(", ")", ";", "JsonArray", "identities", "=", "result", ".", "getJsonArray", "(", "\"identities\"", ")", ";", "if", "(", "identities", "!=", "null", "&&", "!", "identities", ".", "isEmpty", "(", ")", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "identities", ".", "size", "(", ")", ";", "i", "++", ")", "{", "JsonObject", "identity", "=", "identities", ".", "getJsonObject", "(", "i", ")", ";", "HFCAIdentity", "idObj", "=", "new", "HFCAIdentity", "(", "identity", ")", ";", "allIdentities", ".", "add", "(", "idObj", ")", ";", "}", "}", "logger", ".", "debug", "(", "format", "(", "\"identity url: %s, registrar: %s done.\"", ",", "url", ",", "registrar", ")", ")", ";", "return", "allIdentities", ";", "}", "catch", "(", "HTTPException", "e", ")", "{", "String", "msg", "=", "format", "(", "\"[HTTP Status Code: %d] - Error while getting all users from url '%s': %s\"", ",", "e", ".", "getStatusCode", "(", ")", ",", "url", ",", "e", ".", "getMessage", "(", ")", ")", ";", "IdentityException", "identityException", "=", "new", "IdentityException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "identityException", ";", "}", "catch", "(", "Exception", "e", ")", "{", "String", "msg", "=", "format", "(", "\"Error while getting all users from url '%s': %s\"", ",", "url", ",", "e", ".", "getMessage", "(", ")", ")", ";", "IdentityException", "identityException", "=", "new", "IdentityException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "identityException", ";", "}", "}" ]
gets all identities that the registrar is allowed to see @param registrar The identity of the registrar (i.e. who is performing the registration). @return the identity that was requested @throws IdentityException if adding an identity fails. @throws InvalidArgumentException Invalid (null) argument specified
[ "gets", "all", "identities", "that", "the", "registrar", "is", "allowed", "to", "see" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java#L1000-L1035
22,087
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java
HFCAClient.getHFCAAffiliations
public HFCAAffiliation getHFCAAffiliations(User registrar) throws AffiliationException, InvalidArgumentException { if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } logger.debug(format("affiliations url: %s, registrar: %s", url, registrar.getName())); try { JsonObject result = httpGet(HFCAAffiliation.HFCA_AFFILIATION, registrar); HFCAAffiliation affiliations = new HFCAAffiliation(result); logger.debug(format("affiliations url: %s, registrar: %s done.", url, registrar)); return affiliations; } catch (HTTPException e) { String msg = format("[HTTP Status Code: %d] - Error while getting all affiliations from url '%s': %s", e.getStatusCode(), url, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } catch (Exception e) { String msg = format("Error while getting all affiliations from url '%s': %s", url, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } }
java
public HFCAAffiliation getHFCAAffiliations(User registrar) throws AffiliationException, InvalidArgumentException { if (cryptoSuite == null) { throw new InvalidArgumentException("Crypto primitives not set."); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } logger.debug(format("affiliations url: %s, registrar: %s", url, registrar.getName())); try { JsonObject result = httpGet(HFCAAffiliation.HFCA_AFFILIATION, registrar); HFCAAffiliation affiliations = new HFCAAffiliation(result); logger.debug(format("affiliations url: %s, registrar: %s done.", url, registrar)); return affiliations; } catch (HTTPException e) { String msg = format("[HTTP Status Code: %d] - Error while getting all affiliations from url '%s': %s", e.getStatusCode(), url, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } catch (Exception e) { String msg = format("Error while getting all affiliations from url '%s': %s", url, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; } }
[ "public", "HFCAAffiliation", "getHFCAAffiliations", "(", "User", "registrar", ")", "throws", "AffiliationException", ",", "InvalidArgumentException", "{", "if", "(", "cryptoSuite", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Crypto primitives not set.\"", ")", ";", "}", "if", "(", "registrar", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Registrar should be a valid member\"", ")", ";", "}", "logger", ".", "debug", "(", "format", "(", "\"affiliations url: %s, registrar: %s\"", ",", "url", ",", "registrar", ".", "getName", "(", ")", ")", ")", ";", "try", "{", "JsonObject", "result", "=", "httpGet", "(", "HFCAAffiliation", ".", "HFCA_AFFILIATION", ",", "registrar", ")", ";", "HFCAAffiliation", "affiliations", "=", "new", "HFCAAffiliation", "(", "result", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"affiliations url: %s, registrar: %s done.\"", ",", "url", ",", "registrar", ")", ")", ";", "return", "affiliations", ";", "}", "catch", "(", "HTTPException", "e", ")", "{", "String", "msg", "=", "format", "(", "\"[HTTP Status Code: %d] - Error while getting all affiliations from url '%s': %s\"", ",", "e", ".", "getStatusCode", "(", ")", ",", "url", ",", "e", ".", "getMessage", "(", ")", ")", ";", "AffiliationException", "affiliationException", "=", "new", "AffiliationException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "affiliationException", ";", "}", "catch", "(", "Exception", "e", ")", "{", "String", "msg", "=", "format", "(", "\"Error while getting all affiliations from url '%s': %s\"", ",", "url", ",", "e", ".", "getMessage", "(", ")", ")", ";", "AffiliationException", "affiliationException", "=", "new", "AffiliationException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "affiliationException", ";", "}", "}" ]
gets all affiliations that the registrar is allowed to see @param registrar The identity of the registrar (i.e. who is performing the registration). @return The affiliations that were requested @throws AffiliationException if getting all affiliations fails @throws InvalidArgumentException
[ "gets", "all", "affiliations", "that", "the", "registrar", "is", "allowed", "to", "see" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java#L1055-L1084
22,088
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java
HFCAClient.getHFCACertificates
public HFCACertificateResponse getHFCACertificates(User registrar, HFCACertificateRequest req) throws HFCACertificateException { try { logger.debug(format("certificate url: %s, registrar: %s", HFCA_CERTIFICATE, registrar.getName())); JsonObject result = httpGet(HFCA_CERTIFICATE, registrar, req.getQueryParameters()); int statusCode = result.getInt("statusCode"); Collection<HFCACredential> certs = new ArrayList<>(); if (statusCode < 400) { JsonArray certificates = result.getJsonArray("certs"); if (certificates != null && !certificates.isEmpty()) { for (int i = 0; i < certificates.size(); i++) { String certPEM = certificates.getJsonObject(i).getString("PEM"); certs.add(new HFCAX509Certificate(certPEM)); } } logger.debug(format("certificate url: %s, registrar: %s done.", HFCA_CERTIFICATE, registrar)); } return new HFCACertificateResponse(statusCode, certs); } catch (HTTPException e) { String msg = format("[Code: %d] - Error while getting certificates from url '%s': %s", e.getStatusCode(), HFCA_CERTIFICATE, e.getMessage()); HFCACertificateException certificateException = new HFCACertificateException(msg, e); logger.error(msg); throw certificateException; } catch (Exception e) { String msg = format("Error while getting certificates from url '%s': %s", HFCA_CERTIFICATE, e.getMessage()); HFCACertificateException certificateException = new HFCACertificateException(msg, e); logger.error(msg); throw certificateException; } }
java
public HFCACertificateResponse getHFCACertificates(User registrar, HFCACertificateRequest req) throws HFCACertificateException { try { logger.debug(format("certificate url: %s, registrar: %s", HFCA_CERTIFICATE, registrar.getName())); JsonObject result = httpGet(HFCA_CERTIFICATE, registrar, req.getQueryParameters()); int statusCode = result.getInt("statusCode"); Collection<HFCACredential> certs = new ArrayList<>(); if (statusCode < 400) { JsonArray certificates = result.getJsonArray("certs"); if (certificates != null && !certificates.isEmpty()) { for (int i = 0; i < certificates.size(); i++) { String certPEM = certificates.getJsonObject(i).getString("PEM"); certs.add(new HFCAX509Certificate(certPEM)); } } logger.debug(format("certificate url: %s, registrar: %s done.", HFCA_CERTIFICATE, registrar)); } return new HFCACertificateResponse(statusCode, certs); } catch (HTTPException e) { String msg = format("[Code: %d] - Error while getting certificates from url '%s': %s", e.getStatusCode(), HFCA_CERTIFICATE, e.getMessage()); HFCACertificateException certificateException = new HFCACertificateException(msg, e); logger.error(msg); throw certificateException; } catch (Exception e) { String msg = format("Error while getting certificates from url '%s': %s", HFCA_CERTIFICATE, e.getMessage()); HFCACertificateException certificateException = new HFCACertificateException(msg, e); logger.error(msg); throw certificateException; } }
[ "public", "HFCACertificateResponse", "getHFCACertificates", "(", "User", "registrar", ",", "HFCACertificateRequest", "req", ")", "throws", "HFCACertificateException", "{", "try", "{", "logger", ".", "debug", "(", "format", "(", "\"certificate url: %s, registrar: %s\"", ",", "HFCA_CERTIFICATE", ",", "registrar", ".", "getName", "(", ")", ")", ")", ";", "JsonObject", "result", "=", "httpGet", "(", "HFCA_CERTIFICATE", ",", "registrar", ",", "req", ".", "getQueryParameters", "(", ")", ")", ";", "int", "statusCode", "=", "result", ".", "getInt", "(", "\"statusCode\"", ")", ";", "Collection", "<", "HFCACredential", ">", "certs", "=", "new", "ArrayList", "<>", "(", ")", ";", "if", "(", "statusCode", "<", "400", ")", "{", "JsonArray", "certificates", "=", "result", ".", "getJsonArray", "(", "\"certs\"", ")", ";", "if", "(", "certificates", "!=", "null", "&&", "!", "certificates", ".", "isEmpty", "(", ")", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "certificates", ".", "size", "(", ")", ";", "i", "++", ")", "{", "String", "certPEM", "=", "certificates", ".", "getJsonObject", "(", "i", ")", ".", "getString", "(", "\"PEM\"", ")", ";", "certs", ".", "add", "(", "new", "HFCAX509Certificate", "(", "certPEM", ")", ")", ";", "}", "}", "logger", ".", "debug", "(", "format", "(", "\"certificate url: %s, registrar: %s done.\"", ",", "HFCA_CERTIFICATE", ",", "registrar", ")", ")", ";", "}", "return", "new", "HFCACertificateResponse", "(", "statusCode", ",", "certs", ")", ";", "}", "catch", "(", "HTTPException", "e", ")", "{", "String", "msg", "=", "format", "(", "\"[Code: %d] - Error while getting certificates from url '%s': %s\"", ",", "e", ".", "getStatusCode", "(", ")", ",", "HFCA_CERTIFICATE", ",", "e", ".", "getMessage", "(", ")", ")", ";", "HFCACertificateException", "certificateException", "=", "new", "HFCACertificateException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "certificateException", ";", "}", "catch", "(", "Exception", "e", ")", "{", "String", "msg", "=", "format", "(", "\"Error while getting certificates from url '%s': %s\"", ",", "HFCA_CERTIFICATE", ",", "e", ".", "getMessage", "(", ")", ")", ";", "HFCACertificateException", "certificateException", "=", "new", "HFCACertificateException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "certificateException", ";", "}", "}" ]
Gets all certificates that the registrar is allowed to see and based on filter parameters that are part of the certificate request. @param registrar The identity of the registrar (i.e. who is performing the registration). @param req The certificate request that contains filter parameters @return HFCACertificateResponse object @throws HFCACertificateException Failed to process get certificate request
[ "Gets", "all", "certificates", "that", "the", "registrar", "is", "allowed", "to", "see", "and", "based", "on", "filter", "parameters", "that", "are", "part", "of", "the", "certificate", "request", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java#L1224-L1254
22,089
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java
HFCAClient.httpPost
String httpPost(String url, String body, UsernamePasswordCredentials credentials) throws Exception { logger.debug(format("httpPost %s, body:%s", url, body)); final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); CredentialsProvider provider = null; if (credentials != null) { provider = new BasicCredentialsProvider(); provider.setCredentials(AuthScope.ANY, credentials); httpClientBuilder.setDefaultCredentialsProvider(provider); } if (registry != null) { httpClientBuilder.setConnectionManager(new PoolingHttpClientConnectionManager(registry)); } HttpClient client = httpClientBuilder.build(); HttpPost httpPost = new HttpPost(url); httpPost.setConfig(getRequestConfig()); AuthCache authCache = new BasicAuthCache(); HttpHost targetHost = new HttpHost(httpPost.getURI().getHost(), httpPost.getURI().getPort()); if (credentials != null) { authCache.put(targetHost, new BasicScheme()); } final HttpClientContext context = HttpClientContext.create(); if (null != provider) { context.setCredentialsProvider(provider); } if (credentials != null) { context.setAuthCache(authCache); } httpPost.setEntity(new StringEntity(body)); if (credentials != null) { httpPost.addHeader(new BasicScheme(). authenticate(credentials, httpPost, context)); } HttpResponse response = client.execute(httpPost, context); int status = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); logger.trace(format("httpPost %s sending...", url)); String responseBody = entity != null ? EntityUtils.toString(entity) : null; logger.trace(format("httpPost %s responseBody %s", url, responseBody)); if (status >= 400) { Exception e = new Exception(format("POST request to %s with request body: %s, " + "failed with status code: %d. Response: %s", url, body, status, responseBody)); logger.error(e.getMessage()); throw e; } logger.debug(format("httpPost Status: %d returning: %s ", status, responseBody)); return responseBody; }
java
String httpPost(String url, String body, UsernamePasswordCredentials credentials) throws Exception { logger.debug(format("httpPost %s, body:%s", url, body)); final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); CredentialsProvider provider = null; if (credentials != null) { provider = new BasicCredentialsProvider(); provider.setCredentials(AuthScope.ANY, credentials); httpClientBuilder.setDefaultCredentialsProvider(provider); } if (registry != null) { httpClientBuilder.setConnectionManager(new PoolingHttpClientConnectionManager(registry)); } HttpClient client = httpClientBuilder.build(); HttpPost httpPost = new HttpPost(url); httpPost.setConfig(getRequestConfig()); AuthCache authCache = new BasicAuthCache(); HttpHost targetHost = new HttpHost(httpPost.getURI().getHost(), httpPost.getURI().getPort()); if (credentials != null) { authCache.put(targetHost, new BasicScheme()); } final HttpClientContext context = HttpClientContext.create(); if (null != provider) { context.setCredentialsProvider(provider); } if (credentials != null) { context.setAuthCache(authCache); } httpPost.setEntity(new StringEntity(body)); if (credentials != null) { httpPost.addHeader(new BasicScheme(). authenticate(credentials, httpPost, context)); } HttpResponse response = client.execute(httpPost, context); int status = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); logger.trace(format("httpPost %s sending...", url)); String responseBody = entity != null ? EntityUtils.toString(entity) : null; logger.trace(format("httpPost %s responseBody %s", url, responseBody)); if (status >= 400) { Exception e = new Exception(format("POST request to %s with request body: %s, " + "failed with status code: %d. Response: %s", url, body, status, responseBody)); logger.error(e.getMessage()); throw e; } logger.debug(format("httpPost Status: %d returning: %s ", status, responseBody)); return responseBody; }
[ "String", "httpPost", "(", "String", "url", ",", "String", "body", ",", "UsernamePasswordCredentials", "credentials", ")", "throws", "Exception", "{", "logger", ".", "debug", "(", "format", "(", "\"httpPost %s, body:%s\"", ",", "url", ",", "body", ")", ")", ";", "final", "HttpClientBuilder", "httpClientBuilder", "=", "HttpClientBuilder", ".", "create", "(", ")", ";", "CredentialsProvider", "provider", "=", "null", ";", "if", "(", "credentials", "!=", "null", ")", "{", "provider", "=", "new", "BasicCredentialsProvider", "(", ")", ";", "provider", ".", "setCredentials", "(", "AuthScope", ".", "ANY", ",", "credentials", ")", ";", "httpClientBuilder", ".", "setDefaultCredentialsProvider", "(", "provider", ")", ";", "}", "if", "(", "registry", "!=", "null", ")", "{", "httpClientBuilder", ".", "setConnectionManager", "(", "new", "PoolingHttpClientConnectionManager", "(", "registry", ")", ")", ";", "}", "HttpClient", "client", "=", "httpClientBuilder", ".", "build", "(", ")", ";", "HttpPost", "httpPost", "=", "new", "HttpPost", "(", "url", ")", ";", "httpPost", ".", "setConfig", "(", "getRequestConfig", "(", ")", ")", ";", "AuthCache", "authCache", "=", "new", "BasicAuthCache", "(", ")", ";", "HttpHost", "targetHost", "=", "new", "HttpHost", "(", "httpPost", ".", "getURI", "(", ")", ".", "getHost", "(", ")", ",", "httpPost", ".", "getURI", "(", ")", ".", "getPort", "(", ")", ")", ";", "if", "(", "credentials", "!=", "null", ")", "{", "authCache", ".", "put", "(", "targetHost", ",", "new", "BasicScheme", "(", ")", ")", ";", "}", "final", "HttpClientContext", "context", "=", "HttpClientContext", ".", "create", "(", ")", ";", "if", "(", "null", "!=", "provider", ")", "{", "context", ".", "setCredentialsProvider", "(", "provider", ")", ";", "}", "if", "(", "credentials", "!=", "null", ")", "{", "context", ".", "setAuthCache", "(", "authCache", ")", ";", "}", "httpPost", ".", "setEntity", "(", "new", "StringEntity", "(", "body", ")", ")", ";", "if", "(", "credentials", "!=", "null", ")", "{", "httpPost", ".", "addHeader", "(", "new", "BasicScheme", "(", ")", ".", "authenticate", "(", "credentials", ",", "httpPost", ",", "context", ")", ")", ";", "}", "HttpResponse", "response", "=", "client", ".", "execute", "(", "httpPost", ",", "context", ")", ";", "int", "status", "=", "response", ".", "getStatusLine", "(", ")", ".", "getStatusCode", "(", ")", ";", "HttpEntity", "entity", "=", "response", ".", "getEntity", "(", ")", ";", "logger", ".", "trace", "(", "format", "(", "\"httpPost %s sending...\"", ",", "url", ")", ")", ";", "String", "responseBody", "=", "entity", "!=", "null", "?", "EntityUtils", ".", "toString", "(", "entity", ")", ":", "null", ";", "logger", ".", "trace", "(", "format", "(", "\"httpPost %s responseBody %s\"", ",", "url", ",", "responseBody", ")", ")", ";", "if", "(", "status", ">=", "400", ")", "{", "Exception", "e", "=", "new", "Exception", "(", "format", "(", "\"POST request to %s with request body: %s, \"", "+", "\"failed with status code: %d. Response: %s\"", ",", "url", ",", "body", ",", "status", ",", "responseBody", ")", ")", ";", "logger", ".", "error", "(", "e", ".", "getMessage", "(", ")", ")", ";", "throw", "e", ";", "}", "logger", ".", "debug", "(", "format", "(", "\"httpPost Status: %d returning: %s \"", ",", "status", ",", "responseBody", ")", ")", ";", "return", "responseBody", ";", "}" ]
Http Post Request. @param url Target URL to POST to. @param body Body to be sent with the post. @param credentials Credentials to use for basic auth. @return Body of post returned. @throws Exception
[ "Http", "Post", "Request", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java#L1266-L1337
22,090
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAIdentity.java
HFCAIdentity.read
public int read(User registrar) throws IdentityException, InvalidArgumentException { if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String readIdURL = ""; try { readIdURL = HFCA_IDENTITY + "/" + enrollmentID; logger.debug(format("identity url: %s, registrar: %s", readIdURL, registrar.getName())); JsonObject result = client.httpGet(readIdURL, registrar); statusCode = result.getInt("statusCode"); if (statusCode < 400) { type = result.getString("type"); maxEnrollments = result.getInt("max_enrollments"); affiliation = result.getString("affiliation"); JsonArray attributes = result.getJsonArray("attrs"); Collection<Attribute> attrs = new ArrayList<Attribute>(); if (attributes != null && !attributes.isEmpty()) { for (int i = 0; i < attributes.size(); i++) { JsonObject attribute = attributes.getJsonObject(i); Attribute attr = new Attribute(attribute.getString("name"), attribute.getString("value"), attribute.getBoolean("ecert", false)); attrs.add(attr); } } this.attrs = attrs; logger.debug(format("identity url: %s, registrar: %s done.", readIdURL, registrar)); } this.deleted = false; return statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while getting user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), readIdURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while getting user '%s' from url '%s': %s", enrollmentID, readIdURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
java
public int read(User registrar) throws IdentityException, InvalidArgumentException { if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String readIdURL = ""; try { readIdURL = HFCA_IDENTITY + "/" + enrollmentID; logger.debug(format("identity url: %s, registrar: %s", readIdURL, registrar.getName())); JsonObject result = client.httpGet(readIdURL, registrar); statusCode = result.getInt("statusCode"); if (statusCode < 400) { type = result.getString("type"); maxEnrollments = result.getInt("max_enrollments"); affiliation = result.getString("affiliation"); JsonArray attributes = result.getJsonArray("attrs"); Collection<Attribute> attrs = new ArrayList<Attribute>(); if (attributes != null && !attributes.isEmpty()) { for (int i = 0; i < attributes.size(); i++) { JsonObject attribute = attributes.getJsonObject(i); Attribute attr = new Attribute(attribute.getString("name"), attribute.getString("value"), attribute.getBoolean("ecert", false)); attrs.add(attr); } } this.attrs = attrs; logger.debug(format("identity url: %s, registrar: %s done.", readIdURL, registrar)); } this.deleted = false; return statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while getting user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), readIdURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while getting user '%s' from url '%s': %s", enrollmentID, readIdURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
[ "public", "int", "read", "(", "User", "registrar", ")", "throws", "IdentityException", ",", "InvalidArgumentException", "{", "if", "(", "registrar", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Registrar should be a valid member\"", ")", ";", "}", "String", "readIdURL", "=", "\"\"", ";", "try", "{", "readIdURL", "=", "HFCA_IDENTITY", "+", "\"/\"", "+", "enrollmentID", ";", "logger", ".", "debug", "(", "format", "(", "\"identity url: %s, registrar: %s\"", ",", "readIdURL", ",", "registrar", ".", "getName", "(", ")", ")", ")", ";", "JsonObject", "result", "=", "client", ".", "httpGet", "(", "readIdURL", ",", "registrar", ")", ";", "statusCode", "=", "result", ".", "getInt", "(", "\"statusCode\"", ")", ";", "if", "(", "statusCode", "<", "400", ")", "{", "type", "=", "result", ".", "getString", "(", "\"type\"", ")", ";", "maxEnrollments", "=", "result", ".", "getInt", "(", "\"max_enrollments\"", ")", ";", "affiliation", "=", "result", ".", "getString", "(", "\"affiliation\"", ")", ";", "JsonArray", "attributes", "=", "result", ".", "getJsonArray", "(", "\"attrs\"", ")", ";", "Collection", "<", "Attribute", ">", "attrs", "=", "new", "ArrayList", "<", "Attribute", ">", "(", ")", ";", "if", "(", "attributes", "!=", "null", "&&", "!", "attributes", ".", "isEmpty", "(", ")", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "attributes", ".", "size", "(", ")", ";", "i", "++", ")", "{", "JsonObject", "attribute", "=", "attributes", ".", "getJsonObject", "(", "i", ")", ";", "Attribute", "attr", "=", "new", "Attribute", "(", "attribute", ".", "getString", "(", "\"name\"", ")", ",", "attribute", ".", "getString", "(", "\"value\"", ")", ",", "attribute", ".", "getBoolean", "(", "\"ecert\"", ",", "false", ")", ")", ";", "attrs", ".", "add", "(", "attr", ")", ";", "}", "}", "this", ".", "attrs", "=", "attrs", ";", "logger", ".", "debug", "(", "format", "(", "\"identity url: %s, registrar: %s done.\"", ",", "readIdURL", ",", "registrar", ")", ")", ";", "}", "this", ".", "deleted", "=", "false", ";", "return", "statusCode", ";", "}", "catch", "(", "HTTPException", "e", ")", "{", "String", "msg", "=", "format", "(", "\"[Code: %d] - Error while getting user '%s' from url '%s': %s\"", ",", "e", ".", "getStatusCode", "(", ")", ",", "getEnrollmentId", "(", ")", ",", "readIdURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "IdentityException", "identityException", "=", "new", "IdentityException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "identityException", ";", "}", "catch", "(", "Exception", "e", ")", "{", "String", "msg", "=", "format", "(", "\"Error while getting user '%s' from url '%s': %s\"", ",", "enrollmentID", ",", "readIdURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "IdentityException", "identityException", "=", "new", "IdentityException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "identityException", ";", "}", "}" ]
read retrieves a specific identity @param registrar The identity of the registrar (i.e. who is performing the registration). @return statusCode The HTTP status code in the response @throws IdentityException if retrieving an identity fails. @throws InvalidArgumentException Invalid (null) argument specified
[ "read", "retrieves", "a", "specific", "identity" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAIdentity.java#L198-L243
22,091
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAIdentity.java
HFCAIdentity.create
public int create(User registrar) throws IdentityException, InvalidArgumentException { if (this.deleted) { throw new IdentityException("Identity has been deleted"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String createURL = ""; try { createURL = client.getURL(HFCA_IDENTITY); logger.debug(format("identity url: %s, registrar: %s", createURL, registrar.getName())); String body = client.toJson(idToJsonObject()); JsonObject result = client.httpPost(createURL, body, registrar); statusCode = result.getInt("statusCode"); if (statusCode < 400) { getHFCAIdentity(result); logger.debug(format("identity url: %s, registrar: %s done.", createURL, registrar)); } this.deleted = false; return statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while creating user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), createURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while creating user '%s' from url '%s': %s", getEnrollmentId(), createURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
java
public int create(User registrar) throws IdentityException, InvalidArgumentException { if (this.deleted) { throw new IdentityException("Identity has been deleted"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String createURL = ""; try { createURL = client.getURL(HFCA_IDENTITY); logger.debug(format("identity url: %s, registrar: %s", createURL, registrar.getName())); String body = client.toJson(idToJsonObject()); JsonObject result = client.httpPost(createURL, body, registrar); statusCode = result.getInt("statusCode"); if (statusCode < 400) { getHFCAIdentity(result); logger.debug(format("identity url: %s, registrar: %s done.", createURL, registrar)); } this.deleted = false; return statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while creating user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), createURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while creating user '%s' from url '%s': %s", getEnrollmentId(), createURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
[ "public", "int", "create", "(", "User", "registrar", ")", "throws", "IdentityException", ",", "InvalidArgumentException", "{", "if", "(", "this", ".", "deleted", ")", "{", "throw", "new", "IdentityException", "(", "\"Identity has been deleted\"", ")", ";", "}", "if", "(", "registrar", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Registrar should be a valid member\"", ")", ";", "}", "String", "createURL", "=", "\"\"", ";", "try", "{", "createURL", "=", "client", ".", "getURL", "(", "HFCA_IDENTITY", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"identity url: %s, registrar: %s\"", ",", "createURL", ",", "registrar", ".", "getName", "(", ")", ")", ")", ";", "String", "body", "=", "client", ".", "toJson", "(", "idToJsonObject", "(", ")", ")", ";", "JsonObject", "result", "=", "client", ".", "httpPost", "(", "createURL", ",", "body", ",", "registrar", ")", ";", "statusCode", "=", "result", ".", "getInt", "(", "\"statusCode\"", ")", ";", "if", "(", "statusCode", "<", "400", ")", "{", "getHFCAIdentity", "(", "result", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"identity url: %s, registrar: %s done.\"", ",", "createURL", ",", "registrar", ")", ")", ";", "}", "this", ".", "deleted", "=", "false", ";", "return", "statusCode", ";", "}", "catch", "(", "HTTPException", "e", ")", "{", "String", "msg", "=", "format", "(", "\"[Code: %d] - Error while creating user '%s' from url '%s': %s\"", ",", "e", ".", "getStatusCode", "(", ")", ",", "getEnrollmentId", "(", ")", ",", "createURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "IdentityException", "identityException", "=", "new", "IdentityException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "identityException", ";", "}", "catch", "(", "Exception", "e", ")", "{", "String", "msg", "=", "format", "(", "\"Error while creating user '%s' from url '%s': %s\"", ",", "getEnrollmentId", "(", ")", ",", "createURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "IdentityException", "identityException", "=", "new", "IdentityException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "identityException", ";", "}", "}" ]
create an identity @param registrar The identity of the registrar (i.e. who is performing the registration). @return statusCode The HTTP status code in the response @throws IdentityException if creating an identity fails. @throws InvalidArgumentException Invalid (null) argument specified
[ "create", "an", "identity" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAIdentity.java#L254-L287
22,092
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAIdentity.java
HFCAIdentity.update
public int update(User registrar) throws IdentityException, InvalidArgumentException { if (this.deleted) { throw new IdentityException("Identity has been deleted"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String updateURL = ""; try { updateURL = client.getURL(HFCA_IDENTITY + "/" + getEnrollmentId()); logger.debug(format("identity url: %s, registrar: %s", updateURL, registrar.getName())); String body = client.toJson(idToJsonObject(filtredUpdateAttrNames)); JsonObject result = client.httpPut(updateURL, body, registrar); statusCode = result.getInt("statusCode"); if (statusCode < 400) { getHFCAIdentity(result); logger.debug(format("identity url: %s, registrar: %s done.", updateURL, registrar)); } return statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while updating user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), updateURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while updating user '%s' from url '%s': %s", getEnrollmentId(), updateURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
java
public int update(User registrar) throws IdentityException, InvalidArgumentException { if (this.deleted) { throw new IdentityException("Identity has been deleted"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String updateURL = ""; try { updateURL = client.getURL(HFCA_IDENTITY + "/" + getEnrollmentId()); logger.debug(format("identity url: %s, registrar: %s", updateURL, registrar.getName())); String body = client.toJson(idToJsonObject(filtredUpdateAttrNames)); JsonObject result = client.httpPut(updateURL, body, registrar); statusCode = result.getInt("statusCode"); if (statusCode < 400) { getHFCAIdentity(result); logger.debug(format("identity url: %s, registrar: %s done.", updateURL, registrar)); } return statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while updating user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), updateURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while updating user '%s' from url '%s': %s", getEnrollmentId(), updateURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
[ "public", "int", "update", "(", "User", "registrar", ")", "throws", "IdentityException", ",", "InvalidArgumentException", "{", "if", "(", "this", ".", "deleted", ")", "{", "throw", "new", "IdentityException", "(", "\"Identity has been deleted\"", ")", ";", "}", "if", "(", "registrar", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Registrar should be a valid member\"", ")", ";", "}", "String", "updateURL", "=", "\"\"", ";", "try", "{", "updateURL", "=", "client", ".", "getURL", "(", "HFCA_IDENTITY", "+", "\"/\"", "+", "getEnrollmentId", "(", ")", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"identity url: %s, registrar: %s\"", ",", "updateURL", ",", "registrar", ".", "getName", "(", ")", ")", ")", ";", "String", "body", "=", "client", ".", "toJson", "(", "idToJsonObject", "(", "filtredUpdateAttrNames", ")", ")", ";", "JsonObject", "result", "=", "client", ".", "httpPut", "(", "updateURL", ",", "body", ",", "registrar", ")", ";", "statusCode", "=", "result", ".", "getInt", "(", "\"statusCode\"", ")", ";", "if", "(", "statusCode", "<", "400", ")", "{", "getHFCAIdentity", "(", "result", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"identity url: %s, registrar: %s done.\"", ",", "updateURL", ",", "registrar", ")", ")", ";", "}", "return", "statusCode", ";", "}", "catch", "(", "HTTPException", "e", ")", "{", "String", "msg", "=", "format", "(", "\"[Code: %d] - Error while updating user '%s' from url '%s': %s\"", ",", "e", ".", "getStatusCode", "(", ")", ",", "getEnrollmentId", "(", ")", ",", "updateURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "IdentityException", "identityException", "=", "new", "IdentityException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "identityException", ";", "}", "catch", "(", "Exception", "e", ")", "{", "String", "msg", "=", "format", "(", "\"Error while updating user '%s' from url '%s': %s\"", ",", "getEnrollmentId", "(", ")", ",", "updateURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "IdentityException", "identityException", "=", "new", "IdentityException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "identityException", ";", "}", "}" ]
update an identity @param registrar The identity of the registrar (i.e. who is performing the registration). @return statusCode The HTTP status code in the response @throws IdentityException if adding an identity fails. @throws InvalidArgumentException Invalid (null) argument specified
[ "update", "an", "identity" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAIdentity.java#L298-L331
22,093
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric_ca/sdk/HFCAIdentity.java
HFCAIdentity.delete
public int delete(User registrar) throws IdentityException, InvalidArgumentException { if (this.deleted) { throw new IdentityException("Identity has been deleted"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String deleteURL = ""; try { deleteURL = client.getURL(HFCA_IDENTITY + "/" + getEnrollmentId()); logger.debug(format("identity url: %s, registrar: %s", deleteURL, registrar.getName())); JsonObject result = client.httpDelete(deleteURL, registrar); statusCode = result.getInt("statusCode"); if (statusCode < 400) { getHFCAIdentity(result); logger.debug(format("identity url: %s, registrar: %s done.", deleteURL, registrar)); } this.deleted = true; return statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while deleting user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), deleteURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while deleting user '%s' from url '%s': %s", getEnrollmentId(), deleteURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
java
public int delete(User registrar) throws IdentityException, InvalidArgumentException { if (this.deleted) { throw new IdentityException("Identity has been deleted"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String deleteURL = ""; try { deleteURL = client.getURL(HFCA_IDENTITY + "/" + getEnrollmentId()); logger.debug(format("identity url: %s, registrar: %s", deleteURL, registrar.getName())); JsonObject result = client.httpDelete(deleteURL, registrar); statusCode = result.getInt("statusCode"); if (statusCode < 400) { getHFCAIdentity(result); logger.debug(format("identity url: %s, registrar: %s done.", deleteURL, registrar)); } this.deleted = true; return statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while deleting user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), deleteURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while deleting user '%s' from url '%s': %s", getEnrollmentId(), deleteURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
[ "public", "int", "delete", "(", "User", "registrar", ")", "throws", "IdentityException", ",", "InvalidArgumentException", "{", "if", "(", "this", ".", "deleted", ")", "{", "throw", "new", "IdentityException", "(", "\"Identity has been deleted\"", ")", ";", "}", "if", "(", "registrar", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Registrar should be a valid member\"", ")", ";", "}", "String", "deleteURL", "=", "\"\"", ";", "try", "{", "deleteURL", "=", "client", ".", "getURL", "(", "HFCA_IDENTITY", "+", "\"/\"", "+", "getEnrollmentId", "(", ")", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"identity url: %s, registrar: %s\"", ",", "deleteURL", ",", "registrar", ".", "getName", "(", ")", ")", ")", ";", "JsonObject", "result", "=", "client", ".", "httpDelete", "(", "deleteURL", ",", "registrar", ")", ";", "statusCode", "=", "result", ".", "getInt", "(", "\"statusCode\"", ")", ";", "if", "(", "statusCode", "<", "400", ")", "{", "getHFCAIdentity", "(", "result", ")", ";", "logger", ".", "debug", "(", "format", "(", "\"identity url: %s, registrar: %s done.\"", ",", "deleteURL", ",", "registrar", ")", ")", ";", "}", "this", ".", "deleted", "=", "true", ";", "return", "statusCode", ";", "}", "catch", "(", "HTTPException", "e", ")", "{", "String", "msg", "=", "format", "(", "\"[Code: %d] - Error while deleting user '%s' from url '%s': %s\"", ",", "e", ".", "getStatusCode", "(", ")", ",", "getEnrollmentId", "(", ")", ",", "deleteURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "IdentityException", "identityException", "=", "new", "IdentityException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "identityException", ";", "}", "catch", "(", "Exception", "e", ")", "{", "String", "msg", "=", "format", "(", "\"Error while deleting user '%s' from url '%s': %s\"", ",", "getEnrollmentId", "(", ")", ",", "deleteURL", ",", "e", ".", "getMessage", "(", ")", ")", ";", "IdentityException", "identityException", "=", "new", "IdentityException", "(", "msg", ",", "e", ")", ";", "logger", ".", "error", "(", "msg", ")", ";", "throw", "identityException", ";", "}", "}" ]
delete an identity @param registrar The identity of the registrar (i.e. who is performing the registration). @return statusCode The HTTP status code in the response @throws IdentityException if adding an identity fails. @throws InvalidArgumentException Invalid (null) argument specified
[ "delete", "an", "identity" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAIdentity.java#L342-L375
22,094
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java
Utils.generateDirectoryHash
public static String generateDirectoryHash(String rootDir, String chaincodeDir, String hash) throws IOException { // Generate the project directory Path projectPath = null; if (rootDir == null) { projectPath = Paths.get(chaincodeDir); } else { projectPath = Paths.get(rootDir, chaincodeDir); } File dir = projectPath.toFile(); if (!dir.exists() || !dir.isDirectory()) { throw new IOException(format("The chaincode path \"%s\" is invalid", projectPath)); } StringBuilder hashBuilder = new StringBuilder(hash); Files.walk(projectPath) .sorted(Comparator.naturalOrder()) .filter(Files::isRegularFile) .map(Path::toFile) .forEach(file -> { try { byte[] buf = readFile(file); byte[] toHash = Arrays.concatenate(buf, hashBuilder.toString().getBytes(UTF_8)); hashBuilder.setLength(0); hashBuilder.append(Hex.toHexString(hash(toHash, new SHA3Digest()))); } catch (IOException ex) { throw new RuntimeException(format("Error while reading file %s", file.getAbsolutePath()), ex); } }); // If original hash and final hash are the same, it indicates that no new contents were found if (hashBuilder.toString().equals(hash)) { throw new IOException(format("The chaincode directory \"%s\" has no files", projectPath)); } return hashBuilder.toString(); }
java
public static String generateDirectoryHash(String rootDir, String chaincodeDir, String hash) throws IOException { // Generate the project directory Path projectPath = null; if (rootDir == null) { projectPath = Paths.get(chaincodeDir); } else { projectPath = Paths.get(rootDir, chaincodeDir); } File dir = projectPath.toFile(); if (!dir.exists() || !dir.isDirectory()) { throw new IOException(format("The chaincode path \"%s\" is invalid", projectPath)); } StringBuilder hashBuilder = new StringBuilder(hash); Files.walk(projectPath) .sorted(Comparator.naturalOrder()) .filter(Files::isRegularFile) .map(Path::toFile) .forEach(file -> { try { byte[] buf = readFile(file); byte[] toHash = Arrays.concatenate(buf, hashBuilder.toString().getBytes(UTF_8)); hashBuilder.setLength(0); hashBuilder.append(Hex.toHexString(hash(toHash, new SHA3Digest()))); } catch (IOException ex) { throw new RuntimeException(format("Error while reading file %s", file.getAbsolutePath()), ex); } }); // If original hash and final hash are the same, it indicates that no new contents were found if (hashBuilder.toString().equals(hash)) { throw new IOException(format("The chaincode directory \"%s\" has no files", projectPath)); } return hashBuilder.toString(); }
[ "public", "static", "String", "generateDirectoryHash", "(", "String", "rootDir", ",", "String", "chaincodeDir", ",", "String", "hash", ")", "throws", "IOException", "{", "// Generate the project directory", "Path", "projectPath", "=", "null", ";", "if", "(", "rootDir", "==", "null", ")", "{", "projectPath", "=", "Paths", ".", "get", "(", "chaincodeDir", ")", ";", "}", "else", "{", "projectPath", "=", "Paths", ".", "get", "(", "rootDir", ",", "chaincodeDir", ")", ";", "}", "File", "dir", "=", "projectPath", ".", "toFile", "(", ")", ";", "if", "(", "!", "dir", ".", "exists", "(", ")", "||", "!", "dir", ".", "isDirectory", "(", ")", ")", "{", "throw", "new", "IOException", "(", "format", "(", "\"The chaincode path \\\"%s\\\" is invalid\"", ",", "projectPath", ")", ")", ";", "}", "StringBuilder", "hashBuilder", "=", "new", "StringBuilder", "(", "hash", ")", ";", "Files", ".", "walk", "(", "projectPath", ")", ".", "sorted", "(", "Comparator", ".", "naturalOrder", "(", ")", ")", ".", "filter", "(", "Files", "::", "isRegularFile", ")", ".", "map", "(", "Path", "::", "toFile", ")", ".", "forEach", "(", "file", "->", "{", "try", "{", "byte", "[", "]", "buf", "=", "readFile", "(", "file", ")", ";", "byte", "[", "]", "toHash", "=", "Arrays", ".", "concatenate", "(", "buf", ",", "hashBuilder", ".", "toString", "(", ")", ".", "getBytes", "(", "UTF_8", ")", ")", ";", "hashBuilder", ".", "setLength", "(", "0", ")", ";", "hashBuilder", ".", "append", "(", "Hex", ".", "toHexString", "(", "hash", "(", "toHash", ",", "new", "SHA3Digest", "(", ")", ")", ")", ")", ";", "}", "catch", "(", "IOException", "ex", ")", "{", "throw", "new", "RuntimeException", "(", "format", "(", "\"Error while reading file %s\"", ",", "file", ".", "getAbsolutePath", "(", ")", ")", ",", "ex", ")", ";", "}", "}", ")", ";", "// If original hash and final hash are the same, it indicates that no new contents were found", "if", "(", "hashBuilder", ".", "toString", "(", ")", ".", "equals", "(", "hash", ")", ")", "{", "throw", "new", "IOException", "(", "format", "(", "\"The chaincode directory \\\"%s\\\" has no files\"", ",", "projectPath", ")", ")", ";", "}", "return", "hashBuilder", ".", "toString", "(", ")", ";", "}" ]
Generate hash of a chaincode directory @param rootDir Root directory @param chaincodeDir Channel code directory @param hash Previous hash (if any) @return hash of the directory @throws IOException
[ "Generate", "hash", "of", "a", "chaincode", "directory" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java#L95-L130
22,095
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java
Utils.generateTarGz
public static byte[] generateTarGz(File sourceDirectory, String pathPrefix, File chaincodeMetaInf) throws IOException { logger.trace(format("generateTarGz: sourceDirectory: %s, pathPrefix: %s, chaincodeMetaInf: %s", sourceDirectory == null ? "null" : sourceDirectory.getAbsolutePath(), pathPrefix, chaincodeMetaInf == null ? "null" : chaincodeMetaInf.getAbsolutePath())); ByteArrayOutputStream bos = new ByteArrayOutputStream(500000); String sourcePath = sourceDirectory.getAbsolutePath(); TarArchiveOutputStream archiveOutputStream = new TarArchiveOutputStream(new GzipCompressorOutputStream(bos)); archiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); try { Collection<File> childrenFiles = org.apache.commons.io.FileUtils.listFiles(sourceDirectory, null, true); ArchiveEntry archiveEntry; FileInputStream fileInputStream; for (File childFile : childrenFiles) { String childPath = childFile.getAbsolutePath(); String relativePath = childPath.substring((sourcePath.length() + 1), childPath.length()); if (pathPrefix != null) { relativePath = Utils.combinePaths(pathPrefix, relativePath); } relativePath = FilenameUtils.separatorsToUnix(relativePath); if (TRACE_ENABED) { logger.trace(format("generateTarGz: Adding '%s' entry from source '%s' to archive.", relativePath, childFile.getAbsolutePath())); } archiveEntry = new TarArchiveEntry(childFile, relativePath); fileInputStream = new FileInputStream(childFile); archiveOutputStream.putArchiveEntry(archiveEntry); try { IOUtils.copy(fileInputStream, archiveOutputStream); } finally { IOUtils.closeQuietly(fileInputStream); archiveOutputStream.closeArchiveEntry(); } } if (null != chaincodeMetaInf) { childrenFiles = org.apache.commons.io.FileUtils.listFiles(chaincodeMetaInf, null, true); final URI metabase = chaincodeMetaInf.toURI(); for (File childFile : childrenFiles) { final String relativePath = Paths.get("META-INF", metabase.relativize(childFile.toURI()).getPath()).toString(); if (TRACE_ENABED) { logger.trace(format("generateTarGz: Adding '%s' entry from source '%s' to archive.", relativePath, childFile.getAbsolutePath())); } archiveEntry = new TarArchiveEntry(childFile, relativePath); fileInputStream = new FileInputStream(childFile); archiveOutputStream.putArchiveEntry(archiveEntry); try { IOUtils.copy(fileInputStream, archiveOutputStream); } finally { IOUtils.closeQuietly(fileInputStream); archiveOutputStream.closeArchiveEntry(); } } } } finally { IOUtils.closeQuietly(archiveOutputStream); } return bos.toByteArray(); }
java
public static byte[] generateTarGz(File sourceDirectory, String pathPrefix, File chaincodeMetaInf) throws IOException { logger.trace(format("generateTarGz: sourceDirectory: %s, pathPrefix: %s, chaincodeMetaInf: %s", sourceDirectory == null ? "null" : sourceDirectory.getAbsolutePath(), pathPrefix, chaincodeMetaInf == null ? "null" : chaincodeMetaInf.getAbsolutePath())); ByteArrayOutputStream bos = new ByteArrayOutputStream(500000); String sourcePath = sourceDirectory.getAbsolutePath(); TarArchiveOutputStream archiveOutputStream = new TarArchiveOutputStream(new GzipCompressorOutputStream(bos)); archiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); try { Collection<File> childrenFiles = org.apache.commons.io.FileUtils.listFiles(sourceDirectory, null, true); ArchiveEntry archiveEntry; FileInputStream fileInputStream; for (File childFile : childrenFiles) { String childPath = childFile.getAbsolutePath(); String relativePath = childPath.substring((sourcePath.length() + 1), childPath.length()); if (pathPrefix != null) { relativePath = Utils.combinePaths(pathPrefix, relativePath); } relativePath = FilenameUtils.separatorsToUnix(relativePath); if (TRACE_ENABED) { logger.trace(format("generateTarGz: Adding '%s' entry from source '%s' to archive.", relativePath, childFile.getAbsolutePath())); } archiveEntry = new TarArchiveEntry(childFile, relativePath); fileInputStream = new FileInputStream(childFile); archiveOutputStream.putArchiveEntry(archiveEntry); try { IOUtils.copy(fileInputStream, archiveOutputStream); } finally { IOUtils.closeQuietly(fileInputStream); archiveOutputStream.closeArchiveEntry(); } } if (null != chaincodeMetaInf) { childrenFiles = org.apache.commons.io.FileUtils.listFiles(chaincodeMetaInf, null, true); final URI metabase = chaincodeMetaInf.toURI(); for (File childFile : childrenFiles) { final String relativePath = Paths.get("META-INF", metabase.relativize(childFile.toURI()).getPath()).toString(); if (TRACE_ENABED) { logger.trace(format("generateTarGz: Adding '%s' entry from source '%s' to archive.", relativePath, childFile.getAbsolutePath())); } archiveEntry = new TarArchiveEntry(childFile, relativePath); fileInputStream = new FileInputStream(childFile); archiveOutputStream.putArchiveEntry(archiveEntry); try { IOUtils.copy(fileInputStream, archiveOutputStream); } finally { IOUtils.closeQuietly(fileInputStream); archiveOutputStream.closeArchiveEntry(); } } } } finally { IOUtils.closeQuietly(archiveOutputStream); } return bos.toByteArray(); }
[ "public", "static", "byte", "[", "]", "generateTarGz", "(", "File", "sourceDirectory", ",", "String", "pathPrefix", ",", "File", "chaincodeMetaInf", ")", "throws", "IOException", "{", "logger", ".", "trace", "(", "format", "(", "\"generateTarGz: sourceDirectory: %s, pathPrefix: %s, chaincodeMetaInf: %s\"", ",", "sourceDirectory", "==", "null", "?", "\"null\"", ":", "sourceDirectory", ".", "getAbsolutePath", "(", ")", ",", "pathPrefix", ",", "chaincodeMetaInf", "==", "null", "?", "\"null\"", ":", "chaincodeMetaInf", ".", "getAbsolutePath", "(", ")", ")", ")", ";", "ByteArrayOutputStream", "bos", "=", "new", "ByteArrayOutputStream", "(", "500000", ")", ";", "String", "sourcePath", "=", "sourceDirectory", ".", "getAbsolutePath", "(", ")", ";", "TarArchiveOutputStream", "archiveOutputStream", "=", "new", "TarArchiveOutputStream", "(", "new", "GzipCompressorOutputStream", "(", "bos", ")", ")", ";", "archiveOutputStream", ".", "setLongFileMode", "(", "TarArchiveOutputStream", ".", "LONGFILE_GNU", ")", ";", "try", "{", "Collection", "<", "File", ">", "childrenFiles", "=", "org", ".", "apache", ".", "commons", ".", "io", ".", "FileUtils", ".", "listFiles", "(", "sourceDirectory", ",", "null", ",", "true", ")", ";", "ArchiveEntry", "archiveEntry", ";", "FileInputStream", "fileInputStream", ";", "for", "(", "File", "childFile", ":", "childrenFiles", ")", "{", "String", "childPath", "=", "childFile", ".", "getAbsolutePath", "(", ")", ";", "String", "relativePath", "=", "childPath", ".", "substring", "(", "(", "sourcePath", ".", "length", "(", ")", "+", "1", ")", ",", "childPath", ".", "length", "(", ")", ")", ";", "if", "(", "pathPrefix", "!=", "null", ")", "{", "relativePath", "=", "Utils", ".", "combinePaths", "(", "pathPrefix", ",", "relativePath", ")", ";", "}", "relativePath", "=", "FilenameUtils", ".", "separatorsToUnix", "(", "relativePath", ")", ";", "if", "(", "TRACE_ENABED", ")", "{", "logger", ".", "trace", "(", "format", "(", "\"generateTarGz: Adding '%s' entry from source '%s' to archive.\"", ",", "relativePath", ",", "childFile", ".", "getAbsolutePath", "(", ")", ")", ")", ";", "}", "archiveEntry", "=", "new", "TarArchiveEntry", "(", "childFile", ",", "relativePath", ")", ";", "fileInputStream", "=", "new", "FileInputStream", "(", "childFile", ")", ";", "archiveOutputStream", ".", "putArchiveEntry", "(", "archiveEntry", ")", ";", "try", "{", "IOUtils", ".", "copy", "(", "fileInputStream", ",", "archiveOutputStream", ")", ";", "}", "finally", "{", "IOUtils", ".", "closeQuietly", "(", "fileInputStream", ")", ";", "archiveOutputStream", ".", "closeArchiveEntry", "(", ")", ";", "}", "}", "if", "(", "null", "!=", "chaincodeMetaInf", ")", "{", "childrenFiles", "=", "org", ".", "apache", ".", "commons", ".", "io", ".", "FileUtils", ".", "listFiles", "(", "chaincodeMetaInf", ",", "null", ",", "true", ")", ";", "final", "URI", "metabase", "=", "chaincodeMetaInf", ".", "toURI", "(", ")", ";", "for", "(", "File", "childFile", ":", "childrenFiles", ")", "{", "final", "String", "relativePath", "=", "Paths", ".", "get", "(", "\"META-INF\"", ",", "metabase", ".", "relativize", "(", "childFile", ".", "toURI", "(", ")", ")", ".", "getPath", "(", ")", ")", ".", "toString", "(", ")", ";", "if", "(", "TRACE_ENABED", ")", "{", "logger", ".", "trace", "(", "format", "(", "\"generateTarGz: Adding '%s' entry from source '%s' to archive.\"", ",", "relativePath", ",", "childFile", ".", "getAbsolutePath", "(", ")", ")", ")", ";", "}", "archiveEntry", "=", "new", "TarArchiveEntry", "(", "childFile", ",", "relativePath", ")", ";", "fileInputStream", "=", "new", "FileInputStream", "(", "childFile", ")", ";", "archiveOutputStream", ".", "putArchiveEntry", "(", "archiveEntry", ")", ";", "try", "{", "IOUtils", ".", "copy", "(", "fileInputStream", ",", "archiveOutputStream", ")", ";", "}", "finally", "{", "IOUtils", ".", "closeQuietly", "(", "fileInputStream", ")", ";", "archiveOutputStream", ".", "closeArchiveEntry", "(", ")", ";", "}", "}", "}", "}", "finally", "{", "IOUtils", ".", "closeQuietly", "(", "archiveOutputStream", ")", ";", "}", "return", "bos", ".", "toByteArray", "(", ")", ";", "}" ]
Compress the contents of given directory using Tar and Gzip to an in-memory byte array. @param sourceDirectory the source directory. @param pathPrefix a path to be prepended to every file name in the .tar.gz output, or {@code null} if no prefix is required. @param chaincodeMetaInf @return the compressed directory contents. @throws IOException
[ "Compress", "the", "contents", "of", "given", "directory", "using", "Tar", "and", "Gzip", "to", "an", "in", "-", "memory", "byte", "array", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java#L141-L217
22,096
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java
Utils.readFile
public static byte[] readFile(File input) throws IOException { return Files.readAllBytes(Paths.get(input.getAbsolutePath())); }
java
public static byte[] readFile(File input) throws IOException { return Files.readAllBytes(Paths.get(input.getAbsolutePath())); }
[ "public", "static", "byte", "[", "]", "readFile", "(", "File", "input", ")", "throws", "IOException", "{", "return", "Files", ".", "readAllBytes", "(", "Paths", ".", "get", "(", "input", ".", "getAbsolutePath", "(", ")", ")", ")", ";", "}" ]
Read the contents a file. @param input source file to read. @return contents of the file. @throws IOException
[ "Read", "the", "contents", "a", "file", "." ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java#L226-L228
22,097
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java
Utils.deleteFileOrDirectory
public static void deleteFileOrDirectory(File file) throws IOException { if (file.exists()) { if (file.isDirectory()) { Path rootPath = Paths.get(file.getAbsolutePath()); Files.walk(rootPath, FileVisitOption.FOLLOW_LINKS) .sorted(Comparator.reverseOrder()) .map(Path::toFile) .forEach(File::delete); } else { file.delete(); } } else { throw new RuntimeException("File or directory does not exist"); } }
java
public static void deleteFileOrDirectory(File file) throws IOException { if (file.exists()) { if (file.isDirectory()) { Path rootPath = Paths.get(file.getAbsolutePath()); Files.walk(rootPath, FileVisitOption.FOLLOW_LINKS) .sorted(Comparator.reverseOrder()) .map(Path::toFile) .forEach(File::delete); } else { file.delete(); } } else { throw new RuntimeException("File or directory does not exist"); } }
[ "public", "static", "void", "deleteFileOrDirectory", "(", "File", "file", ")", "throws", "IOException", "{", "if", "(", "file", ".", "exists", "(", ")", ")", "{", "if", "(", "file", ".", "isDirectory", "(", ")", ")", "{", "Path", "rootPath", "=", "Paths", ".", "get", "(", "file", ".", "getAbsolutePath", "(", ")", ")", ";", "Files", ".", "walk", "(", "rootPath", ",", "FileVisitOption", ".", "FOLLOW_LINKS", ")", ".", "sorted", "(", "Comparator", ".", "reverseOrder", "(", ")", ")", ".", "map", "(", "Path", "::", "toFile", ")", ".", "forEach", "(", "File", "::", "delete", ")", ";", "}", "else", "{", "file", ".", "delete", "(", ")", ";", "}", "}", "else", "{", "throw", "new", "RuntimeException", "(", "\"File or directory does not exist\"", ")", ";", "}", "}" ]
Delete a file or directory @param file {@link File} representing file or directory @throws IOException
[ "Delete", "a", "file", "or", "directory" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java#L256-L271
22,098
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java
Utils.combinePaths
public static String combinePaths(String first, String... other) { return Paths.get(first, other).toString(); }
java
public static String combinePaths(String first, String... other) { return Paths.get(first, other).toString(); }
[ "public", "static", "String", "combinePaths", "(", "String", "first", ",", "String", "...", "other", ")", "{", "return", "Paths", ".", "get", "(", "first", ",", "other", ")", ".", "toString", "(", ")", ";", "}" ]
Combine two or more paths @param first parent directory path @param other children @return combined path
[ "Combine", "two", "or", "more", "paths" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java#L294-L296
22,099
hyperledger/fabric-sdk-java
src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java
Utils.readFileFromClasspath
public static byte[] readFileFromClasspath(String fileName) throws IOException { InputStream is = Utils.class.getClassLoader().getResourceAsStream(fileName); byte[] data = ByteStreams.toByteArray(is); try { is.close(); } catch (IOException ex) { } return data; }
java
public static byte[] readFileFromClasspath(String fileName) throws IOException { InputStream is = Utils.class.getClassLoader().getResourceAsStream(fileName); byte[] data = ByteStreams.toByteArray(is); try { is.close(); } catch (IOException ex) { } return data; }
[ "public", "static", "byte", "[", "]", "readFileFromClasspath", "(", "String", "fileName", ")", "throws", "IOException", "{", "InputStream", "is", "=", "Utils", ".", "class", ".", "getClassLoader", "(", ")", ".", "getResourceAsStream", "(", "fileName", ")", ";", "byte", "[", "]", "data", "=", "ByteStreams", ".", "toByteArray", "(", "is", ")", ";", "try", "{", "is", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "ex", ")", "{", "}", "return", "data", ";", "}" ]
Read a file from classpath @param fileName @return byte[] data @throws IOException
[ "Read", "a", "file", "from", "classpath" ]
4a2d7b3408b8b0a1ed812aa36942c438159c37a0
https://github.com/hyperledger/fabric-sdk-java/blob/4a2d7b3408b8b0a1ed812aa36942c438159c37a0/src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java#L305-L313