Skip to content

Commit 67bad36

Browse files
committed
style: uniformly adopt the trailing return type style
1 parent f75a809 commit 67bad36

4 files changed

Lines changed: 8 additions & 12 deletions

File tree

include/hashlib/md5.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ namespace hashlib {
8989
}
9090

9191
private:
92-
void process_block_(const byte* block) noexcept {
92+
auto process_block_(const byte* block) noexcept -> void {
9393
static constexpr std::uint32_t K[64]{
9494
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
9595
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
@@ -150,7 +150,7 @@ namespace hashlib {
150150
}
151151

152152
HASHLIB_ALWAYS_INLINE
153-
HASHLIB_CXX17_CONSTEXPR static std::uint32_t byte4_to_uint32_(const byte* bytes) noexcept {
153+
HASHLIB_CXX17_CONSTEXPR static auto byte4_to_uint32_(const byte* bytes) noexcept -> std::uint32_t {
154154
return std::uint32_t(bytes[0]) | (std::uint32_t(bytes[1]) << 8) |
155155
(std::uint32_t(bytes[2]) << 16) | (std::uint32_t(bytes[3]) << 24);
156156
}

include/hashlib/sha1.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace hashlib {
77
namespace detail {
88
class sha1 {
99
public:
10-
static constexpr std::size_t digest_size = 20; // bytes
10+
static constexpr std::size_t digest_size = 20;
1111

1212
public:
1313
sha1() noexcept : h_{0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0} {}
@@ -144,7 +144,7 @@ namespace hashlib {
144144
}
145145

146146
HASHLIB_ALWAYS_INLINE
147-
static constexpr std::uint32_t rotl32(std::uint32_t x, int n) noexcept {
147+
static constexpr auto rotl32(std::uint32_t x, int n) noexcept -> std::uint32_t {
148148
return (x << n) | (x >> (32 - n));
149149
}
150150

include/hashlib/sha224_and_sha256.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ namespace hashlib {
7272
std::size_t padding_size = (buffer_size < 56) ? (56 - buffer_size) : (120 - buffer_size);
7373
update({padding, padding_size});
7474
std::uint64_t bits = total_size * 8;
75-
// 使用大端序填充长度
7675
for (std::size_t i = 0; i < 8; ++i) {
7776
padding[7 - i] = bits & 0xff;
7877
bits >>= 8;
@@ -93,7 +92,7 @@ namespace hashlib {
9392
}
9493

9594
private:
96-
void process_block_(const byte* block) noexcept {
95+
auto process_block_(const byte* block) noexcept -> void {
9796
static constexpr std::uint32_t k[64] = {
9897
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
9998
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
@@ -115,15 +114,13 @@ namespace hashlib {
115114

116115
std::uint32_t w[64];
117116

118-
// 使用大端序读取
119117
for (std::size_t i = 0; i < 16; ++i) {
120118
w[i] = (std::uint32_t(block[i * 4]) << 24) |
121119
(std::uint32_t(block[i * 4 + 1]) << 16) |
122120
(std::uint32_t(block[i * 4 + 2]) << 8) |
123121
(std::uint32_t(block[i * 4 + 3]));
124122
}
125123

126-
// 消息调度
127124
for (std::size_t i = 16; i < 64; ++i) {
128125
const auto s0 = rotr32(w[i-15], 7) ^ rotr32(w[i-15], 18) ^ (w[i-15] >> 3);
129126
const auto s1 = rotr32(w[i-2], 17) ^ rotr32(w[i-2], 19) ^ (w[i-2] >> 10);
@@ -133,7 +130,6 @@ namespace hashlib {
133130
auto a = h_[0], b = h_[1], c = h_[2], d = h_[3],
134131
e = h_[4], f = h_[5], g = h_[6], h = h_[7];
135132

136-
// 压缩函数主循环
137133
for (std::size_t i = 0; i < 64; ++i) {
138134
const auto S1 = rotr32(e, 6) ^ rotr32(e, 11) ^ rotr32(e, 25);
139135
const auto ch = (e & f) ^ ((~e) & g);
@@ -163,7 +159,7 @@ namespace hashlib {
163159
}
164160

165161
HASHLIB_ALWAYS_INLINE
166-
static constexpr std::uint32_t rotr32(std::uint32_t x, int n) noexcept {
162+
static constexpr auto rotr32(std::uint32_t x, int n) noexcept -> std::uint32_t {
167163
return (x >> n) | (x << (32 - n));
168164
}
169165

include/hashlib/sha384_and_sha512.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ namespace hashlib {
104104
}
105105

106106
private:
107-
void process_block_(const byte* block) noexcept {
107+
auto process_block_(const byte* block) noexcept -> void {
108108
static constexpr std::uint64_t k[80] = {
109109
0x428a2f98d728ae22ull, 0x7137449123ef65cdull, 0xb5c0fbcfec4d3b2full, 0xe9b5dba58189dbbcull,
110110
0x3956c25bf348b538ull, 0x59f111f1b605d019ull, 0x923f82a4af194f9bull, 0xab1c5ed5da6d8118ull,
@@ -179,7 +179,7 @@ namespace hashlib {
179179
}
180180

181181
HASHLIB_ALWAYS_INLINE
182-
static constexpr std::uint64_t rotr64(std::uint64_t x, int n) noexcept {
182+
static constexpr auto rotr64(std::uint64_t x, int n) noexcept -> std::uint64_t {
183183
return (x >> n) | (x << (64 - n));
184184
}
185185

0 commit comments

Comments
 (0)