From fbb2317997d755c9aafa4831e988ff57e62fdf0f Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Quiros Date: Tue, 14 Feb 2023 16:23:42 +0100 Subject: [PATCH] Use decode response in decrypt --- waku-bindings/src/decrypt.rs | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/waku-bindings/src/decrypt.rs b/waku-bindings/src/decrypt.rs index c8e6804..b1482ba 100644 --- a/waku-bindings/src/decrypt.rs +++ b/waku-bindings/src/decrypt.rs @@ -1,12 +1,13 @@ //! Symmetric and asymmetric waku messages [decrypting](https://rfc.vac.dev/spec/36/#decrypting-messages) methods // std -use std::ffi::{CStr, CString}; +use std::ffi::CString; // crates use aes_gcm::{Aes256Gcm, Key}; use secp256k1::SecretKey; // internal -use crate::general::{DecodedPayload, JsonResponse, Result, WakuMessage}; +use crate::general::{DecodedPayload, Result, WakuMessage}; +use crate::utils::decode_and_free_response; /// Decrypt a message using a symmetric key /// @@ -34,16 +35,7 @@ pub fn waku_decode_symmetric( res }; - let result = unsafe { CStr::from_ptr(result_ptr) } - .to_str() - .expect("Response should always succeed to load to a &str"); - - let response: JsonResponse = - serde_json::from_str(result).map_err(|e| format!("{e}"))?; - - unsafe { waku_sys::waku_utils_free(result_ptr) }; - - response.into() + decode_and_free_response(result_ptr) } /// Decrypt a message using a symmetric key @@ -72,14 +64,5 @@ pub fn waku_decode_asymmetric( res }; - let result = unsafe { CStr::from_ptr(result_ptr) } - .to_str() - .expect("Response should always succeed to load to a &str"); - - let response: JsonResponse = - serde_json::from_str(result).map_err(|e| format!("{e}"))?; - - unsafe { waku_sys::waku_utils_free(result_ptr) }; - - response.into() + decode_and_free_response(result_ptr) }