value: cleanup, move sign & encrypt to cpp

This commit is contained in:
Adrien Béraud committed 2022-05-25 11:04:46 -04:00
1 parent 56442acc84
commit 5f743344e5
2 files changed
+25 -17

No files matched your search

+21
View File
@@ -254,6 +254,27 @@ unpackId(const Json::Value& json, const std::string& key) {
}
#endif
void
Value::sign(const crypto::PrivateKey& key)
{
if (isEncrypted())
throw DhtException("Can't sign encrypted data.");
owner = key.getSharedPublicKey();
signature = key.sign(getToSign());
}
Value
Value::encrypt(const crypto::PrivateKey& from, const crypto::PublicKey& to)
{
if (isEncrypted())
throw DhtException("Data is already encrypted.");
setRecipient(to.getId());
sign(from);
Value nv {id};
nv.setCypher(to.encrypt(getToEncrypt()));
return nv;
}
bool
Value::checkSignature()
{