aboutsummaryrefslogtreecommitdiffstats
path: root/sample
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2016-09-03 10:16:16 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2016-09-03 10:16:16 +0800
commit12bb5c058ac2cd5775ae6f4c800792547896300c (patch)
tree8530c9cbd302b084999eb6a7dd2d8c5a72182a30 /sample
parent472be207e7ff296230fd1be0bf98d03db0c7082f (diff)
downloaddexon-bls-12bb5c058ac2cd5775ae6f4c800792547896300c.tar
dexon-bls-12bb5c058ac2cd5775ae6f4c800792547896300c.tar.gz
dexon-bls-12bb5c058ac2cd5775ae6f4c800792547896300c.tar.bz2
dexon-bls-12bb5c058ac2cd5775ae6f4c800792547896300c.tar.lz
dexon-bls-12bb5c058ac2cd5775ae6f4c800792547896300c.tar.xz
dexon-bls-12bb5c058ac2cd5775ae6f4c800792547896300c.tar.zst
dexon-bls-12bb5c058ac2cd5775ae6f4c800792547896300c.zip
accept multi line message. remove last '\n'
Diffstat (limited to 'sample')
-rw-r--r--sample/bls_tool.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/sample/bls_tool.cpp b/sample/bls_tool.cpp
index 78b5bbc..158f7b2 100644
--- a/sample/bls_tool.cpp
+++ b/sample/bls_tool.cpp
@@ -22,16 +22,27 @@ void strip(std::string& str)
if (str[str.size() - 1] == '\n') str.resize(str.size() - 1);
}
-void readLine(std::string& str)
+void readMessage(std::string& str)
{
str.clear();
+#if 1
+ std::string line;
+ std::getline(std::cin, line); // remove first blank line
+ while (std::getline(std::cin, line)) {
+ if (!str.empty()) str += '\n';
+ str += line;
+ }
+ strip(str);
+ if (!str.empty()) return;
+#else
// retry once if blank line exists
for (size_t i = 0; i < 2; i++) {
std::getline(std::cin, str);
strip(str);
if (!str.empty()) return;
}
- throw std::runtime_error("readLine:message is empty");
+#endif
+ throw std::runtime_error("readMessage:message is empty");
}
bool g_verbose = false;
@@ -63,7 +74,7 @@ void sign()
read(sec);
if (g_verbose) std::cerr << "sec:" << sec << std::endl;
std::string m;
- readLine(m);
+ readMessage(m);
if (g_verbose) fprintf(stderr, "message:`%s`\n", m.c_str());
bls::Sign s;
sec.sign(s, m);
@@ -80,7 +91,7 @@ void verify()
read(pub);
if (g_verbose) std::cerr << "pub:" << pub << std::endl;
std::string m;
- readLine(m);
+ readMessage(m);
if (g_verbose) fprintf(stderr, "message:`%s`\n", m.c_str());
bool b = s.verify(pub, m);
write(b ? "1" : "0");