X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/0287272a3b9924f3ba9aeded570a32841d3e1196..d08508e6efbb0f993a6b7bd633d6406d0575db34:/src/main/java/org/asamk/signal/manager/TrustLevel.java diff --git a/src/main/java/org/asamk/signal/manager/TrustLevel.java b/src/main/java/org/asamk/signal/manager/TrustLevel.java new file mode 100644 index 00000000..c9fa7a5e --- /dev/null +++ b/src/main/java/org/asamk/signal/manager/TrustLevel.java @@ -0,0 +1,42 @@ +package org.asamk.signal.manager; + +import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage; + +public enum TrustLevel { + UNTRUSTED, + TRUSTED_UNVERIFIED, + TRUSTED_VERIFIED; + + private static TrustLevel[] cachedValues = null; + + public static TrustLevel fromInt(int i) { + if (TrustLevel.cachedValues == null) { + TrustLevel.cachedValues = TrustLevel.values(); + } + return TrustLevel.cachedValues[i]; + } + + public static TrustLevel fromVerifiedState(VerifiedMessage.VerifiedState verifiedState) { + switch (verifiedState) { + case DEFAULT: + return TRUSTED_UNVERIFIED; + case UNVERIFIED: + return UNTRUSTED; + case VERIFIED: + return TRUSTED_VERIFIED; + } + throw new RuntimeException("Unknown verified state: " + verifiedState); + } + + public VerifiedMessage.VerifiedState toVerifiedState() { + switch (this) { + case TRUSTED_UNVERIFIED: + return VerifiedMessage.VerifiedState.DEFAULT; + case UNTRUSTED: + return VerifiedMessage.VerifiedState.UNVERIFIED; + case TRUSTED_VERIFIED: + return VerifiedMessage.VerifiedState.VERIFIED; + } + throw new RuntimeException("Unknown verified state: " + this); + } +}