aboutsummaryrefslogtreecommitdiff
path: root/android/olm-sdk/src/main/java/org/matrix
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2018-10-17 22:29:01 -0400
committerHubert Chathi <hubert@uhoreg.ca>2018-10-19 12:10:36 -0400
commit2cace25fba3d0606540f0c187f77f3b979af195b (patch)
treee8e1491cd874245140af3b0b99fbe103edd12a6d /android/olm-sdk/src/main/java/org/matrix
parent1c7ff7f48d121ea1108eec2247a34aaec2906e61 (diff)
add functions for dealing with private keys directly
Diffstat (limited to 'android/olm-sdk/src/main/java/org/matrix')
-rw-r--r--android/olm-sdk/src/main/java/org/matrix/olm/OlmException.java2
-rw-r--r--android/olm-sdk/src/main/java/org/matrix/olm/OlmPkDecryption.java23
2 files changed, 25 insertions, 0 deletions
diff --git a/android/olm-sdk/src/main/java/org/matrix/olm/OlmException.java b/android/olm-sdk/src/main/java/org/matrix/olm/OlmException.java
index 31b5729..5b534d5 100644
--- a/android/olm-sdk/src/main/java/org/matrix/olm/OlmException.java
+++ b/android/olm-sdk/src/main/java/org/matrix/olm/OlmException.java
@@ -68,6 +68,8 @@ public class OlmException extends IOException {
public static final int EXCEPTION_CODE_PK_DECRYPTION_CREATION = 700;
public static final int EXCEPTION_CODE_PK_DECRYPTION_GENERATE_KEY = 701;
public static final int EXCEPTION_CODE_PK_DECRYPTION_DECRYPT = 702;
+ public static final int EXCEPTION_CODE_PK_DECRYPTION_SET_PRIVATE_KEY = 703;
+ public static final int EXCEPTION_CODE_PK_DECRYPTION_PRIVATE_KEY = 704;
// exception human readable messages
public static final String EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION = "invalid de-serialized parameters";
diff --git a/android/olm-sdk/src/main/java/org/matrix/olm/OlmPkDecryption.java b/android/olm-sdk/src/main/java/org/matrix/olm/OlmPkDecryption.java
index 1a33547..6522f70 100644
--- a/android/olm-sdk/src/main/java/org/matrix/olm/OlmPkDecryption.java
+++ b/android/olm-sdk/src/main/java/org/matrix/olm/OlmPkDecryption.java
@@ -51,6 +51,18 @@ public class OlmPkDecryption {
return (0 == mNativeId);
}
+ public String setPrivateKey(byte[] privateKey) throws OlmException {
+ try {
+ byte[] key = setPrivateKeyJni(privateKey);
+ return new String(key, "UTF-8");
+ } catch (Exception e) {
+ Log.e(LOG_TAG, "## setPrivateKey(): failed " + e.getMessage());
+ throw new OlmException(OlmException.EXCEPTION_CODE_PK_DECRYPTION_SET_PRIVATE_KEY, e.getMessage());
+ }
+ }
+
+ private native byte[] setPrivateKeyJni(byte[] privateKey);
+
public String generateKey() throws OlmException {
try {
byte[] key = generateKeyJni();
@@ -63,6 +75,17 @@ public class OlmPkDecryption {
private native byte[] generateKeyJni();
+ public byte[] privateKey() throws OlmException {
+ try {
+ return privateKeyJni();
+ } catch (Exception e) {
+ Log.e(LOG_TAG, "## privateKey(): failed " + e.getMessage());
+ throw new OlmException(OlmException.EXCEPTION_CODE_PK_DECRYPTION_PRIVATE_KEY, e.getMessage());
+ }
+ }
+
+ private native byte[] privateKeyJni();
+
public String decrypt(OlmPkMessage aMessage) throws OlmException {
if (null == aMessage) {
return null;