[authsaml2] Working java binding
This commit is contained in:
parent
0d6985c7e9
commit
c698c34e93
|
@ -18,10 +18,16 @@ class Myclass{
|
||||||
System.out.println("Group generation...");
|
System.out.println("Group generation...");
|
||||||
PrimeOrderGroup g = new PrimeOrderGroup(256);
|
PrimeOrderGroup g = new PrimeOrderGroup(256);
|
||||||
g.moreBases(5);
|
g.moreBases(5);
|
||||||
|
String[] bases = (String[]) g.getbases();
|
||||||
|
int i;
|
||||||
|
for(i=0;i<5;i++){
|
||||||
|
System.out.println("Base: " + bases[i]);
|
||||||
|
}
|
||||||
System.out.println("Group generation successful.");
|
System.out.println("Group generation successful.");
|
||||||
|
|
||||||
System.out.println("Prover: DLREP to prove generation...");
|
System.out.println("Prover: DLREP to prove generation...");
|
||||||
String dlrep = CrypticJNI.get_dlrep(3,quantities,g.getbases(),g.getp());
|
String dlrep = CrypticJNI.get_dlrep(3,quantities,bases,g.getp());
|
||||||
|
System.out.println("DLREP: " + dlrep);
|
||||||
|
|
||||||
System.out.println("Prover: Proof round1");
|
System.out.println("Prover: Proof round1");
|
||||||
ZkpkSchnorr s = new ZkpkSchnorr(g.getbases(),3,g.getp());
|
ZkpkSchnorr s = new ZkpkSchnorr(g.getbases(),3,g.getp());
|
||||||
|
@ -45,6 +51,15 @@ class Myclass{
|
||||||
private static void test_2(){
|
private static void test_2(){
|
||||||
System.out.println("\n\t############## TEST 2 ##############\n");
|
System.out.println("\n\t############## TEST 2 ##############\n");
|
||||||
|
|
||||||
|
System.out.println("QRG generation...");
|
||||||
|
QRG qrg = new QRG(1024);
|
||||||
|
System.out.println("QRG generated");
|
||||||
|
System.out.println("qrg.getp() : " + qrg.getp());
|
||||||
|
System.out.println("qrg.getn() : " + qrg.getn());
|
||||||
|
System.out.println("qrg.getbase() : " + qrg.getbase());
|
||||||
|
QRG qrg2 = QRG.newLoad(qrg.getp(), qrg.getn(), qrg.getbase());
|
||||||
|
//QRG qrg2 = new QRG(qrg.getp(), qrg.getn(), qrg.getbase());
|
||||||
|
|
||||||
System.out.println("Clsig server generation...");
|
System.out.println("Clsig server generation...");
|
||||||
Clsig c = new Clsig(1024,256,600,0,0,0,10);
|
Clsig c = new Clsig(1024,256,600,0,0,0,10);
|
||||||
c.generateParameters();
|
c.generateParameters();
|
||||||
|
|
|
@ -152,6 +152,9 @@ class Binding:
|
||||||
self.generate_wrapper()
|
self.generate_wrapper()
|
||||||
self.generate_exception_classes()
|
self.generate_exception_classes()
|
||||||
self.generate_cryptic_classes()
|
self.generate_cryptic_classes()
|
||||||
|
###########################
|
||||||
|
self.generate_functions()
|
||||||
|
###########################
|
||||||
|
|
||||||
|
|
||||||
# CrypticConstants
|
# CrypticConstants
|
||||||
|
@ -230,8 +233,10 @@ protected static native void destroy(long cptr);
|
||||||
if is_boolean(vtype):
|
if is_boolean(vtype):
|
||||||
return 'boolean'
|
return 'boolean'
|
||||||
############################
|
############################
|
||||||
elif is_tabbn(vtype) or is_tabint(vtype):
|
elif is_tabbn(vtype):
|
||||||
return 'Object[]'
|
return 'String[]'
|
||||||
|
elif is_tabint(vtype):
|
||||||
|
return 'int[]'
|
||||||
elif is_bn(vtype):
|
elif is_bn(vtype):
|
||||||
return 'String'
|
return 'String'
|
||||||
############################
|
############################
|
||||||
|
@ -261,9 +266,7 @@ protected static native void destroy(long cptr);
|
||||||
# elif vtype in ('const GList*','GList*','GHashTable*'):
|
# elif vtype in ('const GList*','GList*','GHashTable*'):
|
||||||
##################################"
|
##################################"
|
||||||
elif vtype in ('const GList*','GList*','GHashTable*', 'int*', 'BIGNUM**'):
|
elif vtype in ('const GList*','GList*','GHashTable*', 'int*', 'BIGNUM**'):
|
||||||
##################################"
|
|
||||||
return 'Object[]'
|
return 'Object[]'
|
||||||
##################################"
|
|
||||||
elif vtype == 'BIGNUM*':
|
elif vtype == 'BIGNUM*':
|
||||||
return 'String'
|
return 'String'
|
||||||
##################################"
|
##################################"
|
||||||
|
@ -293,17 +296,12 @@ protected static native void destroy(long cptr);
|
||||||
##################################"
|
##################################"
|
||||||
|
|
||||||
def generate_JNI_functions(self, m, fd):
|
def generate_JNI_functions(self, m, fd):
|
||||||
import sys
|
|
||||||
print >> sys.stderr, '%s %s' %(m.name,m.return_type)
|
|
||||||
##################################"
|
|
||||||
#if m.return_type.startswith('Cryptic'):
|
|
||||||
if m.name.endswith('_new'):
|
if m.name.endswith('_new'):
|
||||||
##################################"
|
|
||||||
jtype = 'long'
|
jtype = 'long'
|
||||||
else:
|
else:
|
||||||
jtype = self.JNI_return_type(m.return_type)
|
jtype = self.JNI_return_type(m.return_type)
|
||||||
name = self.JNI_function_name(m)
|
name = self.JNI_function_name(m)
|
||||||
print >> fd, ' public static native %s %s(%s);' % (jtype, name, generate_arg_list3(self,m.args))
|
print >> fd, ' public static native %s %s(%s);' % (jtype,name, generate_arg_list3(self,m.args))
|
||||||
|
|
||||||
def JNI_member_function_prefix(self,c,m):
|
def JNI_member_function_prefix(self,c,m):
|
||||||
#############################"
|
#############################"
|
||||||
|
@ -334,6 +332,18 @@ protected static native void destroy(long cptr);
|
||||||
print >> fd, ' public static native %s[] %s(GObject obj);' % (jtype,name)
|
print >> fd, ' public static native %s[] %s(GObject obj);' % (jtype,name)
|
||||||
name = '%s_set' % prefix
|
name = '%s_set' % prefix
|
||||||
print >> fd, ' public static native void %s(GObject obj, %s[] value);' % (name,jtype)
|
print >> fd, ' public static native void %s(GObject obj, %s[] value);' % (name,jtype)
|
||||||
|
######################################
|
||||||
|
# elif mtype == 'BIGNUM**':
|
||||||
|
# name = '%s_get' % prefix
|
||||||
|
# print >> fd, ' public static native %s[] %s(GObject obj);' % (jtype,name)
|
||||||
|
# name = '%s_set' % prefix
|
||||||
|
# print >> fd, ' public static native void %s(GObject obj, %s[] value);' % (name,jtype)
|
||||||
|
# elif mtype == 'int*':
|
||||||
|
# name = '%s_get' % prefix
|
||||||
|
# print >> fd, ' public static native %s[] %s(GObject obj);' % (jtype,name)
|
||||||
|
# name = '%s_set' % prefix
|
||||||
|
# print >> fd, ' public static native void %s(GObject obj, %s[] value);' % (name,jtype)
|
||||||
|
######################################
|
||||||
else:
|
else:
|
||||||
name = '%s_get' % prefix
|
name = '%s_get' % prefix
|
||||||
print >> fd, ' public static native %s %s(GObject obj);' % (jtype,name)
|
print >> fd, ' public static native %s %s(GObject obj);' % (jtype,name)
|
||||||
|
@ -413,11 +423,11 @@ protected static native void destroy(long cptr);
|
||||||
elif is_cstring(type):
|
elif is_cstring(type):
|
||||||
return 'jstring'
|
return 'jstring'
|
||||||
#######################################"""
|
#######################################"""
|
||||||
|
elif is_glist(type) or is_hashtable(type) or is_tabbn(type) or is_tabint(type):
|
||||||
|
return 'jobjectArray'
|
||||||
elif is_bn(type):
|
elif is_bn(type):
|
||||||
return 'jstring'
|
return 'jstring'
|
||||||
elif is_glist(type) or is_hashtable(type) or is_tabbn(type) or is_tabint(type):
|
|
||||||
#######################################"""
|
#######################################"""
|
||||||
return 'jobjectArray'
|
|
||||||
elif is_xml_node(type):
|
elif is_xml_node(type):
|
||||||
return 'jstring'
|
return 'jstring'
|
||||||
elif is_object(type):
|
elif is_object(type):
|
||||||
|
@ -473,7 +483,8 @@ protected static native void destroy(long cptr);
|
||||||
return 'jstring_to_string(env, %s, (char**)&%s);' % (right,left)
|
return 'jstring_to_string(env, %s, (char**)&%s);' % (right,left)
|
||||||
####################
|
####################
|
||||||
elif is_tabbn(type):
|
elif is_tabbn(type):
|
||||||
return 'set_list_of_bn(env, &%s,%s);' % (left,right)
|
# return 'set_list_of_bn(env, &%s,%s);' % (left,right)
|
||||||
|
return '%s = set_list_of_bn(env, %s);' % (left,right)
|
||||||
elif is_bn(type):
|
elif is_bn(type):
|
||||||
return 'jstring_to_bignum(env, %s, (BIGNUM**)&%s);' % (right,left)
|
return 'jstring_to_bignum(env, %s, (BIGNUM**)&%s);' % (right,left)
|
||||||
elif is_tabint(type):
|
elif is_tabint(type):
|
||||||
|
@ -526,10 +537,7 @@ protected static native void destroy(long cptr);
|
||||||
# print >> fd, '''static PyObject*
|
# print >> fd, '''static PyObject*
|
||||||
#%s(PyObject *self, PyObject *args)
|
#%s(PyObject *self, PyObject *args)
|
||||||
#{''' % name
|
#{''' % name
|
||||||
##################################"
|
|
||||||
#if m.return_type.startswith('Cryptic'):
|
|
||||||
if m.name.endswith('_new'):
|
if m.name.endswith('_new'):
|
||||||
##################################"
|
|
||||||
jtype = 'jlong'
|
jtype = 'jlong'
|
||||||
else:
|
else:
|
||||||
jtype = self.jni_return_type(m.return_type)
|
jtype = self.jni_return_type(m.return_type)
|
||||||
|
@ -607,10 +615,7 @@ protected static native void destroy(long cptr);
|
||||||
|
|
||||||
# Return
|
# Return
|
||||||
if m.return_type:
|
if m.return_type:
|
||||||
##################################"
|
|
||||||
#if m.return_type.startswith('Cryptic'):
|
|
||||||
if m.name.endswith('_new'):
|
if m.name.endswith('_new'):
|
||||||
##################################"
|
|
||||||
print >> fd, ' r_value = (jlong)(ptrdiff_t) return_value;'
|
print >> fd, ' r_value = (jlong)(ptrdiff_t) return_value;'
|
||||||
else:
|
else:
|
||||||
options = {}
|
options = {}
|
||||||
|
@ -632,6 +637,7 @@ protected static native void destroy(long cptr);
|
||||||
klass = c.name
|
klass = c.name
|
||||||
prefix = self.JNI_member_function_prefix(c,m)
|
prefix = self.JNI_member_function_prefix(c,m)
|
||||||
return_type = self.jni_return_type(m)
|
return_type = self.jni_return_type(m)
|
||||||
|
print 'return_type ' + return_type
|
||||||
signature = wrapper_decl("%s_get" % prefix, return_type)
|
signature = wrapper_decl("%s_get" % prefix, return_type)
|
||||||
field = 'gobj->%s' % name
|
field = 'gobj->%s' % name
|
||||||
d = locals()
|
d = locals()
|
||||||
|
@ -730,7 +736,10 @@ protected static native void destroy(long cptr);
|
||||||
|
|
||||||
def generate_wrapper_getter_setter(self, c, fd):
|
def generate_wrapper_getter_setter(self, c, fd):
|
||||||
klassname = c.name
|
klassname = c.name
|
||||||
|
print klassname
|
||||||
for m in c.members:
|
for m in c.members:
|
||||||
|
print m
|
||||||
|
print m[0]
|
||||||
# getter
|
# getter
|
||||||
self.generate_wrapper_getter(c, m, fd)
|
self.generate_wrapper_getter(c, m, fd)
|
||||||
self.generate_wrapper_setter(c, m, fd)
|
self.generate_wrapper_setter(c, m, fd)
|
||||||
|
@ -738,6 +747,7 @@ protected static native void destroy(long cptr);
|
||||||
prefix = self.JNI_member_function_prefix(c,m)
|
prefix = self.JNI_member_function_prefix(c,m)
|
||||||
jtype = self.jni_return_type(mtype)
|
jtype = self.jni_return_type(mtype)
|
||||||
# add/remove
|
# add/remove
|
||||||
|
print jtype
|
||||||
if is_glist(mtype):
|
if is_glist(mtype):
|
||||||
self.generate_wrapper_adder(c, m, fd)
|
self.generate_wrapper_adder(c, m, fd)
|
||||||
self.generate_wrapper_remover(c, m, fd)
|
self.generate_wrapper_remover(c, m, fd)
|
||||||
|
@ -860,9 +870,6 @@ protected static native void destroy(long cptr);
|
||||||
print >> fd, ' static public %s %s(%s) {' % (class_name, name, generate_arg_list(self,m.args))
|
print >> fd, ' static public %s %s(%s) {' % (class_name, name, generate_arg_list(self,m.args))
|
||||||
print >> fd, ' return (%s) CrypticJNI.%s(%s);' % (class_name, self.JNI_function_name(m),generate_arg_list2(m.args))
|
print >> fd, ' return (%s) CrypticJNI.%s(%s);' % (class_name, self.JNI_function_name(m),generate_arg_list2(m.args))
|
||||||
print >> fd, ' }'
|
print >> fd, ' }'
|
||||||
#print >> fd, ' public %s(%s) {' % (class_name, generate_arg_list(self,m.args))
|
|
||||||
#print >> fd, ' super(CrypticJNI.%s(%s));' % (self.JNI_function_name(m),generate_arg_list2(m.args))
|
|
||||||
#print >> fd, ' }'
|
|
||||||
print >> fd, ' /* Setters and getters */'
|
print >> fd, ' /* Setters and getters */'
|
||||||
for m in c.members:
|
for m in c.members:
|
||||||
type, name, options = m
|
type, name, options = m
|
||||||
|
@ -904,6 +911,22 @@ protected static native void destroy(long cptr);
|
||||||
print >> fd, ' public Map get%s() {' % jname
|
print >> fd, ' public Map get%s() {' % jname
|
||||||
print >> fd, ' return arrayToMap(CrypticJNI.%s_get(this));' % prefix
|
print >> fd, ' return arrayToMap(CrypticJNI.%s_get(this));' % prefix
|
||||||
print >> fd, ' }'
|
print >> fd, ' }'
|
||||||
|
##############################"
|
||||||
|
elif type == 'BIGNUM**':
|
||||||
|
print >> fd, ' public void set%s(String[] value) {' % (jname)
|
||||||
|
print >> fd, ' CrypticJNI.%s_set(this, value);' % prefix
|
||||||
|
print >> fd, ' }'
|
||||||
|
print >> fd, ' public String[] get%s() {' % (jname)
|
||||||
|
print >> fd, ' return CrypticJNI.%s_get(this);' % prefix
|
||||||
|
print >> fd, ' }'
|
||||||
|
elif type == 'int*':
|
||||||
|
print >> fd, ' public void set%s(int[] value) {' % (jname)
|
||||||
|
print >> fd, ' CrypticJNI.%s_set(this, value);' % prefix
|
||||||
|
print >> fd, ' }'
|
||||||
|
print >> fd, ' public int[] get%s() {' % (jname)
|
||||||
|
print >> fd, ' return CrypticJNI.%s_get(this);' % prefix
|
||||||
|
print >> fd, ' }'
|
||||||
|
##############################"
|
||||||
else:
|
else:
|
||||||
print >> fd, ' public void set%s(%s value) {' % (jname,jtype)
|
print >> fd, ' public void set%s(%s value) {' % (jname,jtype)
|
||||||
print >> fd, ' CrypticJNI.%s_set(this, value);' % prefix
|
print >> fd, ' CrypticJNI.%s_set(this, value);' % prefix
|
||||||
|
@ -992,3 +1015,111 @@ protected static native void destroy(long cptr);
|
||||||
print >> fd, ' }'
|
print >> fd, ' }'
|
||||||
print >> fd, '}'
|
print >> fd, '}'
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
|
def generate_functions(self):
|
||||||
|
def method_name(m,class_name):
|
||||||
|
prefix = len(class_name)
|
||||||
|
if m.rename:
|
||||||
|
return m.rename
|
||||||
|
else:
|
||||||
|
#######################"
|
||||||
|
# name = format_as_camelcase(m.name[6:])
|
||||||
|
name = format_as_camelcase(m.name[8:])
|
||||||
|
#######################"
|
||||||
|
name = name[prefix:]
|
||||||
|
return name[0].lower() + name[1:]
|
||||||
|
|
||||||
|
path = cryptic_java_path + 'Functions.java'
|
||||||
|
fd = open(path,'w')
|
||||||
|
print >> fd, 'package %s;' % cryptic_package_name
|
||||||
|
|
||||||
|
print >> fd, 'public class Functions {'
|
||||||
|
print >> fd, ' /* Constructors */'
|
||||||
|
print >> fd, ' public Functions() {'
|
||||||
|
print >> fd, ' }'
|
||||||
|
|
||||||
|
for m in self.binding_data.functions:
|
||||||
|
|
||||||
|
if m.name.endswith('_new') or '_new_' in m.name:
|
||||||
|
continue
|
||||||
|
|
||||||
|
return_type = self.JNI_return_type(m.return_type)
|
||||||
|
jni_name = self.JNI_function_name(m)
|
||||||
|
mname = format_as_camelcase(m.name[8:])
|
||||||
|
args = m.args
|
||||||
|
doc = m.docstring
|
||||||
|
|
||||||
|
|
||||||
|
def normalize(str,first=' * '):
|
||||||
|
wrapper = textwrap.TextWrapper()
|
||||||
|
wrapper.initial_indent = first
|
||||||
|
wrapper.subsequent_indent = ' * '
|
||||||
|
str = re.sub(r'\bNULL\b','null', str)
|
||||||
|
str = re.sub(r'#Cryptic(\w+)',r'{@@link \1}',str)
|
||||||
|
str = re.sub(r'[^.]*must *be *freed *by[^.]*\.?', '', str)
|
||||||
|
str = re.sub(r'[^.]*internally[^.]*\.?[^.]*freed[^.]*\.?', '', str)
|
||||||
|
|
||||||
|
str = re.sub(r'[^.]*\bfreed?\b[^.]*\.?', '', str)
|
||||||
|
str = re.sub(r'(a +)?#?GList\*?','an array', str)
|
||||||
|
return wrapper.fill(re.sub(r'@\b(\w+)\b',r'\1',str))
|
||||||
|
if doc:
|
||||||
|
first = normalize(doc.description, ' /** ')
|
||||||
|
if first:
|
||||||
|
print >> fd, first
|
||||||
|
else:
|
||||||
|
print >> fd, ' /**\n'
|
||||||
|
print >> fd, ' *'
|
||||||
|
for p in doc.parameters:
|
||||||
|
name = p[0]
|
||||||
|
desc = p[1]
|
||||||
|
print >> fd, normalize(desc, ' * @param %s ' % format_as_camelcase(name))
|
||||||
|
if doc.return_value:
|
||||||
|
print >> fd, normalize(doc.return_value, ' * @return ')
|
||||||
|
if m.errors:
|
||||||
|
for err in m.errors:
|
||||||
|
err = error_to_exception(err)[0]
|
||||||
|
print >> fd, normalize(err,' * @throws ')
|
||||||
|
print >> fd, ' **/'
|
||||||
|
outarg = None
|
||||||
|
for a in args:
|
||||||
|
if is_out(a):
|
||||||
|
# only one output arg supported
|
||||||
|
assert not outarg
|
||||||
|
outarg = a
|
||||||
|
if outarg:
|
||||||
|
assert is_int(make_arg(m.return_type), self.binding_data)
|
||||||
|
new_return_type = self.JNI_return_type(var_type(outarg))
|
||||||
|
print >> fd, ' public %s %s(%s) {' % (new_return_type, mname, generate_arg_list(self, args[1:]))
|
||||||
|
print >> fd, ' Object[] output = new Object[1];'
|
||||||
|
print >> fd, ' CrypticException.throwError(CrypticJNI.%s(this, %s));' % (jni_name, generate_arg_list2(args[1:]))
|
||||||
|
print >> fd, ' return (%s)output[0];' % new_return_type
|
||||||
|
print >> fd, ' }'
|
||||||
|
|
||||||
|
elif m.return_type == 'GList*' or m.return_type == 'const GList*':
|
||||||
|
print >> fd, ' public List %s(%s) {' % (mname,generate_arg_list(self,args[1:]))
|
||||||
|
arglist = generate_arg_list2(args[1:])
|
||||||
|
if arglist:
|
||||||
|
arglist = ', ' + arglist
|
||||||
|
print >> fd, ' Object[] arr = CrypticJNI.%s(this%s);' % (jni_name,arglist)
|
||||||
|
print >> fd, ' if (arr != null)'
|
||||||
|
print >> fd, ' return Arrays.asList(arr);'
|
||||||
|
print >> fd, ' else'
|
||||||
|
print >> fd, ' return null;'
|
||||||
|
print >> fd, ' }'
|
||||||
|
else:
|
||||||
|
print >> fd, ' public %s %s(%s) {' % (return_type,mname,generate_arg_list(self,args))
|
||||||
|
print >> fd, ' ',
|
||||||
|
if m.return_type:
|
||||||
|
print >> fd, 'return',
|
||||||
|
arglist = generate_arg_list2(args)
|
||||||
|
if m.errors:
|
||||||
|
print >> fd, 'CrypticException.throwError(',
|
||||||
|
print >> fd,'CrypticJNI.%s(%s)' % (jni_name,arglist),
|
||||||
|
if m.errors:
|
||||||
|
print >> fd, ');'
|
||||||
|
else:
|
||||||
|
print >> fd, ';'
|
||||||
|
print >> fd, ' }'
|
||||||
|
|
||||||
|
print >> fd, '}'
|
||||||
|
fd.close()
|
||||||
|
|
|
@ -82,7 +82,8 @@ G_GNUC_UNUSED static void throw_by_name(JNIEnv *env, const char *name, const cha
|
||||||
|
|
||||||
G_GNUC_UNUSED static int bignum_to_jstring(JNIEnv *env, BIGNUM *bn, jstring *jstr);
|
G_GNUC_UNUSED static int bignum_to_jstring(JNIEnv *env, BIGNUM *bn, jstring *jstr);
|
||||||
G_GNUC_UNUSED static int jstring_to_bignum(JNIEnv *env, jstring jstr, BIGNUM **bn);
|
G_GNUC_UNUSED static int jstring_to_bignum(JNIEnv *env, jstring jstr, BIGNUM **bn);
|
||||||
G_GNUC_UNUSED static int set_list_of_bn(JNIEnv *env, BIGNUM ***list, jobjectArray jarr);
|
//G_GNUC_UNUSED static int set_list_of_bn(JNIEnv *env, BIGNUM ***list, jobjectArray jarr);
|
||||||
|
G_GNUC_UNUSED static BIGNUM** set_list_of_bn(JNIEnv *env, jobjectArray jarr);
|
||||||
G_GNUC_UNUSED static int get_list_of_bn(JNIEnv *env, BIGNUM **list, jobjectArray *jarr);
|
G_GNUC_UNUSED static int get_list_of_bn(JNIEnv *env, BIGNUM **list, jobjectArray *jarr);
|
||||||
#define get_list_of_bignum(env,list,jarr) get_list(env,"java/lang/String",list,(Converter)bignum_to_jstring,jarr)
|
#define get_list_of_bignum(env,list,jarr) get_list(env,"java/lang/String",list,(Converter)bignum_to_jstring,jarr)
|
||||||
#define set_list_of_bignum(env,list,jarr) set_list(env,list,jarr,(GFunc)g_free,(OutConverter)jstring_to_bignum)
|
#define set_list_of_bignum(env,list,jarr) set_list(env,list,jarr,(GFunc)g_free,(OutConverter)jstring_to_bignum)
|
||||||
|
@ -99,8 +100,8 @@ static jint extractInt(JNIEnv *env, jobject arg);
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
bignum_to_jstring(JNIEnv *env, BIGNUM *bn, jstring *jstr) {
|
bignum_to_jstring(JNIEnv *env, BIGNUM *bn, jstring *jstr)
|
||||||
g_error_if_fail(env);
|
{
|
||||||
if (bn) {
|
if (bn) {
|
||||||
char *hex = BN_bn2hex(bn);
|
char *hex = BN_bn2hex(bn);
|
||||||
*jstr = (*env)->NewStringUTF(env, hex);
|
*jstr = (*env)->NewStringUTF(env, hex);
|
||||||
|
@ -109,17 +110,19 @@ bignum_to_jstring(JNIEnv *env, BIGNUM *bn, jstring *jstr) {
|
||||||
} else {
|
} else {
|
||||||
*jstr = NULL;
|
*jstr = NULL;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_list_of_bn(JNIEnv *env, BIGNUM **list, jobjectArray *jarr) {
|
get_list_of_bn(JNIEnv *env, BIGNUM **list, jobjectArray *jarr) {
|
||||||
g_error_if_fail(env);
|
|
||||||
jsize i;
|
jsize i;
|
||||||
jclass cls;
|
jclass cls;
|
||||||
|
|
||||||
g_error_if_fail (env);
|
g_error_if_fail (env);
|
||||||
|
|
||||||
int size = 0;
|
int size = 0;
|
||||||
while(list[size] != NULL) size++;
|
while(list[size] != NULL) size++;
|
||||||
|
|
||||||
cls = get_jclass_by_name(env, "java/lang/String");
|
cls = get_jclass_by_name(env, "java/lang/String");
|
||||||
cryptic_return_val_if_fail(cls, 0);
|
cryptic_return_val_if_fail(cls, 0);
|
||||||
cryptic_return_val_if_fail(create_object_array(env, "java/lang/String", size, jarr), 0);
|
cryptic_return_val_if_fail(create_object_array(env, "java/lang/String", size, jarr), 0);
|
||||||
|
@ -133,70 +136,98 @@ get_list_of_bn(JNIEnv *env, BIGNUM **list, jobjectArray *jarr) {
|
||||||
|
|
||||||
static int
|
static int
|
||||||
jstring_to_bignum(JNIEnv *env, jstring jstr, BIGNUM **bn) {
|
jstring_to_bignum(JNIEnv *env, jstring jstr, BIGNUM **bn) {
|
||||||
g_error_if_fail(env);
|
|
||||||
const char *local_str = NULL;
|
const char *local_str = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
cryptic_return_val_if_fail(jstring_to_local_string(env, jstr, &local_str), 0);
|
cryptic_return_val_if_fail(jstring_to_local_string(env, jstr, &local_str), 0);
|
||||||
if (local_str) {
|
if (local_str) {
|
||||||
if (local_str[0] == '-') {
|
|
||||||
r = BN_hex2bn(bn, local_str);
|
if(local_str[0] == '-'){
|
||||||
BN_set_negative(*bn,1);
|
r = BN_hex2bn(bn, local_str);
|
||||||
} else {
|
BN_set_negative(*bn,1);
|
||||||
r = BN_hex2bn(bn, local_str);
|
}else{
|
||||||
}
|
r = BN_hex2bn(bn, local_str);
|
||||||
|
}
|
||||||
release_local_string(env, jstr, local_str);
|
release_local_string(env, jstr, local_str);
|
||||||
if (r<0 || *bn == NULL) {
|
if (r<0 || *bn == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*bn = NULL;
|
*bn = NULL;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
/*static BIGNUM**
|
||||||
set_list_of_bn(JNIEnv *env, BIGNUM ***list, jobjectArray jarr) {
|
set_list_of_bn(JNIEnv *env, jobjectArray jarr) {
|
||||||
g_error_if_fail(env);
|
|
||||||
jobject element = NULL;
|
jobject element = NULL;
|
||||||
jsize size = 0;
|
jsize size = 0;
|
||||||
jsize i = 0;
|
jsize i = 0;
|
||||||
|
BIGNUM **list;
|
||||||
|
printf("set_list_of_bn\n");
|
||||||
g_error_if_fail (list && env);
|
g_error_if_fail (list && env);
|
||||||
if (jarr) {
|
if (jarr) {
|
||||||
if (! get_array_size(env, jarr, &size)) {
|
if (! get_array_size(env, jarr, &size)){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
list = NULL;
|
list = NULL;
|
||||||
list = (BIGNUM***) g_malloc0(sizeof(BIGNUM***));
|
list = (BIGNUM***) g_malloc0(sizeof(BIGNUM***));
|
||||||
list[0] = NULL;
|
list[0] = NULL;
|
||||||
list[0] = (BIGNUM**) g_malloc0(size*sizeof(BIGNUM**));
|
list[0] = (BIGNUM**) g_malloc0(size*sizeof(BIGNUM**));
|
||||||
for (i=0; i<size; i++) {
|
for (i=0; i<size; i++){
|
||||||
list[0][i] = NULL;
|
list[0][i] = NULL;
|
||||||
if (! get_array_element(env, jarr, i, &element)) {
|
if (! get_array_element(env, jarr, i, &element)){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
jstring_to_bignum(env,element,&list[0][i]);
|
jstring_to_bignum(env,element,&list[0][i]);
|
||||||
|
cryptic_print_bn("",list[0][i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
}*/
|
||||||
|
static BIGNUM**
|
||||||
|
set_list_of_bn(JNIEnv *env, jobjectArray jarr) {
|
||||||
|
jobject element = NULL;
|
||||||
|
jsize size = 0;
|
||||||
|
jsize i = 0;
|
||||||
|
BIGNUM **list;
|
||||||
|
g_error_if_fail (list && env);
|
||||||
|
if (jarr) {
|
||||||
|
if (! get_array_size(env, jarr, &size)){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
list = NULL;
|
||||||
|
list = (BIGNUM**) g_malloc0(size*sizeof(BIGNUM**));
|
||||||
|
for (i=0; i<size; i++){
|
||||||
|
list[i] = NULL;
|
||||||
|
if (! get_array_element(env, jarr, i, &element)){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
jstring_to_bignum(env,element,&list[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
int_to_jint(JNIEnv *env, int i, jint *ji)
|
int_to_jint(JNIEnv *env, int i, jint *ji)
|
||||||
{
|
{
|
||||||
g_error_if_fail(env);
|
return 1;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_list_of_int(JNIEnv *env, int *list, jobjectArray *jarr) {
|
get_list_of_int(JNIEnv *env, int *list, jobjectArray *jarr) {
|
||||||
g_error_if_fail(env);
|
|
||||||
jsize i;
|
jsize i;
|
||||||
jclass cls;
|
jclass cls;
|
||||||
|
|
||||||
g_error_if_fail (env);
|
g_error_if_fail (env);
|
||||||
|
|
||||||
int size = 0;
|
int size = 0;
|
||||||
while(&list[size] != NULL) size++;
|
while(&list[size] != NULL) size++;
|
||||||
|
|
||||||
cls = get_jclass_by_name(env, "java/lang/Integer");
|
cls = get_jclass_by_name(env, "java/lang/Integer");
|
||||||
cryptic_return_val_if_fail(cls, 0);
|
cryptic_return_val_if_fail(cls, 0);
|
||||||
|
|
||||||
cryptic_return_val_if_fail(create_object_array(env, "java/lang/Integer", size, jarr), 0);
|
cryptic_return_val_if_fail(create_object_array(env, "java/lang/Integer", size, jarr), 0);
|
||||||
for (i=0; i<size; i++) {
|
for (i=0; i<size; i++) {
|
||||||
jint item;
|
jint item;
|
||||||
|
@ -208,7 +239,6 @@ get_list_of_int(JNIEnv *env, int *list, jobjectArray *jarr) {
|
||||||
|
|
||||||
static int
|
static int
|
||||||
jint_to_int(JNIEnv *env, jint ji, int *i) {
|
jint_to_int(JNIEnv *env, jint ji, int *i) {
|
||||||
g_error_if_fail(env);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,9 +247,10 @@ set_list_of_int(JNIEnv *env, int **list, jobjectArray jarr) {
|
||||||
jobject element = NULL;
|
jobject element = NULL;
|
||||||
jsize size = 0;
|
jsize size = 0;
|
||||||
jsize i = 0;
|
jsize i = 0;
|
||||||
|
|
||||||
g_error_if_fail (list && env);
|
g_error_if_fail (list && env);
|
||||||
if (jarr) {
|
if (jarr) {
|
||||||
if (! get_array_size(env, jarr, &size)) {
|
if (! get_array_size(env, jarr, &size)){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
list = NULL;
|
list = NULL;
|
||||||
|
|
Reference in New Issue