summaryrefslogtreecommitdiff
path: root/src/storage.cpp
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2021-01-24 22:46:48 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2021-01-29 22:28:01 +0100
commita16b33031c7bcf2eabf1e0c3571000234b7740df (patch)
treef012ff7814abe7fa22c5a610388faf4310d53772 /src/storage.cpp
parent3a3cce8eed7e43faa8c9f606e56bb43ba3bd9451 (diff)
Attach service
Diffstat (limited to 'src/storage.cpp')
-rw-r--r--src/storage.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/storage.cpp b/src/storage.cpp
index 51ce9bc..6e2f118 100644
--- a/src/storage.cpp
+++ b/src/storage.cpp
@@ -613,13 +613,7 @@ Ref Storage::zref() const
Digest PartialStorage::Priv::storeBytes(const vector<uint8_t> & content) const
{
- array<uint8_t, Digest::size> arr;
- int ret = blake2b(arr.data(), content.data(), nullptr,
- Digest::size, content.size(), 0);
- if (ret != 0)
- throw runtime_error("failed to compute digest");
-
- Digest digest(arr);
+ Digest digest = Digest::of(content);
backend->storeBytes(digest, content);
return digest;
}
@@ -631,10 +625,7 @@ optional<vector<uint8_t>> PartialStorage::Priv::loadBytes(const Digest & digest)
return nullopt;
auto content = ocontent.value();
- array<uint8_t, Digest::size> arr;
- int ret = blake2b(arr.data(), content.data(), nullptr,
- Digest::size, content.size(), 0);
- if (ret != 0 || digest != Digest(arr))
+ if (digest != Digest::of(content))
throw runtime_error("digest verification failed");
return content;
@@ -820,6 +811,17 @@ bool Digest::isZero() const
return true;
}
+Digest Digest::of(const vector<uint8_t> & content)
+{
+ array<uint8_t, size> arr;
+ int ret = blake2b(arr.data(), content.data(), nullptr,
+ size, content.size(), 0);
+ if (ret != 0)
+ throw runtime_error("failed to compute digest");
+
+ return Digest(arr);
+}
+
PartialRef PartialRef::create(PartialStorage st, const Digest & digest)
{