Browse Source

And deserialization.

Thomas Kerber 1 year ago
parent
commit
4e37778706
Signed by: Thomas Kerber <tk@drwx.org> GPG Key ID: 8489B911F9ED617B
1 changed files with 46 additions and 1 deletions
  1. 46
    1
      src/lib.rs

+ 46
- 1
src/lib.rs View File

@@ -231,6 +231,12 @@ impl Drop for ConstraintSystem {
231 231
 
232 232
 pub struct Proof(*mut proof_t);
233 233
 
234
+impl From<CppString> for Proof {
235
+    fn from(s: CppString) -> Self {
236
+        Proof(unsafe { libsnark_de_proof_t(s.0) })
237
+    }
238
+}
239
+
234 240
 impl Drop for Proof {
235 241
     fn drop(&mut self) {
236 242
         unsafe { libsnark_deinit_proof_t(self.0) };
@@ -242,6 +248,18 @@ pub struct VerificationKey {
242 248
     inputs: usize,
243 249
 }
244 250
 
251
+impl From<CppString> for VerificationKey {
252
+    fn from(s: CppString) -> Self {
253
+        let mut inputs: usize;
254
+        let mut vk: *mut vk_t;
255
+        unsafe { libsnark_de_pvk_t(s.0, &mut vk, &mut inputs) };
256
+        VerificationKey {
257
+            inner: pvk,
258
+            inputs: inputs,
259
+        }
260
+    }
261
+}
262
+
245 263
 impl VerificationKey {
246 264
     pub fn process(&self) -> ProcessedVerificationKey {
247 265
         ProcessedVerificationKey {
@@ -305,6 +323,21 @@ impl ProvingKey {
305 323
     }
306 324
 }
307 325
 
326
+impl From<CppString> for ProvingKey {
327
+    fn from(s: CppString) -> Self {
328
+        let mut inputs: usize;
329
+        let mut aux_inputs: usize;
330
+        let mut pk: *mut pk_t;
331
+        unsafe {
332
+            libsnark_de_pk_t(s.0, &mut pk, &mut inputs, &mut aux_inputs)
333
+        };
334
+        ProvingKey {
335
+            inner: pk,
336
+            inputs: inputs,
337
+        }
338
+    }
339
+}
340
+
308 341
 impl Drop for ProvingKey {
309 342
     fn drop(&mut self) {
310 343
         unsafe { libsnark_deinit_pk_t(self.inner) };
@@ -341,6 +374,18 @@ impl ProcessedVerificationKey {
341 374
     }
342 375
 }
343 376
 
377
+impl From<CppString> for ProcessedVerificationKey {
378
+    fn from(s: CppString) -> Self {
379
+        let mut inputs: usize;
380
+        let mut pvk: *mut pvk_t;
381
+        unsafe { libsnark_de_pvk_t(s.0, &mut pvk, &mut inputs) };
382
+        ProcessedVerificationKey {
383
+            inner: pvk,
384
+            inputs: inputs,
385
+        }
386
+    }
387
+}
388
+
344 389
 impl Drop for ProcessedVerificationKey {
345 390
     fn drop(&mut self) {
346 391
         unsafe { libsnark_deinit_pvk_t(self.inner) };
@@ -354,7 +399,7 @@ mod tests {
354 399
     use super::*;
355 400
 
356 401
     #[test]
357
-    fn it_works() {
402
+    fn simple_example() {
358 403
         let handle = Handle::new();
359 404
         let mut csb = ConstraintSystemBuilder::new(handle);
360 405
         let mut lc1 = LinearCombination::new(&csb);

Loading…
Cancel
Save