summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2022-06-03 06:31:09 +0200
committerSven Gothel <[email protected]>2022-06-03 06:31:09 +0200
commitd826f8c14fbb2a4f072ffd681728df4e0ad04c82 (patch)
treee0d078238047b0c4e3d848cb1c32dcdd9feedd13 /java
parentbedec46d83d2ae6c2b2263848952dcf86c9cb569 (diff)
Minor fixes: version.cpp, Java and JNI code to match.
Diffstat (limited to 'java')
-rw-r--r--java/jni/cipherpack/ByteInStream_Feed.cxx3
-rw-r--r--java/jni/cipherpack/CipherpackHelper.cxx4
-rw-r--r--java/jni/cipherpack/CipherpackListener.cxx16
-rw-r--r--java/org/cipherpack/CPFactory.java74
-rw-r--r--java/org/cipherpack/CPUtils.java27
5 files changed, 62 insertions, 62 deletions
diff --git a/java/jni/cipherpack/ByteInStream_Feed.cxx b/java/jni/cipherpack/ByteInStream_Feed.cxx
index c7dcd27..fc864ea 100644
--- a/java/jni/cipherpack/ByteInStream_Feed.cxx
+++ b/java/jni/cipherpack/ByteInStream_Feed.cxx
@@ -42,10 +42,11 @@ using namespace jau::fractions_i64_literals;
*/
jlong Java_org_cipherpack_ByteInStream_Feed_ctorImpl(JNIEnv *env, jobject obj, jstring jid_name, jlong jtimeoutMS) {
try {
+ Environment::env_init();
(void)obj;
// new instance
const std::string id_name = jau::from_jstring_to_string(env, jid_name);
- const jau::fraction_i64 timeout = jtimeoutMS * 1_ms;
+ const jau::fraction_i64 timeout = (int64_t)jtimeoutMS * 1_ms;
jau::shared_ptr_ref<ByteInStream_Feed> ref( new ByteInStream_Feed(id_name, timeout) );
return ref.release_to_jlong();
} catch(...) {
diff --git a/java/jni/cipherpack/CipherpackHelper.cxx b/java/jni/cipherpack/CipherpackHelper.cxx
index c3e9c21..6c258cc 100644
--- a/java/jni/cipherpack/CipherpackHelper.cxx
+++ b/java/jni/cipherpack/CipherpackHelper.cxx
@@ -34,7 +34,7 @@ static const std::string _cryptoConfigClassName("org/cipherpack/CryptoConfig");
static const std::string _cryptoConfigClazzCtorArgs("(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V");
static const std::string _packHeaderClassName("org/cipherpack/PackHeader");
-static const std::string _packHeaderClazzCtorArgs("(Ljava/lang/String;JJLjava/lang/String;IILorg/cipherpack/CryptoConfig;Ljava/lang/String;[Ljava/lang/String;IZ)V");
+static const std::string _packHeaderClazzCtorArgs("(Ljava/lang/String;JJLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/cipherpack/CryptoConfig;Ljava/lang/String;Ljava/util/List;IZ)V");
CryptoConfig jcipherpack::to_CryptoConfig(JNIEnv *env, jobject jccfg) {
std::string pk_type_ = jau::getStringFieldValue(env, jccfg, "pk_type");
@@ -98,7 +98,7 @@ jobject jcipherpack::to_jPackHeader(JNIEnv *env, const PackHeader& ph) {
// final String pversion, final String pversion_parent,
// final CryptoConfig crypto_cfg_,
// final String host_key_fingerprint_,
- // final String[] term_keys_fingerprint_,
+ // final List<String> term_keys_fingerprint_,
// final int term_key_fingerprint_used_idx_,
// final boolean valid_) {
jstring jtarget_path = jau::from_string_to_jstring(env, ph.getTargetPath());
diff --git a/java/jni/cipherpack/CipherpackListener.cxx b/java/jni/cipherpack/CipherpackListener.cxx
index a5e52da..a7af21f 100644
--- a/java/jni/cipherpack/CipherpackListener.cxx
+++ b/java/jni/cipherpack/CipherpackListener.cxx
@@ -33,7 +33,7 @@
using namespace cipherpack;
-static const std::string _notifyErrorMethodArgs("(Lorg/cipherpack/BTAdapter;Lorg/cipherpack/cryptoConfig;Lorg/cipherpack/cryptoConfig;Lorg/cipherpack/cryptoConfig;J)V");
+static const std::string _notifyErrorMethodArgs("(ZLjava/lang/String;)V");
static const std::string _notifyHeaderMethodArgs("(ZLorg/cipherpack/PackHeader;Z)V");
static const std::string _notifyProgressMethodArgs("(ZJJ)V");
static const std::string _notifyEndMethodArgs("(ZLorg/cipherpack/PackHeader;Z)V");
@@ -67,12 +67,12 @@ class JNICipherpackListener : public CipherpackListener {
{
jclass cpListenerClazz = jau::search_class(env, cpListenerObj);
- mNotifyError = jau::search_method(env, cpListenerClazz, "adapterSettingsChanged", _notifyErrorMethodArgs.c_str(), false);
- mNotifyHeader = jau::search_method(env, cpListenerClazz, "discoveringChanged", _notifyHeaderMethodArgs.c_str(), false);
- mNotifyProgress = jau::search_method(env, cpListenerClazz, "deviceFound", _notifyProgressMethodArgs.c_str(), false);
- mNotifyEnd = jau::search_method(env, cpListenerClazz, "deviceUpdated", _notifyEndMethodArgs.c_str(), false);
- mGetSendContent = jau::search_method(env, cpListenerClazz, "deviceConnected", _getSendContentMethodArgs.c_str(), false);
- mContentProcessed = jau::search_method(env, cpListenerClazz, "devicePairingState", _contentProcessedMethodArgs.c_str(), false);
+ mNotifyError = jau::search_method(env, cpListenerClazz, "notifyError", _notifyErrorMethodArgs.c_str(), false);
+ mNotifyHeader = jau::search_method(env, cpListenerClazz, "notifyHeader", _notifyHeaderMethodArgs.c_str(), false);
+ mNotifyProgress = jau::search_method(env, cpListenerClazz, "notifyProgress", _notifyProgressMethodArgs.c_str(), false);
+ mNotifyEnd = jau::search_method(env, cpListenerClazz, "notifyEnd", _notifyEndMethodArgs.c_str(), false);
+ mGetSendContent = jau::search_method(env, cpListenerClazz, "getSendContent", _getSendContentMethodArgs.c_str(), false);
+ mContentProcessed = jau::search_method(env, cpListenerClazz, "contentProcessed", _contentProcessedMethodArgs.c_str(), false);
}
void notifyError(const bool decrypt_mode, const std::string& msg) noexcept override {
@@ -168,6 +168,8 @@ std::atomic<int> JNICipherpackListener::iname_next(0);
*/
jlong Java_org_cipherpack_CipherpackListener_ctorImpl(JNIEnv *env, jobject obj) {
try {
+ Environment::env_init();
+
// new instance
jau::shared_ptr_ref<JNICipherpackListener> ref( new JNICipherpackListener(env, obj) );
diff --git a/java/org/cipherpack/CPFactory.java b/java/org/cipherpack/CPFactory.java
index 5fe8894..d271926 100644
--- a/java/org/cipherpack/CPFactory.java
+++ b/java/org/cipherpack/CPFactory.java
@@ -38,10 +38,10 @@ import java.util.jar.Manifest;
import org.jau.util.VersionUtil;
/**
- * One stop {@link BTManager} API entry point.
+ * Cipherpack Factory, called by automatically to load the native library.
* <p>
* Further provides access to certain property settings,
- * see {@link #DEBUG}, {@link #VERBOSE}, {@link #DEFAULT_BTMODE} and {@link BTManager.Settings}.
+ * see {@link #DEBUG}, {@link #VERBOSE}.
* </p>
*/
public class CPFactory {
@@ -61,7 +61,7 @@ public class CPFactory {
/**
* Verbose logging enabled or disabled.
* <p>
- * System property {@code org.direct_bt.verbose}, boolean, default {@code false}.
+ * System property {@code org.cipherpack.verbose}, boolean, default {@code false}.
* </p>
*/
public static final boolean VERBOSE;
@@ -69,7 +69,7 @@ public class CPFactory {
/**
* Debug logging enabled or disabled.
* <p>
- * System property {@code org.direct_bt.debug}, boolean, default {@code false}.
+ * System property {@code org.cipherpack.debug}, boolean, default {@code false}.
* </p>
*/
public static final boolean DEBUG;
@@ -103,13 +103,13 @@ public class CPFactory {
static {
{
- final String v = System.getProperty("org.direct_bt.debug", "false");
+ final String v = System.getProperty("org.cipherpack.debug", "false");
DEBUG = Boolean.valueOf(v);
}
if( DEBUG ) {
VERBOSE = true;
} else {
- final String v = System.getProperty("org.direct_bt.verbose", "false");
+ final String v = System.getProperty("org.cipherpack.verbose", "false");
VERBOSE = Boolean.valueOf(v);
}
@@ -118,7 +118,7 @@ public class CPFactory {
isJaulibAvail = null != Class.forName("org.jau.sys.PlatformProps", true /* initializeClazz */, CPFactory.class.getClassLoader());
} catch( final Throwable t ) {
if( DEBUG ) {
- System.err.println("BTFactory Caught: "+t.getMessage());
+ System.err.println("CPFactory Caught: "+t.getMessage());
t.printStackTrace();
}
}
@@ -140,7 +140,7 @@ public class CPFactory {
try {
org.jau.pkg.JNIJarLibrary.addNativeJarLibs(new Class<?>[] { CPFactory.class }, null);
} catch (final Exception e0) {
- System.err.println("BTFactory Caught "+e0.getClass().getSimpleName()+": "+e0.getMessage()+", while JNILibLoaderBase.addNativeJarLibs(..)");
+ System.err.println("CPFactory Caught "+e0.getClass().getSimpleName()+": "+e0.getMessage()+", while JNILibLoaderBase.addNativeJarLibs(..)");
if( DEBUG ) {
e0.printStackTrace();
}
@@ -181,10 +181,10 @@ public class CPFactory {
}
}
- // Map all Java properties '[org.]direct_bt.*' and 'direct_bt.*' to native environment.
+ // Map all Java properties '[org.]cipherpack.*' and 'cipherpack.*' to native environment.
try {
if( DEBUG ) {
- System.err.println("BlootoothFactory: Mapping '[org.|jau.]direct_bt.*' properties to native environment");
+ System.err.println("CPFactory: Mapping '[org.|jau.]cipherpack.*' properties to native environment");
}
final Properties props = doPrivileged(new PrivilegedAction<Properties>() {
@Override
@@ -195,8 +195,8 @@ public class CPFactory {
final Enumeration<?> enums = props.propertyNames();
while (enums.hasMoreElements()) {
final String key = (String) enums.nextElement();
- if( key.startsWith("org.direct_bt.") || key.startsWith("jau.direct_bt.") ||
- key.startsWith("direct_bt.") )
+ if( key.startsWith("org.cipherpack.") || key.startsWith("jau.cipherpack.") ||
+ key.startsWith("cipherpack.") )
{
final String value = props.getProperty(key);
if( DEBUG ) {
@@ -211,7 +211,7 @@ public class CPFactory {
}
try {
- final Manifest manifest = getManifest(cl, new String[] { "org.direct_bt" } );
+ final Manifest manifest = getManifest(cl, new String[] { "org.cipherpack" } );
final Attributes mfAttributes = null != manifest ? manifest.getMainAttributes() : null;
// major.minor must match!
@@ -239,9 +239,9 @@ public class CPFactory {
APIVersion = JAPIVersion;
ImplVersion = null != mfAttributes ? mfAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION) : null;
if( VERBOSE ) {
- System.err.println("direct_bt loaded");
- System.err.println("direct_bt java api version "+JAPIVersion);
- System.err.println("direct_bt native api version "+NAPIVersion);
+ System.err.println("Cipherpack loaded");
+ System.err.println("Cipherpack java api version "+JAPIVersion);
+ System.err.println("Cipherpack native api version "+NAPIVersion);
if( null != mfAttributes ) {
final Attributes.Name[] versionAttributeNames = new Attributes.Name[] {
Attributes.Name.SPECIFICATION_TITLE,
@@ -337,7 +337,7 @@ public class CPFactory {
System.err.println(v.getFullManifestInfo(null));
} else {
System.err.println("Full Manifest:");
- final Manifest manifest = getManifest(CPFactory.class.getClassLoader(), new String[] { "org.direct_bt" } );
+ final Manifest manifest = getManifest(CPFactory.class.getClassLoader(), new String[] { "org.cipherpack" } );
final Attributes attr = manifest.getMainAttributes();
final Set<Object> keys = attr.keySet();
final StringBuilder sb = new StringBuilder();
@@ -364,42 +364,12 @@ public class CPFactory {
private native static void setenv(String name, String value, boolean overwrite);
}
-/** \example DBTScanner10.java
- * This Java scanner {@link BTRole::Master} GATT client example uses an event driven workflow
- * and multithreading, i.e. one thread processes each found device when notified.
- * <p>
- * This example represents the recommended utilization of Direct-BT.
- * </p>
- * <p>
- * See `dbt_scanner10.cpp` for invocation examples, since both apps are fully compatible.
- * </p>
- */
-
-/** \example DBTPeripheral00.java
- * This Java peripheral {@link BTRole::Slave} GATT server example uses an event driven workflow.
- * <p>
- * See `dbt_peripheral00.cpp` for invocation examples, since both apps are fully compatible.
- * </p>
- */
-
-/** \example TestDBTClientServer00.java
- * Unit test, trial using actual BT adapter.
- *
- * Basic client and server Bluetooth tests, requiring one BT adapter:
- * - start server advertising
- * - server stop advertising
- * - reuse server-adapter for client-mode discovery (just toggle on/off)
+/** \example Cipherpack.java
+ * This is the commandline version to convert a source from and to a cipherpack, i.e. encrypt and decrypt.
*/
-/** \example TestDBTClientServer10.java
- * Unit test, trial using actual BT adapter.
+/** \example Test01Cipherpack.java
+ * Unit test, testing encrypting to and decrypting from a cipherpack stream using different sources.
*
- * Testing a full Bluetooth server and client lifecycle of operations, requiring two BT adapter:
- * - start server advertising
- * - start client discovery and connect to server when discovered
- * - client/server processing of connection when ready
- * - client disconnect
- * - server stop advertising
- * - security-level: NONE, ENC_ONLY freshly-paired and ENC_ONLY pre-paired
- * - reuse server-adapter for client-mode discovery (just toggle on/off)
+ * Unit test also covers error cases.
*/
diff --git a/java/org/cipherpack/CPUtils.java b/java/org/cipherpack/CPUtils.java
index c1a5daf..368d24f 100644
--- a/java/org/cipherpack/CPUtils.java
+++ b/java/org/cipherpack/CPUtils.java
@@ -24,6 +24,10 @@
package org.cipherpack;
import java.io.PrintStream;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
public class CPUtils {
private static long t0;
@@ -85,4 +89,27 @@ public class CPUtils {
out.printf("[%,9d] %s", elapsedTimeMillis(), msg);
}
+ /**
+ * Convert a non empty list to an array of same type.
+ *
+ * @param <E> the element type of the list
+ * @param list the list instance
+ * @throws IllegalArgumentException if given list instance is empty
+ */
+ @SuppressWarnings("unchecked")
+ public static <E> E[] toArray(final List<E> list) throws IllegalArgumentException {
+ if( 0 == list.size() ) {
+ throw new IllegalArgumentException("Given list is empty");
+ }
+ final Class<E> clazz;
+ {
+ final E e0 = list.get(0);
+ clazz = (Class<E>) e0.getClass();
+ }
+ final E[] res = (E[]) Array.newInstance(clazz, list.size());
+ for(int i=0; i < res.length; ++i) {
+ res[i] = list.get(i);
+ }
+ return res;
+ }
}