Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
/// \file sha256.h
/// \brief Minimal SHA-256 implementation used for content-addressed assets.
///        No external crypto dependency.
 
#pragma once
 
#include <cstddef>
#include <cstdint>
#include <istream>
#include <string>
 
namespace model_package {
 
class Sha256 {
 public:
  static constexpr size_t kDigestSize = 32;
 
  Sha256();
  void Update(const void* data, size_t len);
  void Update(const std::string& s) { Update(s.data(), s.size()); }
  void Final(uint8_t out[kDigestSize]);
 
  /// Hex-encoded (lowercase) digest, 64 chars.
  std::string FinalHex();
 
  static std::string HashBytesHex(const void* data, size_t len);
  static std::string HashStringHex(const std::string& s);
 
  /// Stream-hash a file by path. Returns the hex digest, or empty string on
  /// IO error (caller should pre-check existence).
  static std::string HashFileHex(const std::string& path);
 
 private:
  void Transform(const uint8_t block[64]);
  uint32_t state_[8];
  uint64_t bit_count_;
  uint8_t buffer_[64];
  size_t buffer_len_;
};
 
}  // namespace model_package