libkazv
Loading...
Searching...
No Matches
sha256.hpp
Go to the documentation of this file.
1/*
2 * This file is part of libkazv.
3 * SPDX-FileCopyrightText: 2021 Tusooa Zhu <tusooa@kazv.moe>
4 * SPDX-License-Identifier: AGPL-3.0-or-later
5 */
6
7#pragma once
8#include <libkazv-config.hpp>
9
10#include <memory>
11
12
13#include <copy-helper.hpp>
14
15#include "crypto-util.hpp"
16
17
18namespace Kazv
19{
21 {
22 public:
23 using DataT = std::string;
24
28 SHA256Desc();
29
31
33
37 SHA256Desc process(DataT data) const &;
38
39 template<class RangeT,
40 class = std::enable_if_t<!std::is_same_v<std::decay_t<RangeT>, DataT>, int>>
42 {
43 return process(DataT(data.begin(), data.end()));
44 }
45
49 SHA256Desc process(DataT data) &&;
50
51 template<class RangeT,
52 class = std::enable_if_t<!std::is_same_v<std::decay_t<RangeT>, DataT>, int>>
54 {
55 return std::move(*this).process(DataT(data.begin(), data.end()));
56 }
57
61 void processInPlace(DataT data);
62
63 template<class RangeT,
64 class = std::enable_if_t<!std::is_same_v<std::decay_t<RangeT>, DataT>, int>>
66 {
67 processInPlace(DataT(data.begin(), data.end()));
68 }
69
73 std::string get() const;
74
75 private:
76 struct Private;
77 std::unique_ptr<Private> m_d;
78 };
79}
Definition sha256.hpp:21
SHA256Desc process(DataT data) const &
Process data and return the next hash state.
Definition sha256.cpp:30
void processInPlace(DataT data)
Process data in-place.
Definition sha256.cpp:44
std::string DataT
Definition sha256.hpp:23
std::string get() const
Get the hash result as unpadded base64.
Definition sha256.cpp:49
void processInPlace(RangeT data)
Definition sha256.hpp:65
SHA256Desc()
Construct a SHA256 description.
Definition sha256.cpp:21
SHA256Desc process(RangeT data) &&
Definition sha256.hpp:53
SHA256Desc process(RangeT data) const &
Definition sha256.hpp:41
A RangeT is an ordered collection that can be iterated through.
Definition range-t.hpp:21
auto end() const
The past-end iterator of this range.
auto begin() const
The beginning iterator of this range.
#define KAZV_DECLARE_COPYABLE(typeName)
Definition copy-helper.hpp:10
Definition location.hpp:10
@ Private
Definition client-model.hpp:41