Add getRandomKey()
This commit is contained in:
parent
fb87d8feee
commit
700b02589c
1 changed files with 17 additions and 5 deletions
|
@ -20,10 +20,14 @@ import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class OlmUtility implements Serializable {
|
public class OlmUtility {
|
||||||
private static final String LOG_TAG = "OlmUtility";
|
private static final String LOG_TAG = "OlmUtility";
|
||||||
|
|
||||||
|
public static final int RANDOM_KEY_SIZE = 32;
|
||||||
|
public static final int RANDOM_RANGE = 256;
|
||||||
|
|
||||||
/** raw pointer value returned by JNI.
|
/** raw pointer value returned by JNI.
|
||||||
* this value uniquely identifies this utility instance.
|
* this value uniquely identifies this utility instance.
|
||||||
**/
|
**/
|
||||||
|
@ -128,9 +132,17 @@ public class OlmUtility implements Serializable {
|
||||||
private native String sha256Jni(String aMessage);
|
private native String sha256Jni(String aMessage);
|
||||||
|
|
||||||
|
|
||||||
// TODO missing API: initWithSerializedData
|
public static String getRandomKey() {
|
||||||
// TODO missing API: serializeDataWithKey
|
String keyRetValue;
|
||||||
// TODO missing API: initWithCoder
|
Random rand = new Random();
|
||||||
// TODO missing API: encodeWithCoder
|
StringBuilder strBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
for(int i = 0; i< RANDOM_KEY_SIZE; i++) {
|
||||||
|
strBuilder.append(rand.nextInt(RANDOM_RANGE));
|
||||||
|
}
|
||||||
|
keyRetValue = strBuilder.toString();
|
||||||
|
|
||||||
|
return keyRetValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue