aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/crypto/axolotl
diff options
context:
space:
mode:
authorAndreas Straub <andy@strb.org>2015-07-21 01:52:22 +0200
committerAndreas Straub <andy@strb.org>2015-07-21 01:52:22 +0200
commitb7ff2c34614a92f3893732338f75cb0f7fe77d32 (patch)
tree4ea1f27644c6f4b1bc9cc23b5479eebe0c7fda45 /src/main/java/eu/siacs/conversations/crypto/axolotl
parent639ebd644ba7f6e05bfcb09ad1f616d0f433b5a6 (diff)
Use properly fixed numeral values in Trust enum
Why, oh God, why?! #thanksjamesgosling
Diffstat (limited to 'src/main/java/eu/siacs/conversations/crypto/axolotl')
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
index 7549e439..fc1e13fd 100644
--- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
+++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
@@ -99,10 +99,28 @@ public class AxolotlService {
private int currentPreKeyId = 0;
public enum Trust {
- UNDECIDED, // 0
- TRUSTED,
- UNTRUSTED,
- COMPROMISED;
+ UNDECIDED(0),
+ TRUSTED(1),
+ UNTRUSTED(2),
+ COMPROMISED(3);
+
+ private static final Map<Integer, Trust> trustsByValue = new HashMap<>();
+
+ static {
+ for (Trust trust : Trust.values()) {
+ trustsByValue.put(trust.getCode(), trust);
+ }
+ }
+
+ private final int code;
+
+ Trust(int code){
+ this.code = code;
+ }
+
+ public int getCode() {
+ return this.code;
+ }
public String toString() {
switch(this){
@@ -119,6 +137,10 @@ public class AxolotlService {
public static Trust fromBoolean(Boolean trusted) {
return trusted?TRUSTED:UNTRUSTED;
}
+
+ public static Trust fromCode(int code) {
+ return trustsByValue.get(code);
+ }
};
private static IdentityKeyPair generateIdentityKeyPair() {