-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHash.java
More file actions
44 lines (34 loc) · 1.04 KB
/
Hash.java
File metadata and controls
44 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package model.crypto;
import java.io.Serializable;
import model.lightchain.Identifier;
/**
* Represents abstract data type for the cryptographic hash function used in LightChain.
*/
public abstract class Hash implements Serializable {
/**
* Actual value of hash in bytes.
*/
private final byte[] bytes;
public static final int EQUAL = 0;
public static final int LESS = -1;
public static final int GREATER = 1;
public Hash(byte[] hashValue) {
this.bytes = hashValue.clone();
}
public Hash(Identifier identifier) {
this.bytes = identifier.getBytes();
}
/**
* Compares this hash value with the other hash value.
*
* @param other the other hash object to compare.
* @return +1 if this hash value is greater than other hash value, 0 if both hash values are equal and -1 otherwise.
*/
public abstract int compare(Hash other);
/**
* Converts a hash value to its corresponding identifier type.
*
* @return Identifier representation of the hash value.
*/
public abstract Identifier toIdentifier();
}