aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/otr/OtrConfigurator.java
diff options
context:
space:
mode:
authorGeorge Politis <666f6f@java.net>2009-09-06 15:13:29 +0000
committerGeorge Politis <666f6f@java.net>2009-09-06 15:13:29 +0000
commite2974c6817103f85d8542809a20eede9db8d5142 (patch)
tree145551f100b9bf8d44a68842fdfcab878446b24d /src/net/java/sip/communicator/plugin/otr/OtrConfigurator.java
parent55b0e3520af51d7324abf24d2a88879d2b894b25 (diff)
downloadjitsi-e2974c6817103f85d8542809a20eede9db8d5142.zip
jitsi-e2974c6817103f85d8542809a20eede9db8d5142.tar.gz
jitsi-e2974c6817103f85d8542809a20eede9db8d5142.tar.bz2
Moved key management functionality from ScOtrEngineImpl to ScOtrKeyManager (new). Updated otr4j@112
Diffstat (limited to 'src/net/java/sip/communicator/plugin/otr/OtrConfigurator.java')
-rwxr-xr-xsrc/net/java/sip/communicator/plugin/otr/OtrConfigurator.java86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/plugin/otr/OtrConfigurator.java b/src/net/java/sip/communicator/plugin/otr/OtrConfigurator.java
new file mode 100755
index 0000000..4ae7cd8
--- /dev/null
+++ b/src/net/java/sip/communicator/plugin/otr/OtrConfigurator.java
@@ -0,0 +1,86 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license. See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.plugin.otr;
+
+import org.bouncycastle.util.encoders.*;
+
+/**
+ *
+ * @author George Politis
+ *
+ */
+class Configurator
+{
+ private String getXmlFriendlyString(String s)
+ {
+ if (s == null || s.length() < 1)
+ return s;
+
+ // XML Tags are not allowed to start with digits,
+ // insert a dummy "p" char.
+ if (Character.isDigit(s.charAt(0)))
+ s = "p" + s;
+
+ char[] cId = new char[s.length()];
+ for (int i = 0; i < cId.length; i++)
+ {
+ char c = s.charAt(i);
+ cId[i] = (Character.isLetterOrDigit(c)) ? c : '_';
+ }
+
+ return new String(cId);
+ }
+
+ private String getID(String id)
+ {
+ return "net.java.sip.communicator.plugin.otr."
+ + getXmlFriendlyString(id);
+ }
+
+ public byte[] getPropertyBytes(String id)
+ {
+ String value =
+ (String) OtrActivator.configService.getProperty(this.getID(id));
+ if (value == null)
+ return null;
+
+ return Base64.decode(value.getBytes());
+ }
+
+ public Boolean getPropertyBoolean(String id, boolean defaultValue)
+ {
+ return OtrActivator.configService.getBoolean(this.getID(id),
+ defaultValue);
+ }
+
+ public void setProperty(String id, byte[] value)
+ {
+ String valueToStore = new String(Base64.encode(value));
+
+ OtrActivator.configService
+ .setProperty(this.getID(id), valueToStore);
+ }
+
+ public void setProperty(String id, boolean value)
+ {
+ OtrActivator.configService.setProperty(this.getID(id), value);
+ }
+
+ public void setProperty(String id, Integer value)
+ {
+ OtrActivator.configService.setProperty(this.getID(id), value);
+ }
+
+ public void removeProperty(String id)
+ {
+ OtrActivator.configService.removeProperty(this.getID(id));
+ }
+
+ public int getPropertyInt(String id, int defaultValue)
+ {
+ return OtrActivator.configService.getInt(getID(id), defaultValue);
+ }
+}