List of usage examples for com.google.gson JsonParser JsonParser
@Deprecated
public JsonParser()
From source file:com.continusec.client.ContinusecClient.java
License:Apache License
/** * Fetch the list of maps held by this account. * @return list of maps// w w w . j av a 2 s . c o m * @throws ContinusecException upon error */ public List<MapInfo> listMaps() throws ContinusecException { ResponseData rd = this.makeRequest("GET", "/maps", null, null); try { JsonObject o = new JsonParser().parse(new String(rd.data, "UTF-8")).getAsJsonObject(); ArrayList<MapInfo> rv = new ArrayList<MapInfo>(); for (JsonElement e : o.getAsJsonArray("results")) { rv.add(new MapInfo(e.getAsJsonObject().getAsJsonPrimitive("name").getAsString())); } return rv; } catch (UnsupportedEncodingException e) { throw new ContinusecException(e); } }
From source file:com.continusec.client.JsonEntry.java
License:Apache License
/** * Calculate the leaf hash for this entry. * This uses the {#link ObjectHash} class to produce the hash that this then uses * as input to the Merkle Tree Leaf./*from w w w .j a v a 2 s .c o m*/ * @return the Merkle Tree leaf hash for this entry. * @throws ContinusecException upon error */ public byte[] getLeafHash() throws ContinusecException { if (this.lh == null) { if (this.rawData.length == 0) { this.lh = Util.leafMerkleTreeHash(this.rawData); } else { try { this.lh = Util.leafMerkleTreeHash(ObjectHash .objectHashWithStdRedaction(new JsonParser().parse(new String(this.rawData, "UTF8")))); } catch (UnsupportedEncodingException e) { throw new InvalidObjectException(e); } } } return this.lh; }
From source file:com.continusec.client.LogEntryIterator.java
License:Apache License
/** * Get the next entry - will read from the server in large batches. * @return the next entry./*from w w w .j a v a 2s . c o m*/ */ public VerifiableEntry next() { try { if ((curArray == null) || (this.idxInArray >= this.curArray.size())) { int tentLast = this.cursor + BATCH; if (tentLast > this.endIdx) { tentLast = this.endIdx; } String url = this.path + "/entries/" + this.cursor + "-" + tentLast + factory.getFormat(); String s = new String(this.client.makeRequest("GET", url, null, null).data, "UTF-8"); this.curArray = new JsonParser().parse(s).getAsJsonObject().getAsJsonArray("entries"); this.idxInArray = 0; } if (this.idxInArray < this.curArray.size()) { byte[] rv = Base64.decodeBase64( this.curArray.get(this.idxInArray).getAsJsonObject().get("leaf_data").getAsString()); this.idxInArray += 1; this.cursor += 1; return factory.createFromBytes(rv); } else { throw new RuntimeException(new NotAllEntriesReturnedException()); } } catch (UnsupportedEncodingException e) { throw new RuntimeException(new InternalErrorException(e)); } catch (ContinusecException e) { throw new RuntimeException(e); } }
From source file:com.continusec.client.RedactedJsonEntry.java
License:Apache License
/** * Get the underlying JSON for this entry, with all Redactable nonce-tuples and * redacted sub-objects stripped for ease of processing. See {@link ObjectHash#shedRedactableWithStdRedaction(JsonElement)}. * @return the JSON with with Redactable artefacts shed. * @throws ContinusecException upon error *//*from www .j av a 2s.c o m*/ public byte[] getData() throws ContinusecException { if (this.shedData == null) { try { this.shedData = ObjectHash .shedRedactableWithStdRedaction(new JsonParser().parse(new String(this.rawData, "UTF8"))) .toString().getBytes("UTF8"); } catch (UnsupportedEncodingException e) { throw new InvalidObjectException(e); } } return this.shedData; }
From source file:com.continusec.client.VerifiableLog.java
License:Apache License
/** * Send API call to add an entry to the log. Note the entry is added asynchronously, so while * the library will return as soon as the server acknowledges receipt of entry, it may not be * reflected in the tree hash (or inclusion proofs) until the server has sequenced the entry. * * @param e the entry to add, often {@link RawDataEntry}, {@link JsonEntry} or {@link RedactableJsonEntry}. * @return add entry response, which includes the Merkle Tree Leaf hash of the entry added. * @throws ContinusecException upon error *//*ww w . j av a2 s . c o m*/ public AddEntryResponse add(UploadableEntry e) throws ContinusecException { try { JsonObject j = new JsonParser().parse(new String(this.client.makeRequest("POST", this.path + "/entry" + e.getFormat(), e.getDataForUpload(), null).data, "UTF-8")) .getAsJsonObject(); return new AddEntryResponse(Base64.decodeBase64(j.get("leaf_hash").getAsString())); } catch (UnsupportedEncodingException e1) { throw new ContinusecException(e1); } }
From source file:com.continusec.client.VerifiableLog.java
License:Apache License
/** * Get the tree hash for given tree size. * * @param treeSize the tree size to retrieve the hash for. Pass {@link ContinusecClient#HEAD} to get the * latest tree size./*w w w .j ava 2 s.c o m*/ * @return the tree hash for the given size (includes the tree size actually used, if unknown before running the query). * @throws ContinusecException upon error */ public LogTreeHead getTreeHead(int treeSize) throws ContinusecException { try { JsonObject e = new JsonParser().parse(new String( this.client.makeRequest("GET", this.path + "/tree/" + treeSize, null, null).data, "UTF-8")) .getAsJsonObject(); return LogTreeHead.fromJsonObject(e); } catch (UnsupportedEncodingException e) { throw new ContinusecException(e); } }
From source file:com.continusec.client.VerifiableLog.java
License:Apache License
/** * Get an inclusion proof for a given item for a specific tree size. Most clients will commonly use {@link #verifyInclusion(LogTreeHead,MerkleTreeLeaf)} instead. * @param treeSize the tree size for which the inclusion proof should be returned. This is usually as returned by {@link #getTreeHead(int)}.getTreeSize(). * @param leaf the entry for which the inclusion proof should be returned. Note that {@link AddEntryResponse} and {@link VerifiableEntry} both implement {@link MerkleTreeLeaf}. * @return a log inclusion proof object that can be verified against a given tree hash. * @throws ContinusecException upon error *//*from w w w . j a va2 s. c om*/ public LogInclusionProof getInclusionProof(int treeSize, MerkleTreeLeaf leaf) throws ContinusecException { try { byte[] mtlHash = leaf.getLeafHash(); JsonObject e = new JsonParser() .parse(new String( this.client.makeRequest("GET", this.path + "/tree/" + treeSize + "/inclusion/h/" + Hex.encodeHexString(mtlHash), null, null).data, "UTF-8")) .getAsJsonObject(); return new LogInclusionProof(e.getAsJsonPrimitive("tree_size").getAsInt(), mtlHash, e.get("leaf_index").getAsInt(), jsonArrayToAuditProof(e.getAsJsonArray("proof"))); } catch (UnsupportedEncodingException e) { throw new ContinusecException(e); } }
From source file:com.continusec.client.VerifiableLog.java
License:Apache License
/** * Get an inclusion proof for a specified tree size and leaf index. This is not used by typical clients, * however it can be useful for audit operations and debugging tools. Typical clients will use {@link #verifyInclusion(LogTreeHead,MerkleTreeLeaf)}. * @param treeSize the tree size on which to base the proof. * @param leafIndex the leaf index for which to retrieve the inclusion proof. * @return a partially filled in LogInclusionProof (note it will not include the MerkleTreeLeaf hash for the item). * @throws ContinusecException upon error */// w w w. j av a 2 s . com public LogInclusionProof getInclusionProofByIndex(int treeSize, int leafIndex) throws ContinusecException { try { JsonObject e = new JsonParser() .parse(new String( this.client.makeRequest("GET", this.path + "/tree/" + treeSize + "/inclusion/" + leafIndex, null, null).data, "UTF-8")) .getAsJsonObject(); return new LogInclusionProof(e.getAsJsonPrimitive("tree_size").getAsInt(), null, e.get("leaf_index").getAsInt(), jsonArrayToAuditProof(e.getAsJsonArray("proof"))); } catch (UnsupportedEncodingException e) { throw new ContinusecException(e); } }
From source file:com.continusec.client.VerifiableLog.java
License:Apache License
/** * ConsistencyProof returns an audit path which contains the set of Merkle Subtree hashes * that demonstrate how the root hash is calculated for both the first and second tree sizes. * @param firstSize the size of the first tree. * @param secondSize the size of the second tree. * @return a log consistency proof object that must be verified. * @throws ContinusecException upon error */// w w w. jav a 2s .c o m public LogConsistencyProof getConsistencyProof(int firstSize, int secondSize) throws ContinusecException { try { JsonObject e = new JsonParser().parse(new String(this.client.makeRequest("GET", this.path + "/tree/" + secondSize + "/consistency/" + firstSize, null, null).data, "UTF-8")) .getAsJsonObject(); return new LogConsistencyProof(e.getAsJsonPrimitive("first_tree_size").getAsInt(), e.getAsJsonPrimitive("second_tree_size").getAsInt(), jsonArrayToAuditProof(e.getAsJsonArray("proof"))); } catch (UnsupportedEncodingException e) { throw new ContinusecException(e); } }
From source file:com.continusec.client.VerifiableMap.java
License:Apache License
/** * Set the value for a given key in the map. Calling this has the effect of adding a mutation to the * mutation log for the map, which then reflects in the root hash for the map. This occurs asynchronously. * @param key the key to set./*from www. j a v a 2 s . c om*/ * @param e the entry to set to key to. Typically one of {@link RawDataEntry}, {@link JsonEntry} or {@link RedactableJsonEntry}. * @return add entry response, which includes the Merkle Tree Leaf hash of the mutation log entry added. * @throws ContinusecException upon error */ public AddEntryResponse set(byte[] key, UploadableEntry e) throws ContinusecException { try { JsonObject j = new JsonParser().parse(new String( this.client.makeRequest("PUT", this.path + "/key/h/" + Hex.encodeHexString(key) + e.getFormat(), e.getDataForUpload(), null).data, "UTF-8")).getAsJsonObject(); return new AddEntryResponse(Base64.decodeBase64(j.get("leaf_hash").getAsString())); } catch (UnsupportedEncodingException e1) { throw new ContinusecException(e1); } }