diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2018-10-17 22:29:01 -0400 |
---|---|---|
committer | Hubert Chathi <hubert@uhoreg.ca> | 2018-10-19 12:10:36 -0400 |
commit | 2cace25fba3d0606540f0c187f77f3b979af195b (patch) | |
tree | e8e1491cd874245140af3b0b99fbe103edd12a6d /android/olm-sdk/src/androidTest | |
parent | 1c7ff7f48d121ea1108eec2247a34aaec2906e61 (diff) |
add functions for dealing with private keys directly
Diffstat (limited to 'android/olm-sdk/src/androidTest')
-rw-r--r-- | android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmPkTest.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmPkTest.java b/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmPkTest.java index 04b2217..1577f3b 100644 --- a/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmPkTest.java +++ b/android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmPkTest.java @@ -19,6 +19,8 @@ package org.matrix.olm; import android.support.test.runner.AndroidJUnit4; import android.util.Log; +import java.util.Arrays; + import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; @@ -91,4 +93,46 @@ public class OlmPkTest { assertTrue(mOlmPkEncryption.isReleased()); assertTrue(mOlmPkDecryption.isReleased()); } + + @Test + public void test02PrivateKey() { + try { + mOlmPkDecryption = new OlmPkDecryption(); + } catch (OlmException e) { + e.printStackTrace(); + assertTrue("OlmPkEncryption failed " + e.getMessage(), false); + } + + assertNotNull(mOlmPkDecryption); + + byte[] privateKey = { + (byte)0x77, (byte)0x07, (byte)0x6D, (byte)0x0A, + (byte)0x73, (byte)0x18, (byte)0xA5, (byte)0x7D, + (byte)0x3C, (byte)0x16, (byte)0xC1, (byte)0x72, + (byte)0x51, (byte)0xB2, (byte)0x66, (byte)0x45, + (byte)0xDF, (byte)0x4C, (byte)0x2F, (byte)0x87, + (byte)0xEB, (byte)0xC0, (byte)0x99, (byte)0x2A, + (byte)0xB1, (byte)0x77, (byte)0xFB, (byte)0xA5, + (byte)0x1D, (byte)0xB9, (byte)0x2C, (byte)0x2A + }; + + try { + mOlmPkDecryption.setPrivateKey(privateKey); + } catch (OlmException e) { + assertTrue("Exception in setPrivateKey, Exception code=" + e.getExceptionCode(), false); + } + + byte[] privateKeyCopy = null; + + try { + privateKeyCopy = mOlmPkDecryption.privateKey(); + } catch (OlmException e) { + assertTrue("Exception in privateKey, Exception code=" + e.getExceptionCode(), false); + } + + assertTrue(Arrays.equals(privateKey, privateKeyCopy)); + + mOlmPkDecryption.releaseDecryption(); + assertTrue(mOlmPkDecryption.isReleased()); + } } |