aggs supports serialize

update-fork
MITSUNARI Shigeo 5 years ago
parent b27ecb2fc4
commit 2095a80e17
  1. 60
      include/mcl/aggregate_sig.hpp
  2. 30
      test/aggregate_sig_test.cpp

@ -62,16 +62,32 @@ public:
friend class SecretKey;
friend class PublicKey;
public:
template<class InputStream>
void load(bool *pb, InputStream& is, int ioMode = IoSerialize)
{
S_.load(pb, is, ioMode);
}
template<class OutputStream>
void save(bool *pb, OutputStream& os, int ioMode = IoSerialize) const
{
S_.save(pb, os, ioMode);
}
#ifndef CYBOZU_DONT_USE_EXCEPTION
template<class InputStream>
void load(InputStream& is, int ioMode = IoSerialize)
{
S_.load(is, ioMode);
bool b;
load(&b, is, ioMode);
if (!b) throw cybozu::Exception("Signature:load");
}
template<class OutputStream>
void save(OutputStream& os, int ioMode = IoSerialize) const
{
S_.save(os, ioMode);
bool b;
save(&b, os, ioMode);
if (!b) throw cybozu::Exception("Signature:save");
}
#endif
friend std::istream& operator>>(std::istream& is, Signature& self)
{
self.load(is, fp::detectIoMode(G1::getIoMode(), is));
@ -155,16 +171,32 @@ public:
friend class SecretKey;
friend class Signature;
public:
template<class InputStream>
void load(bool *pb, InputStream& is, int ioMode = IoSerialize)
{
xQ_.load(pb, is, ioMode);
}
template<class OutputStream>
void save(bool *pb, OutputStream& os, int ioMode = IoSerialize) const
{
xQ_.save(pb, os, ioMode);
}
#ifndef CYBOZU_DONT_USE_EXCEPTION
template<class InputStream>
void load(InputStream& is, int ioMode = IoSerialize)
{
xQ_.load(is, ioMode);
bool b;
load(&b, is, ioMode);
if (!b) throw cybozu::Exception("PublicKey:load");
}
template<class OutputStream>
void save(OutputStream& os, int ioMode = IoSerialize) const
{
xQ_.save(os, ioMode);
bool b;
save(&b, os, ioMode);
if (!b) throw cybozu::Exception("PublicKey:save");
}
#endif
friend std::istream& operator>>(std::istream& is, PublicKey& self)
{
self.load(is, fp::detectIoMode(G2::getIoMode(), is));
@ -208,16 +240,32 @@ public:
friend class PublicKey;
friend class Signature;
public:
template<class InputStream>
void load(bool *pb, InputStream& is, int ioMode = IoSerialize)
{
x_.load(pb, is, ioMode);
}
template<class OutputStream>
void save(bool *pb, OutputStream& os, int ioMode = IoSerialize) const
{
x_.save(pb, os, ioMode);
}
#ifndef CYBOZU_DONT_USE_EXCEPTION
template<class InputStream>
void load(InputStream& is, int ioMode = IoSerialize)
{
x_.load(is, ioMode);
bool b;
load(&b, is, ioMode);
if (!b) throw cybozu::Exception("SecretKey:load");
}
template<class OutputStream>
void save(OutputStream& os, int ioMode = IoSerialize) const
{
x_.save(os, ioMode);
bool b;
save(&b, os, ioMode);
if (!b) throw cybozu::Exception("SecretKey:save");
}
#endif
friend std::istream& operator>>(std::istream& is, SecretKey& self)
{
self.load(is, fp::detectIoMode(Fr::getIoMode(), is));

@ -21,6 +21,36 @@ CYBOZU_TEST_AUTO(init)
CYBOZU_TEST_ASSERT(pub.verify(sig, m));
}
template<class T>
void serializeTest(const T& x)
{
std::stringstream ss;
ss << x;
T y;
ss >> y;
CYBOZU_TEST_EQUAL(x, y);
char buf[1024];
size_t n;
n = x.serialize(buf, sizeof(buf));
CYBOZU_TEST_ASSERT(n > 0);
T z;
CYBOZU_TEST_EQUAL(z.deserialize(buf, n), n);
CYBOZU_TEST_EQUAL(x, z);
}
CYBOZU_TEST_AUTO(serialize)
{
SecretKey sec;
sec.init();
PublicKey pub;
sec.getPublicKey(pub);
Signature sig;
sec.sign(sig, "abc");
serializeTest(sec);
serializeTest(pub);
serializeTest(sig);
}
void aggregateTest(const std::vector<std::string>& msgVec)
{
const size_t n = msgVec.size();

Loading…
Cancel
Save