1
1
use robusta_jni:: bridge;
2
2
3
+
3
4
#[ bridge]
4
5
pub mod jni {
5
6
#[ allow( unused_imports) ] //the bridge import is marked as unused, but if removed the compiler throws an error
@@ -19,6 +20,8 @@ pub mod jni {
19
20
20
21
use crate :: SecurityModuleError ;
21
22
23
+ const CLASS_SIGNATURE : & str = "com/example/vulcans_limes/RustDef" ;
24
+
22
25
/// Contains all methods related to Rust - Java communication and the JNI
23
26
#[ derive( Signature , TryIntoJavaValue , IntoJavaValue , TryFromJavaValue ) ]
24
27
#[ package( com. example. vulcans_1limes) ] //the 1 after the "_" is an escape character for the "_"
@@ -27,6 +30,7 @@ pub mod jni {
27
30
pub raw : AutoLocal < ' env , ' borrow > ,
28
31
}
29
32
33
+
30
34
/// This Implementation provides the method declarations that are the interface for the JNI.
31
35
/// The first part contains Java-methods that can be called from Rust.
32
36
/// The second part contains some utility methods.
@@ -63,7 +67,7 @@ pub mod jni {
63
67
//This calls a method in Java in the Class RustDef, with the method name "callback"
64
68
//and no arguments
65
69
environment. call_static_method (
66
- "com/example/vulcans_limes/RustDef" , //Class signature
70
+ CLASS_SIGNATURE , //Class signature
67
71
"callback" , //method name signature
68
72
"()V" , //parameter types of the method
69
73
& [ ] , //parameters to be passed to the method
@@ -82,7 +86,7 @@ pub mod jni {
82
86
pub fn create_key ( environment : & JNIEnv , key_id : String , key_gen_info : String ) -> Result < ( ) , SecurityModuleError > {
83
87
RustDef :: initialize_module ( environment) ?;
84
88
let result = environment. call_static_method (
85
- "com/example/vulcans_limes/RustDef" ,
89
+ CLASS_SIGNATURE ,
86
90
"create_key" ,
87
91
"(Ljava/lang/String;Ljava/lang/String;)V" ,
88
92
& [ JValue :: from ( environment. new_string ( key_id) . unwrap ( ) ) ,
@@ -121,7 +125,7 @@ pub mod jni {
121
125
pub fn load_key ( environment : & JNIEnv , key_id : String ) -> Result < ( ) , SecurityModuleError > {
122
126
RustDef :: initialize_module ( environment) ?;
123
127
let result = environment. call_static_method (
124
- "com/example/vulcans_limes/RustDef" ,
128
+ CLASS_SIGNATURE ,
125
129
"load_key" ,
126
130
"(Ljava/lang/String;)V" ,
127
131
& [ JValue :: from ( environment. new_string ( key_id) . unwrap ( ) ) ] ,
@@ -165,7 +169,7 @@ pub mod jni {
165
169
pub fn initialize_module ( environment : & JNIEnv )
166
170
-> Result < ( ) , SecurityModuleError > {
167
171
let result = environment. call_static_method (
168
- "com/example/vulcans_limes/RustDef" ,
172
+ CLASS_SIGNATURE ,
169
173
"initialize_module" ,
170
174
"()V" ,
171
175
& [ ] ,
@@ -202,7 +206,7 @@ pub mod jni {
202
206
/// or an `Error` on failure.
203
207
pub fn sign_data ( environment : & JNIEnv , data : & [ u8 ] ) -> Result < Vec < u8 > , SecurityModuleError > {
204
208
let result = environment. call_static_method (
205
- "com/example/vulcans_limes/RustDef" ,
209
+ CLASS_SIGNATURE ,
206
210
"sign_data" ,
207
211
"([B)[B" ,
208
212
& [ JValue :: from ( environment. byte_array_from_slice ( data) . unwrap ( ) ) ] ,
@@ -253,7 +257,7 @@ pub mod jni {
253
257
/// or an `Error` on failure to determine the validity.
254
258
pub fn verify_signature ( environment : & JNIEnv , data : & [ u8 ] , signature : & [ u8 ] ) -> Result < bool , SecurityModuleError > {
255
259
let result = environment. call_static_method (
256
- "com/example/vulcans_limes/RustDef" ,
260
+ CLASS_SIGNATURE ,
257
261
"verify_signature" ,
258
262
"([B[B)Z" ,
259
263
& [ JValue :: from ( environment. byte_array_from_slice ( data) . unwrap ( ) ) ,
@@ -303,7 +307,7 @@ pub mod jni {
303
307
/// or an `Error` on failure.
304
308
pub fn encrypt_data ( environment : & JNIEnv , data : & [ u8 ] ) -> Result < Vec < u8 > , SecurityModuleError > {
305
309
let result = environment. call_static_method (
306
- "com/example/vulcans_limes/RustDef" ,
310
+ CLASS_SIGNATURE ,
307
311
"encrypt_data" ,
308
312
"([B)[B" ,
309
313
& [ JValue :: from ( environment. byte_array_from_slice ( data) . unwrap ( ) ) ] ,
@@ -354,7 +358,7 @@ pub mod jni {
354
358
/// or an `Error` on failure.
355
359
pub fn decrypt_data ( environment : & JNIEnv , data : & [ u8 ] ) -> Result < Vec < u8 > , SecurityModuleError > {
356
360
let result = environment. call_static_method (
357
- "com/example/vulcans_limes/RustDef" ,
361
+ CLASS_SIGNATURE ,
358
362
"decrypt_data" ,
359
363
"([B)[B" ,
360
364
& [ JValue :: from ( environment. byte_array_from_slice ( data) . unwrap ( ) ) ] ,
0 commit comments