Skip to content

Commit 8b5afd2

Browse files
committed
sha256: move SHA256 class inside sha256 namespace
1 parent 75a6b17 commit 8b5afd2

File tree

4 files changed

+23
-40
lines changed

4 files changed

+23
-40
lines changed

examples/sha256/sha256.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void setup() {
1515
Serial.begin(9600);
1616
while(!Serial);
1717

18-
uint8_t sha[SHA256::HASH_SIZE];
18+
uint8_t sha[SHA256_DIGEST_SIZE];
1919

2020
SHA256 sha256;
2121
sha256.begin();

src/bpid/bpid.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace arduino { namespace bpid {
3838
if (!get(data, sizeof(data))) {
3939
return String("");
4040
}
41-
uint8_t out[SHA256::HASH_SIZE];
41+
uint8_t out[SHA256_DIGEST_SIZE];
4242
arduino::sha256::sha256(data, sizeof(data), out);
4343
return arduino::hex::encode(out, sizeof(out));
4444
}

src/sha256/SHA256.cpp

-23
This file was deleted.

src/sha256/SHA256.h

+21-15
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,6 @@
1212

1313
#include "sha2.h"
1414

15-
class SHA256 {
16-
17-
public:
18-
19-
static constexpr uint32_t HASH_SIZE = SHA256_DIGEST_SIZE;
20-
21-
void begin();
22-
void update(uint8_t const * data, uint32_t const len);
23-
void finalize(uint8_t * hash);
24-
25-
private:
26-
27-
sha256_ctx _ctx;
28-
};
29-
3015
namespace arduino { namespace sha256 {
3116

3217
inline void begin(sha256_ctx * ctx) {
@@ -42,4 +27,25 @@ namespace arduino { namespace sha256 {
4227
::sha256(input, ilen, output);
4328
}
4429

30+
class SHA256 {
31+
public:
32+
33+
inline void begin() {
34+
return arduino::sha256::begin(&_ctx);
35+
}
36+
inline void update(uint8_t const * data, uint32_t const len) {
37+
return arduino::sha256::update(&_ctx, data, len);
38+
}
39+
inline void finalize(uint8_t * hash) {
40+
return arduino::sha256::finalize(&_ctx, hash);
41+
}
42+
static inline void sha256(uint8_t const * data, uint32_t const len, uint8_t * hash) {
43+
return arduino::sha256::sha256(data, len, hash);
44+
}
45+
46+
private:
47+
48+
sha256_ctx _ctx;
49+
};
50+
4551
}} // arduino::sha256

0 commit comments

Comments
 (0)