Skip to content

Commit

Permalink
use sha512; put algo in hash file; remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
artoonie committed Sep 30, 2023
1 parent d861e72 commit b6f8c9a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/main/java/network/brightspots/rcv/AuditableFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public void finalizeAndHash() {
Logger.info("File %s written with hash %s".formatted(getAbsolutePath(), hash));

// Write hash to hash file
File hashFile = new File(getAbsolutePath() + ".sha");
writeStringToFile(hashFile, hash);
File hashFile = new File(getAbsolutePath() + ".hash");
writeStringToFile(hashFile, "sha512: " + hash);

// Make both file and its hash file read-only
makeReadOnlyOrLogWarning(this);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/network/brightspots/rcv/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ static void createOutputDirectory(String dir) throws UnableToCreateDirectoryExce
static String getHash(File file) {
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-256");
digest = MessageDigest.getInstance("SHA-512");
} catch (NoSuchAlgorithmException e) {
Logger.severe("Failed to get SHA-256 algorithm");
Logger.severe("Failed to get SHA-512 algorithm");
return "[hash not available]";
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/network/brightspots/rcv/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ static void setup() {
// adds file logging for a tabulation run
static void addTabulationFileLogging(String outputFolder, String timestampString)
throws IOException {
// log file name is: outputFolder + timestamp + log index + hash + .log
// FileHandler requires % to be encoded as %%. %g is the log index.
// log file name is: outputFolder + timestamp + log index
// FileHandler requires % to be encoded as %%. %g is the log index
tabulationLogPattern =
Paths.get(
outputFolder.replace("%", "%%"),
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/network/brightspots/rcv/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ static String[] splitByNewline(String s) {
return s.trim().split("\\s*\\r?\\n\\s*");
}

static byte[] readFileToByteArray(File file) {
byte[] fileBytes = null;
try {
fileBytes = Files.readAllBytes(file.toPath());
} catch (IOException e) {
Logger.severe("Failed to read file: %s", file.getAbsolutePath());
}

return fileBytes;
}

static String bytesToHex(byte[] hash) {
StringBuilder hexString = new StringBuilder(2 * hash.length);
for (byte b : hash) {
Expand Down

0 comments on commit b6f8c9a

Please sign in to comment.