Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
matrix-org
Olm
Commits
d741c012
Commit
d741c012
authored
Dec 21, 2016
by
ylecollen
Browse files
identityKeys and oneTimeKeys return Map instead of JSON.
parent
c553d18a
Changes
6
Hide whitespace changes
Inline
Side-by-side
java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java
View file @
d741c012
...
...
@@ -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
identityKeys
Json
=
mOlmAccount
.
identityKeys
();
assertNotNull
(
identityKeys
Json
);
Log
.
d
(
LOG_TAG
,
"## testIdentityKeys Keys="
+
identityKeys
Json
);
Map
<
String
,
String
>
identityKeys
=
mOlmAccount
.
identityKeys
();
assertNotNull
(
identityKeys
);
Log
.
d
(
LOG_TAG
,
"## testIdentityKeys Keys="
+
identityKeys
);
// is JSON_KEY_FINGER_PRINT_KEY present?
String
fingerPrintKey
=
TestHelper
.
getFingerprintKey
(
identityKeys
Json
);
String
fingerPrintKey
=
TestHelper
.
getFingerprintKey
(
identityKeys
);
assertTrue
(
"fingerprint key missing"
,!
TextUtils
.
isEmpty
(
fingerPrintKey
));
// is JSON_KEY_IDENTITY_KEY present?
String
identityKey
=
TestHelper
.
getIdentityKey
(
identityKeys
Json
);
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
<
String
,
Map
<
String
,
String
>>
oneTimeKeysJson
=
mOlmAccount
.
oneTimeKeys
();
assertNotNull
(
oneTimeKeysJson
);
try
{
generatedKeysJsonObj
=
oneTimeKeysJson
.
get
JSONObject
(
OlmAccount
.
JSON_KEY_ONE_TIME_KEY
);
assertTrue
(
OlmAccount
.
JSON_KEY_ONE_TIME_KEY
+
" object is missing"
,
null
!=
generatedKeysJsonObj
);
Map
<
String
,
String
>
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
(
JSON
Exception
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
<
String
,
String
>
identityKeysRef
=
accountRef
.
identityKeys
();
Map
<
String
,
Map
<
String
,
String
>>
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
<
String
,
String
>
identityKeysDeserial
=
accountDeserial
.
identityKeys
();
Map
<
String
,
Map
<
String
,
String
>>
oneTimeKeysDeserial
=
accountDeserial
.
oneTimeKeys
();
assertNotNull
(
identityKeysDeserial
);
assertNotNull
(
oneTimeKeysDeserial
);
...
...
@@ -363,43 +363,43 @@ public class OlmAccountTest {
OlmAccount
account9
=
new
OlmAccount
();
OlmAccount
account10
=
new
OlmAccount
();
JSONObject
identityKeys
Json
1
=
account1
.
identityKeys
();
JSONObject
identityKeys
Json
2
=
account2
.
identityKeys
();
JSONObject
identityKeys
Json
3
=
account3
.
identityKeys
();
JSONObject
identityKeys
Json
4
=
account4
.
identityKeys
();
JSONObject
identityKeys
Json
5
=
account5
.
identityKeys
();
JSONObject
identityKeys
Json
6
=
account6
.
identityKeys
();
JSONObject
identityKeys
Json
7
=
account7
.
identityKeys
();
JSONObject
identityKeys
Json
8
=
account8
.
identityKeys
();
JSONObject
identityKeys
Json
9
=
account9
.
identityKeys
();
JSONObject
identityKeys
Json
10
=
account10
.
identityKeys
();
String
identityKey1
=
TestHelper
.
getIdentityKey
(
identityKeys
Json
1
);
String
identityKey2
=
TestHelper
.
getIdentityKey
(
identityKeys
Json
2
);
Map
<
String
,
String
>
identityKeys1
=
account1
.
identityKeys
();
Map
<
String
,
String
>
identityKeys2
=
account2
.
identityKeys
();
Map
<
String
,
String
>
identityKeys3
=
account3
.
identityKeys
();
Map
<
String
,
String
>
identityKeys4
=
account4
.
identityKeys
();
Map
<
String
,
String
>
identityKeys5
=
account5
.
identityKeys
();
Map
<
String
,
String
>
identityKeys6
=
account6
.
identityKeys
();
Map
<
String
,
String
>
identityKeys7
=
account7
.
identityKeys
();
Map
<
String
,
String
>
identityKeys8
=
account8
.
identityKeys
();
Map
<
String
,
String
>
identityKeys9
=
account9
.
identityKeys
();
Map
<
String
,
String
>
identityKeys10
=
account10
.
identityKeys
();
String
identityKey1
=
TestHelper
.
getIdentityKey
(
identityKeys1
);
String
identityKey2
=
TestHelper
.
getIdentityKey
(
identityKeys2
);
assertFalse
(
identityKey1
.
equals
(
identityKey2
));
String
identityKey3
=
TestHelper
.
getIdentityKey
(
identityKeys
Json
3
);
String
identityKey3
=
TestHelper
.
getIdentityKey
(
identityKeys3
);
assertFalse
(
identityKey2
.
equals
(
identityKey3
));
String
identityKey4
=
TestHelper
.
getIdentityKey
(
identityKeys
Json
4
);
String
identityKey4
=
TestHelper
.
getIdentityKey
(
identityKeys4
);
assertFalse
(
identityKey3
.
equals
(
identityKey4
));
String
identityKey5
=
TestHelper
.
getIdentityKey
(
identityKeys
Json
5
);
String
identityKey5
=
TestHelper
.
getIdentityKey
(
identityKeys5
);
assertFalse
(
identityKey4
.
equals
(
identityKey5
));
String
identityKey6
=
TestHelper
.
getIdentityKey
(
identityKeys
Json
6
);
String
identityKey6
=
TestHelper
.
getIdentityKey
(
identityKeys6
);
assertFalse
(
identityKey5
.
equals
(
identityKey6
));
String
identityKey7
=
TestHelper
.
getIdentityKey
(
identityKeys
Json
7
);
String
identityKey7
=
TestHelper
.
getIdentityKey
(
identityKeys7
);
assertFalse
(
identityKey6
.
equals
(
identityKey7
));
String
identityKey8
=
TestHelper
.
getIdentityKey
(
identityKeys
Json
8
);
String
identityKey8
=
TestHelper
.
getIdentityKey
(
identityKeys8
);
assertFalse
(
identityKey7
.
equals
(
identityKey8
));
String
identityKey9
=
TestHelper
.
getIdentityKey
(
identityKeys
Json
9
);
String
identityKey9
=
TestHelper
.
getIdentityKey
(
identityKeys9
);
assertFalse
(
identityKey8
.
equals
(
identityKey9
));
String
identityKey10
=
TestHelper
.
getIdentityKey
(
identityKeys
Json
10
);
String
identityKey10
=
TestHelper
.
getIdentityKey
(
identityKeys10
);
assertFalse
(
identityKey9
.
equals
(
identityKey10
));
account1
.
releaseAccount
();
...
...
java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java
View file @
d741c012
...
...
@@ -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
bobIdentityKeys
Json
=
bobAccount
.
identityKeys
();
bobIdentityKey
=
TestHelper
.
getIdentityKey
(
bobIdentityKeys
Json
);
Map
<
String
,
String
>
bobIdentityKeys
=
bobAccount
.
identityKeys
();
bobIdentityKey
=
TestHelper
.
getIdentityKey
(
bobIdentityKeys
);
assertTrue
(
null
!=
bobIdentityKey
);
// get bob one time keys
assertTrue
(
0
==
bobAccount
.
generateOneTimeKeys
(
ONE_TIME_KEYS_NUMBER
));
JSONObject
bobOneTimeKeys
JsonObj
=
bobAccount
.
oneTimeKeys
();
bobOneTimeKey
=
TestHelper
.
getOneTimeKey
(
bobOneTimeKeys
JsonObj
,
1
);
Map
<
String
,
Map
<
String
,
String
>>
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
bobIdentityKeys
Json
=
bobAccount
.
identityKeys
();
bobIdentityKey
=
TestHelper
.
getIdentityKey
(
bobIdentityKeys
Json
);
Map
<
String
,
String
>
bobIdentityKeys
=
bobAccount
.
identityKeys
();
bobIdentityKey
=
TestHelper
.
getIdentityKey
(
bobIdentityKeys
);
assertTrue
(
null
!=
bobIdentityKey
);
// get bob one time keys
assertTrue
(
0
==
bobAccount
.
generateOneTimeKeys
(
ONE_TIME_KEYS_NUMBER
));
JSONObject
bobOneTimeKeys
JsonObj
=
bobAccount
.
oneTimeKeys
();
bobOneTimeKey
=
TestHelper
.
getOneTimeKey
(
bobOneTimeKeys
JsonObj
,
1
);
Map
<
String
,
Map
<
String
,
String
>>
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
bobIdentityKeys
Json
=
bobAccount
.
identityKeys
();
JSONObject
aliceIdentityKeys
Json
=
aliceAccount
.
identityKeys
();
String
bobIdentityKey
=
TestHelper
.
getIdentityKey
(
bobIdentityKeys
Json
);
String
aliceIdentityKey
=
TestHelper
.
getIdentityKey
(
aliceIdentityKeys
Json
);
Map
<
String
,
String
>
bobIdentityKeys
=
bobAccount
.
identityKeys
();
Map
<
String
,
String
>
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
bobOneTimeKeys
JsonObj
=
bobAccount
.
oneTimeKeys
();
String
bobOneTimeKey1
=
TestHelper
.
getOneTimeKey
(
bobOneTimeKeys
JsonObj
,
1
);
Map
<
String
,
Map
<
String
,
String
>>
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
bobIdentityKeys
Json
=
bobAccount
.
identityKeys
();
bobIdentityKey
=
TestHelper
.
getIdentityKey
(
bobIdentityKeys
Json
);
Map
<
String
,
String
>
bobIdentityKeys
=
bobAccount
.
identityKeys
();
bobIdentityKey
=
TestHelper
.
getIdentityKey
(
bobIdentityKeys
);
assertTrue
(
null
!=
bobIdentityKey
);
// get bob one time keys
assertTrue
(
0
==
bobAccount
.
generateOneTimeKeys
(
ONE_TIME_KEYS_NUMBER
));
JSONObject
bobOneTimeKeys
JsonObj
=
bobAccount
.
oneTimeKeys
();
bobOneTimeKey
=
TestHelper
.
getOneTimeKey
(
bobOneTimeKeys
JsonObj
,
1
);
Map
<
String
,
Map
<
String
,
String
>>
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
bobIdentityKeys
Json
=
bobAccount
.
identityKeys
();
String
bobIdentityKey
=
TestHelper
.
getIdentityKey
(
bobIdentityKeys
Json
);
Map
<
String
,
String
>
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
bobOneTimeKeys
JsonObj
=
bobAccount
.
oneTimeKeys
();
assertNotNull
(
bobOneTimeKeys
JsonObj
);
String
bobOneTimeKey
=
TestHelper
.
getOneTimeKey
(
bobOneTimeKeys
JsonObj
,
1
);
Map
<
String
,
Map
<
String
,
String
>>
bobOneTimeKeys
=
bobAccount
.
oneTimeKeys
();
assertNotNull
(
bobOneTimeKeys
);
String
bobOneTimeKey
=
TestHelper
.
getOneTimeKey
(
bobOneTimeKeys
,
1
);
assertNotNull
(
bobOneTimeKey
);
// CREATE ALICE SESSION
...
...
java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java
View file @
d741c012
...
...
@@ -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
identityKeys
Json
=
account
.
identityKeys
();
assertNotNull
(
identityKeys
Json
);
fingerPrintKey
=
TestHelper
.
getFingerprintKey
(
identityKeys
Json
);
Map
<
String
,
String
>
identityKeys
=
account
.
identityKeys
();
assertNotNull
(
identityKeys
);
fingerPrintKey
=
TestHelper
.
getFingerprintKey
(
identityKeys
);
assertTrue
(
"fingerprint key missing"
,!
TextUtils
.
isEmpty
(
fingerPrintKey
));
// instantiate utility object
...
...
java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/TestHelper.java
View file @
d741c012
...
...
@@ -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 aIdentityKeys
Obj JSON
result of {@link OlmAccount#identityKeys()}
* @param aIdentityKeys
Map
result of {@link OlmAccount#identityKeys()}
* @return identity key string if operation succeed, null otherwise
*/
static
public
String
getIdentityKey
(
JSONObject
aIdentityKeys
Obj
){
static
public
String
getIdentityKey
(
Map
<
String
,
String
>
aIdentityKeys
Map
){
String
idKey
=
null
;
try
{
idKey
=
aIdentityKeys
Obj
.
get
String
(
OlmAccount
.
JSON_KEY_IDENTITY_KEY
);
}
catch
(
JSON
Exception
e
)
{
idKey
=
aIdentityKeys
Map
.
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 aIdentityKeys
Obj JSON
result of {@link OlmAccount#identityKeys()}
* @param aIdentityKeys
Map
result of {@link OlmAccount#identityKeys()}
* @return fingerprint key string if operation succeed, null otherwise
*/
static
public
String
getFingerprintKey
(
JSONObject
aIdentityKeys
Obj
)
{
static
public
String
getFingerprintKey
(
Map
<
String
,
String
>
aIdentityKeys
Map
)
{
String
fingerprintKey
=
null
;
try
{
fingerprintKey
=
aIdentityKeys
Obj
.
get
String
(
OlmAccount
.
JSON_KEY_FINGER_PRINT_KEY
);
}
catch
(
JSON
Exception
e
)
{
fingerprintKey
=
aIdentityKeys
Map
.
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 aIdentityKeys
Obj JSON
result of {@link OlmAccount#oneTimeKeys()}
* @param aIdentityKeys
Map
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
aIdentityKeys
Obj
,
int
aKeyPosition
)
{
static
public
String
getOneTimeKey
(
Map
<
String
,
Map
<
String
,
String
>>
aIdentityKeys
Map
,
int
aKeyPosition
)
{
String
firstOneTimeKey
=
null
;
int
i
=
0
;
try
{
JSONObject
generatedKeys
=
aIdentityKeys
Obj
.
getJSONObjec
t
(
OlmAccount
.
JSON_KEY_ONE_TIME_KEY
);
Map
<
String
,
String
>
generatedKeys
=
aIdentityKeys
Map
.
ge
t
(
OlmAccount
.
JSON_KEY_ONE_TIME_KEY
);
assertNotNull
(
OlmAccount
.
JSON_KEY_ONE_TIME_KEY
+
" object is missing"
,
generatedKeys
);
Iterator
<
String
>
generatedKeysIt
=
generatedKeys
.
keys
();
while
(
i
<
aKeyPosition
)
{
if
(
generatedKeysIt
.
hasNext
())
{
firstOneTimeKey
=
generatedKeys
.
getString
(
generatedKeysIt
.
next
());
i
++;
}
}
}
catch
(
JSONException
e
)
{
firstOneTimeKey
=
(
new
ArrayList
<>(
generatedKeys
.
values
())).
get
(
aKeyPosition
-
1
);
}
catch
(
Exception
e
)
{
assertTrue
(
"Exception Msg="
+
e
.
getMessage
(),
false
);
}
return
firstOneTimeKey
;
...
...
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
View file @
d741c012
...
...
@@ -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.<br>
...
...
@@ -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 arra
y.<br>
* Return the identity keys (identity and fingerprint keys) in a
dictionar
y.<br>
* Public API for {@link #identityKeysJni()}.<br>
* Ex:<tt>
* {
* "curve25519":"Vam++zZPMqDQM6ANKpO/uAl5ViJSHxV9hd+b0/fwRAg",
* "ed25519":"+v8SOlOASFTMrX3MCKBM4iVnYoZ+JIjpNt1fi8Z9O2I"
* }</tt>
* @return identity keys
in JSON arra
y if operation succeed, null otherwise
* @return identity keys
dictionar
y if operation succeed
s
, null otherwise
*/
public
JSONObject
identityKeys
()
{
public
Map
<
String
,
String
>
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).<br>
...
...
@@ -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 arra
y.<br>
* Return the "one time keys" in a
dictionar
y.<br>
* The number of "one time keys", is specified by {@link #generateOneTimeKeys(int)}<br>
* Ex:<tt>
* { "curve25519":
...
...
@@ -295,9 +298,9 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
* }</tt><br>
* Public API for {@link #oneTimeKeysJni()}.<br>
* 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
<
String
,
Map
<
String
,
String
>>
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.<br>
...
...
@@ -373,4 +376,65 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
public
int
getUnreleasedCount
()
{
return
mUnreleasedCount
;
}
/**
* Build a string-string dictionary from a jsonObject.<br>
* @param jsonObject the object to parse
* @return the map
*/
private
static
Map
<
String
,
String
>
toStringMap
(
JSONObject
jsonObject
)
{
if
(
null
!=
jsonObject
)
{
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
Iterator
<
String
>
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.<br>
* @param jsonObject the object to parse
* @return the map
*/
private
static
Map
<
String
,
Map
<
String
,
String
>>
toStringMapMap
(
JSONObject
jsonObject
)
{
if
(
null
!=
jsonObject
)
{
HashMap
<
String
,
Map
<
String
,
String
>>
map
=
new
HashMap
<>();
Iterator
<
String
>
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
;
}
}
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
View file @
d741c012
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment