Page MenuHomec4science

ReplyMaterial.java
No OneTemporary

File Metadata

Created
Tue, Mar 11, 17:41

ReplyMaterial.java

package framework.reply;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONException;
import org.json.JSONObject;
import crypto.elgamal.ECElGamal;
import crypto.elgamal.fragment.FragmentEncoded;
import crypto.elgamal.fragment.FragmentEncrypted;
import framework.Marker;
import framework.MarkerEncrypted;
import framework.Type;
import framework.request.Request;
public class ReplyMaterial {
private static final Logger LOGGER = Logger.getLogger(ReplyMaterial.class.getName());
private HashMap<MarkerEncrypted, FragmentEncoded> encodedMarkers;
private HashMap<MarkerEncrypted, FragmentEncoded> encodedCFs;
private ArrayList<LinkedList<FragmentEncoded>> encodedHLAs;
public ReplyMaterial(
HashMap<MarkerEncrypted, FragmentEncoded> encodedMarkers,
HashMap<MarkerEncrypted, FragmentEncoded> encodedCFs,
ArrayList<LinkedList<FragmentEncoded>> encodedHLAs) {
this.encodedMarkers = encodedMarkers;
this.encodedCFs = encodedCFs;
this.encodedHLAs = encodedHLAs;
}
public HashMap<MarkerEncrypted, FragmentEncoded> getEncodedMarkers() {
return encodedMarkers;
}
public HashMap<MarkerEncrypted, FragmentEncoded> getEncodedCFs() {
return encodedCFs;
}
public ArrayList<LinkedList<FragmentEncoded>> getEncodedHLAs() {
return encodedHLAs;
}
public static ReplyMaterial getReplyMaterial(JSONObject jsonReplyMaterial) {
try {
ReplyMaterial replyMaterial = (ReplyMaterial) jsonReplyMaterial.get(Request.JSON_KEY_REP);
return replyMaterial;
} catch (JSONException e) {
LOGGER.log(Level.SEVERE, "Could not find Reply component", e);
return null;
}
}
public HashMap<Marker, FragmentEncrypted> getEncryptedMarkers(
ECElGamal cryptoEng) {
HashMap<Marker, FragmentEncrypted> result = new HashMap<>();
for (MarkerEncrypted markerEnc : encodedMarkers.keySet()) {
FragmentEncoded fragEncoded = encodedMarkers.get(markerEnc);
FragmentEncrypted fragEncrypted = fragEncoded.decodeFragment(cryptoEng);
Marker marker = new Marker(markerEnc.getMarker());
result.put(marker, fragEncrypted);
}
return result;
}
public HashMap<Integer, FragmentEncrypted> getEncryptedCFs(
ECElGamal cryptoEng) {
HashMap<Integer, FragmentEncrypted> result = new HashMap<>();
for (MarkerEncrypted markerEnc : encodedCFs.keySet()) {
FragmentEncoded fragEncoded = encodedCFs.get(markerEnc);
FragmentEncrypted fragEncrypted = fragEncoded.decodeFragment(cryptoEng);
Integer marker = Integer.valueOf(markerEnc.toString());
result.put(marker, fragEncrypted);
}
return result;
}
public JSONObject getJSONReply() throws JSONException {
JSONObject jsonReplyMaterial = new JSONObject();
jsonReplyMaterial.put(Request.JSON_KEY_TYPE, Type.MATERIAL);
jsonReplyMaterial.put(Request.JSON_KEY_REP, this);
return jsonReplyMaterial;
}
}

Event Timeline