Skip to content

Commit

Permalink
flag to configure printing of errors in FileController
Browse files Browse the repository at this point in the history
  • Loading branch information
br-fedaykin committed Aug 27, 2020
1 parent 553c77b commit 141465f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
6 changes: 2 additions & 4 deletions src/main/java/com/brunoarruda/hyperdcpabe/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public String toString() {
private Map<String, Map<String, PublicKey>> publishedAttributes;

public Client() {
fc = FileController.getInstance().configure(DATA_PATH);
fc = FileController.getInstance().configure(DATA_PATH, false);
this.server = new ServerConnection(SERVER_PORT);
ObjectNode clientData = (ObjectNode) fc.loadAsJSON(getClientDirectory(), "clientData.json");
if (clientData != null) {
Expand All @@ -115,7 +115,7 @@ public Client() {
}

public Client(String networkURL, String adminName, String adminEmail, String adminPrivateKey) {
fc = FileController.getInstance().configure(DATA_PATH);
fc = FileController.getInstance().configure(DATA_PATH, false);
this.server = new ServerConnection(SERVER_PORT);
this.blockchain = new BlockchainConnection(networkURL);
gp = DCPABE.globalSetup(160);
Expand Down Expand Up @@ -327,7 +327,6 @@ public void encrypt(String file, String policy, String[] authorities) {
}
AccessStructure as = AccessStructure.buildFromPolicy(policy);
Message m = DCPABE.generateRandomMessage(gp);
System.out.println("MESSAGE 358: " + Arrays.toString(m.getM()));
CiphertextJSON ct = new CiphertextJSON(DCPABE.encrypt(m, as, gp, pks));
String path = fc.getUserDirectory(user);
r = new Recording(path, file, ct);
Expand All @@ -346,7 +345,6 @@ public void decrypt(String file) {
Message m = null;
try {
m = DCPABE.decrypt(r.getCiphertext(), user.getABEKeys(), gp);
System.out.println("MESSAGE 377: " + Arrays.toString(m.getM()));
} catch (IllegalArgumentException e) {
String msg = "Client - Could not decrypt the file %s. Attributes not Satisfying Policy Access.";
System.out.println(String.format(msg, file));
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/com/brunoarruda/hyperdcpabe/io/FileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public final class FileController {
private static final ObjectMapper mapper = new ObjectMapper();

private String dataFolder;
private boolean printErrorsFlag;

private FileController() {
}
Expand All @@ -34,8 +35,9 @@ public static FileController getInstance() {
return INSTANCE;
}

public FileController configure(String path) {
public FileController configure(String path, boolean printErrorsFlag) {
this.dataFolder = path;
this.printErrorsFlag = printErrorsFlag;
File dirFile = new File(path);
if (!dirFile.exists() || !dirFile.isDirectory()) {
dirFile.mkdirs();
Expand Down Expand Up @@ -74,7 +76,9 @@ public <T> void writeToDir(String path, String fileName, T obj) {
try {
mapper.writeValue(new File(path), obj);
} catch (IOException e) {
// e.printStackTrace();
if (printErrorsFlag) {
e.printStackTrace();
}
}
}

Expand All @@ -90,7 +94,9 @@ public <T extends Object> List<T> readAsList(String path, String file, Class<T>
list.add(mapper.readValue(value, classReference));
}
} catch (Exception e) {
e.printStackTrace();
if (printErrorsFlag) {
e.printStackTrace();
}
}
return list;
}
Expand All @@ -113,7 +119,9 @@ public <K extends Object, V extends Object> Map<K, V> readAsMap(String path, Str
map.put((K) entry.getKey(), mapper.readValue(value, valueClass));
}
} catch (Exception e) {
e.printStackTrace();
if (printErrorsFlag) {
e.printStackTrace();
}
}
return map;
}
Expand All @@ -134,9 +142,13 @@ public <T> T readFromDir(String path, String fileName, String internalPath, Clas
}
result = mapper.readValue(mapper.writeValueAsString(data), typeReference);
} catch (JsonProcessingException e) {
e.printStackTrace();
if (printErrorsFlag) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
if (printErrorsFlag) {
e.printStackTrace();
}
}
return result;
}
Expand All @@ -150,7 +162,9 @@ public JsonNode loadAsJSON(String path, String file) {
try {
obj = mapper.readTree(new File(path, file));
} catch (IOException e) {
// System.out.println("FileController - Could not load " + file + " inside " + path + "as a JSON object.");
if (printErrorsFlag) {
e.printStackTrace();
}
}
return obj;
}
Expand Down

0 comments on commit 141465f

Please sign in to comment.