diff options
Diffstat (limited to 'src/storage.cpp')
-rw-r--r-- | src/storage.cpp | 24 |
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) { |