diff options
Diffstat (limited to 'android/olm-sdk/src/main/java/org')
-rw-r--r-- | android/olm-sdk/src/main/java/org/matrix/olm/OlmException.java | 2 | ||||
-rw-r--r-- | android/olm-sdk/src/main/java/org/matrix/olm/OlmPkDecryption.java | 23 |
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; |