summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/util/backup/inc/identifier
diff options
context:
space:
mode:
authorKeuin <[email protected]>2020-12-17 00:21:13 +0800
committerkeuin <[email protected]>2020-12-17 00:21:13 +0800
commit8b05c48d76bbb05c2b440e57df1d9b3323edc598 (patch)
tree941c5b51e45b074bcc8656e457c9f582211df754 /src/main/java/com/keuin/kbackupfabric/util/backup/inc/identifier
parentfd9124f475422f62691fb542c3f8f35790b65d9b (diff)
Implementing incremental backup. (in progress)
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/util/backup/inc/identifier')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/backup/inc/identifier/ObjectIdentifier.java9
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/backup/inc/identifier/SingleHashIdentifier.java32
2 files changed, 41 insertions, 0 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/inc/identifier/ObjectIdentifier.java b/src/main/java/com/keuin/kbackupfabric/util/backup/inc/identifier/ObjectIdentifier.java
new file mode 100644
index 0000000..079f49d
--- /dev/null
+++ b/src/main/java/com/keuin/kbackupfabric/util/backup/inc/identifier/ObjectIdentifier.java
@@ -0,0 +1,9 @@
+package com.keuin.kbackupfabric.util.backup.inc.identifier;
+
+/**
+ * The identifier distinguishing files in the object collection.
+ * It should be based on cryptographic hash function in order to prevent possible attacks to the backup system.
+ * All identifiers should be immutable and implement their own equals method.
+ */
+public interface ObjectIdentifier {
+}
diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/inc/identifier/SingleHashIdentifier.java b/src/main/java/com/keuin/kbackupfabric/util/backup/inc/identifier/SingleHashIdentifier.java
new file mode 100644
index 0000000..50b23bb
--- /dev/null
+++ b/src/main/java/com/keuin/kbackupfabric/util/backup/inc/identifier/SingleHashIdentifier.java
@@ -0,0 +1,32 @@
+package com.keuin.kbackupfabric.util.backup.inc.identifier;
+
+import java.io.File;
+import java.util.Arrays;
+
+/**
+ * A simple identifier based on a single hash function.
+ */
+public abstract class SingleHashIdentifier implements ObjectIdentifier {
+
+ private final byte[] hash;
+
+ protected SingleHashIdentifier(byte[] hash) {
+ this.hash = Arrays.copyOf(hash, hash.length);
+ }
+
+ /**
+ * The hash function.
+ *
+ * @param file the file to be hashed.
+ * @return the hash bytes.
+ */
+ protected abstract byte[] hash(File file);
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof SingleHashIdentifier)) {
+ return false;
+ }
+ return Arrays.equals(hash, ((SingleHashIdentifier) obj).hash);
+ }
+}