From e7e2b4eb8c0a24883eda440f8688f20a4f33a879 Mon Sep 17 00:00:00 2001
From: taynpg <taynpg@163.com>
Date: Wed, 28 Feb 2024 17:06:02 +0800
Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=86=85=E5=AD=98=E5=88=86?=
 =?UTF-8?q?=E9=85=8D=E9=87=8A=E6=94=BE=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 cryp/box_rsa.cpp        | 6 ++++++
 cryp/box_rsa.h          | 1 +
 test/cryp_test/main.cpp | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/cryp/box_rsa.cpp b/cryp/box_rsa.cpp
index c44bf9f..8438a0a 100644
--- a/cryp/box_rsa.cpp
+++ b/cryp/box_rsa.cpp
@@ -290,4 +290,10 @@ void CRSAOperator::free_hdata(HData& data)
     imp_->free_data(data);
 }
 
+void CRSAOperator::alloc_hdata(HData& data)
+{
+    assert(imp_);
+    imp_->alloc_data(data);
+}
+
 }   // namespace cppbox
\ No newline at end of file
diff --git a/cryp/box_rsa.h b/cryp/box_rsa.h
index 69f205a..5a8885f 100644
--- a/cryp/box_rsa.h
+++ b/cryp/box_rsa.h
@@ -27,6 +27,7 @@ public:
     bool        generate_keypair(const char* pub_path, const char* pri_path);
     bool        generate_keypair(HData& pub, HData& pri);
     void        free_hdata(HData& data);
+    void        alloc_hdata(HData& data);
     const char* get_last_error() const;
 };
 
diff --git a/test/cryp_test/main.cpp b/test/cryp_test/main.cpp
index f95fbee..56f9691 100644
--- a/test/cryp_test/main.cpp
+++ b/test/cryp_test/main.cpp
@@ -17,8 +17,8 @@ void file_test()
 
     HData source_data;
     int size = 512;
-    source_data.data = (unsigned char*)malloc(size);
     source_data.len = size;
+    opr.alloc_hdata(source_data);
     source_data.len = std::snprintf((char *)source_data.data, source_data.len, "This is a cryp test!");
 
     HData en_result_data;