From 2cace25fba3d0606540f0c187f77f3b979af195b Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Wed, 17 Oct 2018 22:29:01 -0400 Subject: add functions for dealing with private keys directly --- .../androidTest/java/org/matrix/olm/OlmPkTest.java | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'android/olm-sdk/src/androidTest') 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()); + } } -- cgit v1.2.3