From d741c012f303f7d430af013be456d5221f1d29c0 Mon Sep 17 00:00:00 2001 From: ylecollen Date: Wed, 21 Dec 2016 12:58:00 +0100 Subject: [PATCH] identityKeys and oneTimeKeys return Map instead of JSON. --- .../java/org/matrix/olm/OlmAccountTest.java | 70 ++++++++-------- .../java/org/matrix/olm/OlmSessionTest.java | 47 +++++------ .../java/org/matrix/olm/OlmUtilityTest.java | 8 +- .../java/org/matrix/olm/TestHelper.java | 35 ++++---- .../main/java/org/matrix/olm/OlmAccount.java | 80 +++++++++++++++++-- .../olm-sdk/src/main/jni/olm_account.cpp | 2 +- 6 files changed, 152 insertions(+), 90 deletions(-) diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java index 2c2711d..024b44b 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java +++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java @@ -38,6 +38,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.util.Map; import static android.support.test.InstrumentationRegistry.getInstrumentation; import static org.junit.Assert.assertFalse; @@ -130,16 +131,16 @@ public class OlmAccountTest { */ @Test public void test05IdentityKeys() { - JSONObject identityKeysJson = mOlmAccount.identityKeys(); - assertNotNull(identityKeysJson); - Log.d(LOG_TAG,"## testIdentityKeys Keys="+identityKeysJson); + Map identityKeys = mOlmAccount.identityKeys(); + assertNotNull(identityKeys); + Log.d(LOG_TAG,"## testIdentityKeys Keys="+identityKeys); // is JSON_KEY_FINGER_PRINT_KEY present? - String fingerPrintKey = TestHelper.getFingerprintKey(identityKeysJson); + String fingerPrintKey = TestHelper.getFingerprintKey(identityKeys); assertTrue("fingerprint key missing",!TextUtils.isEmpty(fingerPrintKey)); // is JSON_KEY_IDENTITY_KEY present? - String identityKey = TestHelper.getIdentityKey(identityKeysJson); + String identityKey = TestHelper.getIdentityKey(identityKeys); assertTrue("identity key missing",!TextUtils.isEmpty(identityKey)); } @@ -169,20 +170,19 @@ public class OlmAccountTest { @Test public void test08OneTimeKeysJsonFormat() { int oneTimeKeysCount = 0; - JSONObject generatedKeysJsonObj; - JSONObject oneTimeKeysJson = mOlmAccount.oneTimeKeys(); + Map> oneTimeKeysJson = mOlmAccount.oneTimeKeys(); assertNotNull(oneTimeKeysJson); try { - generatedKeysJsonObj = oneTimeKeysJson.getJSONObject(OlmAccount.JSON_KEY_ONE_TIME_KEY); - assertTrue(OlmAccount.JSON_KEY_ONE_TIME_KEY +" object is missing", null!=generatedKeysJsonObj); + Map map = oneTimeKeysJson.get(OlmAccount.JSON_KEY_ONE_TIME_KEY); + assertTrue(OlmAccount.JSON_KEY_ONE_TIME_KEY +" object is missing", null!=map); // test the count of the generated one time keys: - oneTimeKeysCount = generatedKeysJsonObj.length(); + oneTimeKeysCount = map.size(); assertTrue("Expected count="+GENERATION_ONE_TIME_KEYS_NUMBER+" found="+oneTimeKeysCount,GENERATION_ONE_TIME_KEYS_NUMBER==oneTimeKeysCount); - } catch (JSONException e) { + } catch (Exception e) { assertTrue("Exception MSg="+e.getMessage(), false); } } @@ -244,8 +244,8 @@ public class OlmAccountTest { assertTrue(0==retValue); // get keys references - JSONObject identityKeysRef = accountRef.identityKeys(); - JSONObject oneTimeKeysRef = accountRef.oneTimeKeys(); + Map identityKeysRef = accountRef.identityKeys(); + Map> oneTimeKeysRef = accountRef.oneTimeKeys(); assertNotNull(identityKeysRef); assertNotNull(oneTimeKeysRef); @@ -268,8 +268,8 @@ public class OlmAccountTest { assertNotNull(accountDeserial); // get de-serialized keys - JSONObject identityKeysDeserial = accountDeserial.identityKeys(); - JSONObject oneTimeKeysDeserial = accountDeserial.oneTimeKeys(); + Map identityKeysDeserial = accountDeserial.identityKeys(); + Map> oneTimeKeysDeserial = accountDeserial.oneTimeKeys(); assertNotNull(identityKeysDeserial); assertNotNull(oneTimeKeysDeserial); @@ -363,43 +363,43 @@ public class OlmAccountTest { OlmAccount account9 = new OlmAccount(); OlmAccount account10 = new OlmAccount(); - JSONObject identityKeysJson1 = account1.identityKeys(); - JSONObject identityKeysJson2 = account2.identityKeys(); - JSONObject identityKeysJson3 = account3.identityKeys(); - JSONObject identityKeysJson4 = account4.identityKeys(); - JSONObject identityKeysJson5 = account5.identityKeys(); - JSONObject identityKeysJson6 = account6.identityKeys(); - JSONObject identityKeysJson7 = account7.identityKeys(); - JSONObject identityKeysJson8 = account8.identityKeys(); - JSONObject identityKeysJson9 = account9.identityKeys(); - JSONObject identityKeysJson10 = account10.identityKeys(); + Map identityKeys1 = account1.identityKeys(); + Map identityKeys2 = account2.identityKeys(); + Map identityKeys3 = account3.identityKeys(); + Map identityKeys4 = account4.identityKeys(); + Map identityKeys5 = account5.identityKeys(); + Map identityKeys6 = account6.identityKeys(); + Map identityKeys7 = account7.identityKeys(); + Map identityKeys8 = account8.identityKeys(); + Map identityKeys9 = account9.identityKeys(); + Map identityKeys10 = account10.identityKeys(); - String identityKey1 = TestHelper.getIdentityKey(identityKeysJson1); - String identityKey2 = TestHelper.getIdentityKey(identityKeysJson2); + String identityKey1 = TestHelper.getIdentityKey(identityKeys1); + String identityKey2 = TestHelper.getIdentityKey(identityKeys2); assertFalse(identityKey1.equals(identityKey2)); - String identityKey3 = TestHelper.getIdentityKey(identityKeysJson3); + String identityKey3 = TestHelper.getIdentityKey(identityKeys3); assertFalse(identityKey2.equals(identityKey3)); - String identityKey4 = TestHelper.getIdentityKey(identityKeysJson4); + String identityKey4 = TestHelper.getIdentityKey(identityKeys4); assertFalse(identityKey3.equals(identityKey4)); - String identityKey5 = TestHelper.getIdentityKey(identityKeysJson5); + String identityKey5 = TestHelper.getIdentityKey(identityKeys5); assertFalse(identityKey4.equals(identityKey5)); - String identityKey6 = TestHelper.getIdentityKey(identityKeysJson6); + String identityKey6 = TestHelper.getIdentityKey(identityKeys6); assertFalse(identityKey5.equals(identityKey6)); - String identityKey7 = TestHelper.getIdentityKey(identityKeysJson7); + String identityKey7 = TestHelper.getIdentityKey(identityKeys7); assertFalse(identityKey6.equals(identityKey7)); - String identityKey8 = TestHelper.getIdentityKey(identityKeysJson8); + String identityKey8 = TestHelper.getIdentityKey(identityKeys8); assertFalse(identityKey7.equals(identityKey8)); - String identityKey9 = TestHelper.getIdentityKey(identityKeysJson9); + String identityKey9 = TestHelper.getIdentityKey(identityKeys9); assertFalse(identityKey8.equals(identityKey9)); - String identityKey10 = TestHelper.getIdentityKey(identityKeysJson10); + String identityKey10 = TestHelper.getIdentityKey(identityKeys10); assertFalse(identityKey9.equals(identityKey10)); account1.releaseAccount(); diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java index 1aeb3fb..98e5b90 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java +++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java @@ -33,6 +33,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.util.Map; import static android.support.test.InstrumentationRegistry.getInstrumentation; import static org.junit.Assert.assertFalse; @@ -93,14 +94,14 @@ public class OlmSessionTest { assertTrue(0!=aliceAccount.getOlmAccountId()); // get bob identity key - JSONObject bobIdentityKeysJson = bobAccount.identityKeys(); - bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeysJson); + Map bobIdentityKeys = bobAccount.identityKeys(); + bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys); assertTrue(null!=bobIdentityKey); // get bob one time keys assertTrue(0==bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER)); - JSONObject bobOneTimeKeysJsonObj = bobAccount.oneTimeKeys(); - bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeysJsonObj,1); + Map> bobOneTimeKeys = bobAccount.oneTimeKeys(); + bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1); assertNotNull(bobOneTimeKey); // CREATE ALICE SESSION @@ -186,14 +187,14 @@ public class OlmSessionTest { assertTrue(0!=aliceAccount.getOlmAccountId()); // get bob identity key - JSONObject bobIdentityKeysJson = bobAccount.identityKeys(); - bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeysJson); + Map bobIdentityKeys = bobAccount.identityKeys(); + bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys); assertTrue(null!=bobIdentityKey); // get bob one time keys assertTrue(0==bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER)); - JSONObject bobOneTimeKeysJsonObj = bobAccount.oneTimeKeys(); - bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeysJsonObj,1); + Map> bobOneTimeKeys = bobAccount.oneTimeKeys(); + bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1); assertNotNull(bobOneTimeKey); // CREATE ALICE SESSION @@ -358,16 +359,16 @@ public class OlmSessionTest { } // get bob/luke identity key - JSONObject bobIdentityKeysJson = bobAccount.identityKeys(); - JSONObject aliceIdentityKeysJson = aliceAccount.identityKeys(); - String bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeysJson); - String aliceIdentityKey = TestHelper.getIdentityKey(aliceIdentityKeysJson); + Map bobIdentityKeys = bobAccount.identityKeys(); + Map aliceIdentityKeys = aliceAccount.identityKeys(); + String bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys); + String aliceIdentityKey = TestHelper.getIdentityKey(aliceIdentityKeys); // get bob/luke one time keys assertTrue(0 == bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER)); assertTrue(0 == aliceAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER)); - JSONObject bobOneTimeKeysJsonObj = bobAccount.oneTimeKeys(); - String bobOneTimeKey1 = TestHelper.getOneTimeKey(bobOneTimeKeysJsonObj, 1); + Map> bobOneTimeKeys = bobAccount.oneTimeKeys(); + String bobOneTimeKey1 = TestHelper.getOneTimeKey(bobOneTimeKeys, 1); // create alice inbound session for bob assertTrue(0==aliceSession.initOutboundSessionWithAccount(aliceAccount, bobIdentityKey, bobOneTimeKey1)); @@ -428,14 +429,14 @@ public class OlmSessionTest { assertTrue(0!=aliceAccount.getOlmAccountId()); // get bob identity key - JSONObject bobIdentityKeysJson = bobAccount.identityKeys(); - bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeysJson); + Map bobIdentityKeys = bobAccount.identityKeys(); + bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys); assertTrue(null!=bobIdentityKey); // get bob one time keys assertTrue(0==bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER)); - JSONObject bobOneTimeKeysJsonObj = bobAccount.oneTimeKeys(); - bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeysJsonObj,1); + Map> bobOneTimeKeys = bobAccount.oneTimeKeys(); + bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1); assertNotNull(bobOneTimeKey); // CREATE ALICE SESSION @@ -567,15 +568,15 @@ public class OlmSessionTest { } // get bob identity key - JSONObject bobIdentityKeysJson = bobAccount.identityKeys(); - String bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeysJson); + Map bobIdentityKeys = bobAccount.identityKeys(); + String bobIdentityKey = TestHelper.getIdentityKey(bobIdentityKeys); assertTrue(null != bobIdentityKey); // get bob one time keys assertTrue(0 == bobAccount.generateOneTimeKeys(ONE_TIME_KEYS_NUMBER)); - JSONObject bobOneTimeKeysJsonObj = bobAccount.oneTimeKeys(); - assertNotNull(bobOneTimeKeysJsonObj); - String bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeysJsonObj,1); + Map> bobOneTimeKeys = bobAccount.oneTimeKeys(); + assertNotNull(bobOneTimeKeys); + String bobOneTimeKey = TestHelper.getOneTimeKey(bobOneTimeKeys,1); assertNotNull(bobOneTimeKey); // CREATE ALICE SESSION diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java index 3006344..6296a31 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java +++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java @@ -27,6 +27,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; +import java.util.Map; + import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -76,9 +78,9 @@ public class OlmUtilityTest { assertNotNull(messageSignature); // get identities key (finger print key) - JSONObject identityKeysJson = account.identityKeys(); - assertNotNull(identityKeysJson); - fingerPrintKey = TestHelper.getFingerprintKey(identityKeysJson); + Map identityKeys = account.identityKeys(); + assertNotNull(identityKeys); + fingerPrintKey = TestHelper.getFingerprintKey(identityKeys); assertTrue("fingerprint key missing",!TextUtils.isEmpty(fingerPrintKey)); // instantiate utility object diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/TestHelper.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/TestHelper.java index 363ab7a..3adb63c 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/TestHelper.java +++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/TestHelper.java @@ -19,7 +19,9 @@ package org.matrix.olm; import org.json.JSONException; import org.json.JSONObject; +import java.util.ArrayList; import java.util.Iterator; +import java.util.Map; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -31,15 +33,15 @@ public class TestHelper { /** * Return the identity key {@link OlmAccount#JSON_KEY_IDENTITY_KEY} from the JSON object. - * @param aIdentityKeysObj JSON result of {@link OlmAccount#identityKeys()} + * @param aIdentityKeysMap result of {@link OlmAccount#identityKeys()} * @return identity key string if operation succeed, null otherwise */ - static public String getIdentityKey(JSONObject aIdentityKeysObj){ + static public String getIdentityKey(Map aIdentityKeysMap){ String idKey = null; try { - idKey = aIdentityKeysObj.getString(OlmAccount.JSON_KEY_IDENTITY_KEY); - } catch (JSONException e) { + idKey = aIdentityKeysMap.get(OlmAccount.JSON_KEY_IDENTITY_KEY); + } catch (Exception e) { assertTrue("Exception MSg=" + e.getMessage(), false); } return idKey; @@ -47,15 +49,15 @@ public class TestHelper { /** * Return the fingerprint key {@link OlmAccount#JSON_KEY_FINGER_PRINT_KEY} from the JSON object. - * @param aIdentityKeysObj JSON result of {@link OlmAccount#identityKeys()} + * @param aIdentityKeysMap result of {@link OlmAccount#identityKeys()} * @return fingerprint key string if operation succeed, null otherwise */ - static public String getFingerprintKey(JSONObject aIdentityKeysObj){ + static public String getFingerprintKey(Map aIdentityKeysMap) { String fingerprintKey = null; try { - fingerprintKey = aIdentityKeysObj.getString(OlmAccount.JSON_KEY_FINGER_PRINT_KEY); - } catch (JSONException e) { + fingerprintKey = aIdentityKeysMap.get(OlmAccount.JSON_KEY_FINGER_PRINT_KEY); + } catch (Exception e) { assertTrue("Exception MSg=" + e.getMessage(), false); } return fingerprintKey; @@ -63,26 +65,19 @@ public class TestHelper { /** * Return the first one time key from the JSON object. - * @param aIdentityKeysObj JSON result of {@link OlmAccount#oneTimeKeys()} + * @param aIdentityKeysMap result of {@link OlmAccount#oneTimeKeys()} * @param aKeyPosition the position of the key to be retrieved * @return one time key string if operation succeed, null otherwise */ - static public String getOneTimeKey(JSONObject aIdentityKeysObj, int aKeyPosition) { + static public String getOneTimeKey(Map> aIdentityKeysMap, int aKeyPosition) { String firstOneTimeKey = null; - int i=0; try { - JSONObject generatedKeys = aIdentityKeysObj.getJSONObject(OlmAccount.JSON_KEY_ONE_TIME_KEY); + Map generatedKeys = aIdentityKeysMap.get(OlmAccount.JSON_KEY_ONE_TIME_KEY); assertNotNull(OlmAccount.JSON_KEY_ONE_TIME_KEY + " object is missing", generatedKeys); - Iterator generatedKeysIt = generatedKeys.keys(); - while(i(generatedKeys.values())).get(aKeyPosition - 1); + } catch (Exception e) { assertTrue("Exception Msg=" + e.getMessage(), false); } return firstOneTimeKey; diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java index aeeaebc..4863a06 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java +++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java @@ -26,6 +26,9 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; /** * Account class used to create Olm sessions in conjunction with {@link OlmSession} class.
@@ -226,16 +229,16 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { private native long createNewAccountJni(); /** - * Return the identity keys (identity and fingerprint keys) in a JSON array.
+ * Return the identity keys (identity and fingerprint keys) in a dictionary.
* Public API for {@link #identityKeysJni()}.
* Ex: * { * "curve25519":"Vam++zZPMqDQM6ANKpO/uAl5ViJSHxV9hd+b0/fwRAg", * "ed25519":"+v8SOlOASFTMrX3MCKBM4iVnYoZ+JIjpNt1fi8Z9O2I" * } - * @return identity keys in JSON array if operation succeed, null otherwise + * @return identity keys dictionary if operation succeeds, null otherwise */ - public JSONObject identityKeys() { + public Map identityKeys() { JSONObject identityKeysJsonObj = null; byte identityKeysBuffer[]; @@ -251,7 +254,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { Log.e(LOG_TAG, "## identityKeys(): Failure - identityKeysJni()=null"); } - return identityKeysJsonObj; + return toStringMap(identityKeysJsonObj); } /** * Get the public identity keys (Ed25519 fingerprint key and Curve25519 identity key).
@@ -283,7 +286,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { private native int generateOneTimeKeysJni(int aNumberOfKeys); /** - * Return the "one time keys" in a JSON array.
+ * Return the "one time keys" in a dictionary.
* The number of "one time keys", is specified by {@link #generateOneTimeKeys(int)}
* Ex: * { "curve25519": @@ -295,9 +298,9 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { * }
* Public API for {@link #oneTimeKeysJni()}.
* Note: these keys are to be published on the server. - * @return one time keys in JSON array format if operation succeed, null otherwise + * @return one time keys in string dictionary if operation succeed, null otherwise */ - public JSONObject oneTimeKeys() { + public Map> oneTimeKeys() { byte identityKeysBuffer[]; JSONObject oneTimeKeysJsonObj = null; @@ -313,7 +316,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { Log.e(LOG_TAG, "## oneTimeKeys(): Failure - identityKeysJni()=null"); } - return oneTimeKeysJsonObj; + return toStringMapMap(oneTimeKeysJsonObj); } /** * Get the public parts of the unpublished "one time keys" for the account.
@@ -373,4 +376,65 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { public int getUnreleasedCount() { return mUnreleasedCount; } + + /** + * Build a string-string dictionary from a jsonObject.
+ * @param jsonObject the object to parse + * @return the map + */ + private static Map toStringMap(JSONObject jsonObject) { + if (null != jsonObject) { + HashMap map = new HashMap<>(); + Iterator keysItr = jsonObject.keys(); + while(keysItr.hasNext()) { + String key = keysItr.next(); + try { + Object value = jsonObject.get(key); + + if (value instanceof String) { + map.put(key, (String) value); + } else { + Log.e(LOG_TAG, "## toStringMap(): unexpected type " + value.getClass()); + } + } catch (Exception e) { + Log.e(LOG_TAG, "## toStringMap(): failed " + e.getMessage()); + } + } + + return map; + } + + return null; + } + + /** + * Build a string-string dictionary of string dictionary from a jsonObject.
+ * @param jsonObject the object to parse + * @return the map + */ + private static Map> toStringMapMap(JSONObject jsonObject) { + if (null != jsonObject) { + HashMap> map = new HashMap<>(); + + Iterator keysItr = jsonObject.keys(); + while(keysItr.hasNext()) { + String key = keysItr.next(); + try { + Object value = jsonObject.get(key); + + if (value instanceof JSONObject) { + map.put(key, toStringMap((JSONObject) value)); + } else { + Log.e(LOG_TAG, "## toStringMapMap(): unexpected type " + value.getClass()); + } + } catch (Exception e) { + Log.e(LOG_TAG, "## toStringMapMap(): failed " + e.getMessage()); + } + } + + return map; + } + + return null; + } } diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp index c8c6e8a..00c8a8e 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp +++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp @@ -468,7 +468,7 @@ JNIEXPORT jstring OLM_MANAGER_FUNC_DEF(getOlmLibVersionJni)(JNIEnv* env, jobject olm_get_library_version(&majorVer, &minorVer, &patchVer); LOGD("## getOlmLibVersionJni(): Major=%d Minor=%d Patch=%d", majorVer, minorVer, patchVer); - snprintf(buff, sizeof(buff), " V%d.%d.%d", majorVer, minorVer, patchVer); + snprintf(buff, sizeof(buff), "%d.%d.%d", majorVer, minorVer, patchVer); returnValueStr = env->NewStringUTF((const char*)buff); return returnValueStr;