Skip to content

Instantly share code, notes, and snippets.

@joshjdevl
Created January 3, 2015 15:48
Show Gist options
  • Select an option

  • Save joshjdevl/97e755519896ccd1672c to your computer and use it in GitHub Desktop.

Select an option

Save joshjdevl/97e755519896ccd1672c to your computer and use it in GitHub Desktop.
sodium
/* example.i */
%module SodiumJni
%include "typemaps.i"
%include "stdint.i"
%include "arrays_java.i"
%include "carrays.i"
%include "various.i"
%apply int {unsigned long long};
%typemap(jni) unsigned char *"jbyteArray"
%typemap(jtype) unsigned char *"byte[]"
%typemap(jstype) unsigned char *"byte[]"
%typemap(in) unsigned char *{
$1 = (unsigned char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) unsigned char *{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) unsigned char *"$javainput"
/* Prevent default freearg typemap from being used */
%typemap(freearg) unsigned char *""
/* char types */
%typemap(jni) char *BYTE "jbyteArray"
%typemap(jtype) char *BYTE "byte[]"
%typemap(jstype) char *BYTE "byte[]"
%typemap(in) char *BYTE {
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) char *BYTE {
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) char *BYTE "$javainput"
/* Prevent default freearg typemap from being used */
%typemap(freearg) char *BYTE ""
/* ***************************** */
/*
%typemap(jni) unsigned char* "jbyteArray"
%typemap(jtype) unsigned char* "byte[]"
%typemap(jstype) unsigned char* "byte[]"
*/
%{
/* Put header files here or function declarations like below */
#include "sodium.h"
%}
const char *sodium_version_string(void);
int
crypto_hash_sha256_ref(unsigned char *out, const unsigned char *in,
unsigned long long inlen);
void foo(char *array);
void foo2(unsigned char *array);
rm *.java
rm *.c
rm *.so
swig -java sodium.i
swig -java -package org.abstractj.kalium -outdir /media/josh/data/research/secureimage/kalium-jni/kalium-jni/src/main/java/org/abstractj/kalium sodium.i
gcc sodium_wrap.c -shared -fPIC -L/usr/lib -lsodium -o libtestjni.so
sudo rm /usr/lib/libtestjni.so
sudo cp libtestjni.so /usr/lib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment