Browse Source

testcase encryption

JNI-44
Volker Birk 10 years ago
parent
commit
09ea0e6cb5
  1. 24
      src/org/pEp/jniadapter/AbstractEngine.java
  2. 11
      test/Testing.java

24
src/org/pEp/jniadapter/AbstractEngine.java

@ -34,6 +34,9 @@ abstract class AbstractEngine implements AutoCloseable {
public native void stopKeyserverLookup();
public static byte[] toUTF8(String str) {
if (str == null)
return null;
try {
String _str = Normalizer.normalize(str, Normalizer.Form.NFC);
return _str.getBytes("UTF-8");
@ -45,6 +48,9 @@ abstract class AbstractEngine implements AutoCloseable {
}
public static Vector<byte[]> toUTF8(Vector<String> list) {
if (list == null)
return null;
Vector<byte[]> result = new Vector<byte[]>(list.size());
for (int i=0; i<list.size(); i++)
@ -54,6 +60,9 @@ abstract class AbstractEngine implements AutoCloseable {
}
public static Pair<byte[], byte[]> toUTF8(Pair<String, String> pair) {
if (pair == null)
return null;
Pair<byte[], byte[]> result = new Pair<byte[], byte[]>();
result.first = toUTF8(pair.first);
@ -63,6 +72,9 @@ abstract class AbstractEngine implements AutoCloseable {
}
public static ArrayList<Pair<byte[], byte[]>> toUTF8(ArrayList<Pair<String, String>> list) {
if (list == null)
return null;
ArrayList<Pair<byte[], byte[]>> result = new ArrayList<Pair<byte[], byte[]>>(list.size());
for (int i=0; i<list.size(); i++)
@ -72,6 +84,9 @@ abstract class AbstractEngine implements AutoCloseable {
}
public static String toUTF16(byte[] utf8) {
if (utf8 == null)
return null;
try {
return new String(utf8, "UTF-8");
}
@ -82,6 +97,9 @@ abstract class AbstractEngine implements AutoCloseable {
}
public static Vector<String> toUTF16(Vector<byte[]> list) {
if (list == null)
return null;
Vector<String> result = new Vector<String>(list.size());
for (int i=0; i<list.size(); i++)
@ -91,6 +109,9 @@ abstract class AbstractEngine implements AutoCloseable {
}
public static Pair<String, String> toUTF16(Pair<byte[], byte[]> pair) {
if (pair == null)
return null;
Pair<String, String> result = new Pair<String,String>();
result.first = toUTF16(pair.first);
@ -100,6 +121,9 @@ abstract class AbstractEngine implements AutoCloseable {
}
public static ArrayList<Pair<String, String>> toUTF16(ArrayList<Pair<byte[], byte[]>> list) {
if (list == null)
return null;
ArrayList<Pair<String, String>> result = new ArrayList<Pair<String, String>>(list.size());
for (int i=0; i<list.size(); i++)

11
test/Testing.java

@ -39,6 +39,17 @@ class Testing {
to1.address = "vb@pep-project.org";
to.add(to1);
msg.setTo(to);
msg.setShortmsg("hello, world");
msg.setLongmsg("this is a test");
try {
Message enc = e.encrypt_message(msg, null);
System.out.println("encrypted");
}
catch (pEpException ex) {
System.out.println("cannot encrypt");
}
}
}

Loading…
Cancel
Save