aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bls_if.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/bls_if.cpp b/src/bls_if.cpp
index 163996c..8dc99f8 100644
--- a/src/bls_if.cpp
+++ b/src/bls_if.cpp
@@ -1,6 +1,8 @@
#include "bls.hpp"
#include "bls_if.h"
#include <iostream>
+#include <sstream>
+#include <memory.h>
void blsInit(void)
{
@@ -26,6 +28,29 @@ void blsIdPut(const blsId *id)
std::cout << *(const bls::Id*)id << std::endl;
}
+int blsIdSetStr(blsId *id, const char *buf, size_t bufSize)
+ try
+{
+ std::istringstream iss(std::string(buf, bufSize));
+ iss >> *(bls::Id*)id;
+ return 0;
+} catch (std::exception& e) {
+ return 1;
+}
+
+size_t blsIdGetStr(const blsId *id, char *buf, size_t maxBufSize)
+ try
+{
+ std::ostringstream oss;
+ oss << *(const bls::Id*)id;
+ std::string s = oss.str();
+ if (s.size() > maxBufSize) return 0;
+ memcpy(buf, s.c_str(), s.size());
+ return s.size();
+} catch (std::exception& e) {
+ return 0;
+}
+
void blsIdSet(blsId *id, const uint64_t *p)
{
((bls::Id*)id)->set(p);