
10 changed files with 160 additions and 393 deletions
@ -1,28 +0,0 @@ |
|||||
package foundation.pEp.jniadapter; |
|
||||
|
|
||||
import java.util.ArrayList; |
|
||||
import java.util.Vector; |
|
||||
|
|
||||
final public class Engine extends AbstractEngine { |
|
||||
public Engine() throws pEpException { } |
|
||||
|
|
||||
public native Message encrypt_message( |
|
||||
Message src, |
|
||||
ArrayList<String> extra, |
|
||||
Message.EncFormat enc_format |
|
||||
) throws pEpException; |
|
||||
|
|
||||
public class DecryptResult { |
|
||||
public Message dst; |
|
||||
public Color color; |
|
||||
} |
|
||||
|
|
||||
public native DecryptResult decrypt_message( |
|
||||
Message src, |
|
||||
ArrayList<String> keylist |
|
||||
) throws pEpException; |
|
||||
|
|
||||
public native Color outgoing_message_color( |
|
||||
Message msg |
|
||||
) throws pEpException; |
|
||||
} |
|
@ -1,218 +0,0 @@ |
|||||
package foundation.pEp.jniadapter; |
|
||||
|
|
||||
import java.util.ArrayList; |
|
||||
import java.util.Vector; |
|
||||
import java.util.Date; |
|
||||
import java.util.HashMap; |
|
||||
|
|
||||
public class Message implements AutoCloseable { |
|
||||
private final long handle; |
|
||||
|
|
||||
native long init(); |
|
||||
native void release(long handle); |
|
||||
|
|
||||
public Message() { |
|
||||
handle = init(); |
|
||||
} |
|
||||
|
|
||||
public final void close() { |
|
||||
release(handle); |
|
||||
} |
|
||||
|
|
||||
public enum TextFormat { |
|
||||
Plain (0), |
|
||||
Html (1), |
|
||||
Other (255) |
|
||||
; |
|
||||
|
|
||||
static class Management { |
|
||||
public static final HashMap<Integer, TextFormat> tag = |
|
||||
new HashMap<Integer, TextFormat>(); |
|
||||
} |
|
||||
|
|
||||
public final int value; |
|
||||
|
|
||||
TextFormat(int value) { |
|
||||
this.value = value; |
|
||||
fill(value); |
|
||||
} |
|
||||
|
|
||||
private void fill(int value) { |
|
||||
Management.tag.put(value, this); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public enum Direction { |
|
||||
Incoming (0), |
|
||||
Outgoing (1) |
|
||||
; |
|
||||
|
|
||||
static class Management { |
|
||||
public static final HashMap<Integer, Direction> tag = |
|
||||
new HashMap<Integer, Direction>(); |
|
||||
} |
|
||||
|
|
||||
public final int value; |
|
||||
|
|
||||
Direction(int value) { |
|
||||
this.value = value; |
|
||||
fill(value); |
|
||||
} |
|
||||
|
|
||||
private void fill(int value) { |
|
||||
Management.tag.put(value, this); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public enum EncFormat { |
|
||||
None (0), |
|
||||
Pieces (1), |
|
||||
SMIME (2), |
|
||||
PGPMIME (3), |
|
||||
PEP (4) |
|
||||
; |
|
||||
|
|
||||
static class Management { |
|
||||
public static final HashMap<Integer, EncFormat> tag = |
|
||||
new HashMap<Integer, EncFormat>(); |
|
||||
} |
|
||||
|
|
||||
public final int value; |
|
||||
|
|
||||
EncFormat(int value) { |
|
||||
this.value = value; |
|
||||
fill(value); |
|
||||
} |
|
||||
|
|
||||
private void fill(int value) { |
|
||||
Management.tag.put(value, this); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private native int _getDir(); |
|
||||
private native void _setDir(int value); |
|
||||
public Direction getDir() { |
|
||||
return Direction.tag.get(_getDir()); |
|
||||
} |
|
||||
public void setDir(Direction value) { |
|
||||
_setDir(value.value); |
|
||||
} |
|
||||
|
|
||||
private native byte[] _getId(); |
|
||||
private native void _setId(byte[] value); |
|
||||
public String getId() { |
|
||||
return AbstractEngine.toUTF16(_getId()); |
|
||||
} |
|
||||
public void setId(String value) { |
|
||||
_setId(AbstractEngine.toUTF8(value)); |
|
||||
} |
|
||||
|
|
||||
private native byte[] _getShortmsg(); |
|
||||
private native void _setShortmsg(byte[] value); |
|
||||
public String getShortmsg() { |
|
||||
return AbstractEngine.toUTF16(_getShortmsg()); |
|
||||
} |
|
||||
public void setShortmsg(String value) { |
|
||||
_setShortmsg(AbstractEngine.toUTF8(value)); |
|
||||
} |
|
||||
|
|
||||
private native byte[] _getLongmsg(); |
|
||||
private native void _setLongmsg(byte[] value); |
|
||||
public String getLongmsg() { |
|
||||
return AbstractEngine.toUTF16(_getLongmsg()); |
|
||||
} |
|
||||
public void setLongmsg(String value) { |
|
||||
_setLongmsg(AbstractEngine.toUTF8(value)); |
|
||||
} |
|
||||
|
|
||||
private native byte[] _getLongmsgFormatted(); |
|
||||
private native void _setLongmsgFormatted(byte[] value); |
|
||||
public String getLongmsgFormatted() { |
|
||||
return AbstractEngine.toUTF16(_getLongmsgFormatted()); |
|
||||
} |
|
||||
public void setLongmsgFormatted(String value) { |
|
||||
_setLongmsgFormatted(AbstractEngine.toUTF8(value)); |
|
||||
} |
|
||||
|
|
||||
public native ArrayList<Blob> getAttachments(); |
|
||||
public native void setAttachments(ArrayList<Blob> value); |
|
||||
|
|
||||
public native Date getSent(); |
|
||||
public native void setSent(Date value); |
|
||||
|
|
||||
public native Date getRecv(); |
|
||||
public native void setRecv(Date value); |
|
||||
|
|
||||
private native AbstractEngine._Identity _getFrom(); |
|
||||
private native void _setFrom(AbstractEngine._Identity value); |
|
||||
public Identity getFrom() { |
|
||||
return new _getFrom().getIdentity(); |
|
||||
} |
|
||||
public void setFrom(Identity value) { |
|
||||
_setFrom(new AbstractEngine._Identity(value)); |
|
||||
} |
|
||||
|
|
||||
public native ArrayList<Identity> getTo(); |
|
||||
public native void setTo(ArrayList<Identity> value); |
|
||||
|
|
||||
public native Identity getRecvBy(); |
|
||||
public native void setRecvBy(Identity value); |
|
||||
|
|
||||
public native ArrayList<Identity> getCc(); |
|
||||
public native void setCc(ArrayList<Identity> value); |
|
||||
|
|
||||
public native ArrayList<Identity> getBcc(); |
|
||||
public native void setBcc(ArrayList<Identity> value); |
|
||||
|
|
||||
public native ArrayList<Identity> getReplyTo(); |
|
||||
public native void setReplyTo(ArrayList<Identity> value); |
|
||||
|
|
||||
private native ArrayList<byte[]> _getInReplyTo(); |
|
||||
private native void _setInReplyTo(ArrayList<byte[]> value); |
|
||||
public ArrayList<String> getInReplyTo() { |
|
||||
return AbstractEngine.toUTF16(_getInReplyTo()); |
|
||||
} |
|
||||
public void setInReplyTo(ArrayList<String> value) { |
|
||||
_setInReplyTo(AbstractEngine.toUTF8(value)); |
|
||||
} |
|
||||
|
|
||||
private native ArrayList<byte[]> _getReferences(); |
|
||||
private native void _setReferences(ArrayList<byte[]> value); |
|
||||
public ArrayList<String> getReferences() { |
|
||||
return AbstractEngine.toUTF16(_getReferences()); |
|
||||
} |
|
||||
public void setReferences(ArrayList<String> value) { |
|
||||
_setReferences(AbstractEngine.toUTF8(value)); |
|
||||
} |
|
||||
|
|
||||
private native ArrayList<byte[]> _getKeywords(); |
|
||||
private native void _setKeywords(ArrayList<byte[]> value); |
|
||||
public ArrayList<String> getKeywords() { |
|
||||
return AbstractEngine.toUTF16(_getKeywords()); |
|
||||
} |
|
||||
public void setKeywords(ArrayList<String> value) { |
|
||||
_setKeywords(AbstractEngine.toUTF8(value)); |
|
||||
} |
|
||||
|
|
||||
private native byte[] _getComments(); |
|
||||
private native void _setComments(byte[] value); |
|
||||
public String getComments() { |
|
||||
return AbstractEngine.toUTF16(_getComments()); |
|
||||
} |
|
||||
public void setComments(String value) { |
|
||||
_setComments(AbstractEngine.toUTF8(value)); |
|
||||
} |
|
||||
|
|
||||
private native Vector<Pair<byte[], byte[]>> _getOptFields(); |
|
||||
private native void _setOptFields(Vector<Pair<byte[], byte[]>> value); |
|
||||
public Vector<Pair<String, String>> getOptFields() { |
|
||||
return AbstractEngine.toUTF16(_getOptFields()); |
|
||||
} |
|
||||
public void setOptFields(Vector<Pair<String, String>> value) { |
|
||||
_setOptFields(AbstractEngine.toUTF8(value)); |
|
||||
} |
|
||||
|
|
||||
public native Message.EncFormat getEncFormat(); |
|
||||
public native void setEncFormat(Message.EncFormat value); |
|
||||
|
|
||||
} |
|
@ -0,0 +1,115 @@ |
|||||
|
package foundation.pEp.jniadapter; |
||||
|
|
||||
|
import java.io.UnsupportedEncodingException; |
||||
|
import java.text.Normalizer; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.Vector; |
||||
|
|
||||
|
public class Utils { |
||||
|
private Utils() { } |
||||
|
|
||||
|
public static byte[] toUTF8(String str) { |
||||
|
if (str == null) |
||||
|
return null; |
||||
|
|
||||
|
try { |
||||
|
String _str = Normalizer.normalize(str, Normalizer.Form.NFC); |
||||
|
byte _buf[] = _str.getBytes("UTF-8"); |
||||
|
byte _cpy[] = new byte[_buf.length]; |
||||
|
System.arraycopy(_buf,0,_cpy,0,_buf.length); |
||||
|
return _cpy; |
||||
|
} |
||||
|
catch (UnsupportedEncodingException e) { |
||||
|
assert false; |
||||
|
return new byte[0]; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
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++) |
||||
|
result.add(toUTF8(list.get(i))); |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
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); |
||||
|
result.second = toUTF8(pair.second); |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
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++) |
||||
|
result.set(i, toUTF8(list.get(i))); |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public static String toUTF16(byte[] utf8) { |
||||
|
if (utf8 == null) |
||||
|
return null; |
||||
|
|
||||
|
try { |
||||
|
byte newUtf8[] = new byte[utf8.length]; |
||||
|
System.arraycopy(utf8,0,newUtf8,0,utf8.length); |
||||
|
|
||||
|
return new String(newUtf8, "UTF-8"); |
||||
|
} |
||||
|
catch (UnsupportedEncodingException e) { |
||||
|
assert false; |
||||
|
return new String(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
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++) |
||||
|
result.add(toUTF16(list.get(i))); |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
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); |
||||
|
result.second = toUTF16(pair.second); |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
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++) |
||||
|
result.set(i, toUTF16(list.get(i))); |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue