Skip to content

Commit c7fbe6d

Browse files
committed
sha256 update example to use THEXT class
1 parent 6508d7a commit c7fbe6d

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

examples/sha256/sha256.ino

+4-14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#include <Arduino_SHA256.h>
12+
#include <Arduino_HEX.h>
1213
#include "buffer.h"
1314

1415
void setup() {
@@ -22,22 +23,11 @@ void setup() {
2223
sha256.update(buffer, sizeof(buffer));
2324
sha256.finalize(sha);
2425

25-
Serial.println(hexEncode(sha, sizeof(sha)));
26+
Serial.println(THEXT::encode(sha, sizeof(sha)));
2627

2728
/* One-shot */
28-
arduino::sha256::sha256(buffer, sizeof(buffer), sha);
29-
Serial.println(hexEncode(sha, sizeof(sha)));
30-
}
31-
32-
static String hexEncode(uint8_t* in, uint32_t size) {
33-
String out;
34-
out.reserve((size * 2) + 1);
35-
36-
char* ptr = out.begin();
37-
for (uint32_t i = 0; i < size; i++) {
38-
ptr += sprintf(ptr, "%02X", in[i]);
39-
}
40-
return String(out.c_str());
29+
SHA256::sha256(buffer, sizeof(buffer), sha);
30+
Serial.println(THEXT::encode(sha, sizeof(sha)));
4131
}
4232

4333
void loop() { }

0 commit comments

Comments
 (0)