Skip to content

Commit 8283d4f

Browse files
committed
Fixed generic SHA1 name causing conflicts with other libraries
1 parent b48e9d3 commit 8283d4f

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

examples/SHA1/SHA1.ino

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ void printSHA1(const char* str) {
3434
Serial.print(str);
3535
Serial.print("' is 0x");
3636

37-
SHA1.beginHash();
38-
SHA1.print(str);
39-
SHA1.endHash();
37+
BearSHA1.beginHash();
38+
BearSHA1.print(str);
39+
BearSHA1.endHash();
4040

4141
printResult();
4242
}
@@ -48,17 +48,17 @@ void printHMACSHA1(const char* secret, const char* str) {
4848
Serial.print(secret);
4949
Serial.print("' is 0x");
5050

51-
SHA1.beginHmac(secret);
52-
SHA1.print(str);
53-
SHA1.endHmac();
51+
BearSHA1.beginHmac(secret);
52+
BearSHA1.print(str);
53+
BearSHA1.endHmac();
5454

5555
printResult();
5656
}
5757

5858
void printResult()
5959
{
60-
while (SHA1.available()) {
61-
byte b = SHA1.read();
60+
while (BearSHA1.available()) {
61+
byte b = BearSHA1.read();
6262

6363
if (b < 16) {
6464
Serial.print("0");

src/SHA1.cpp

+11-19
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,52 @@
11
/*
22
* Copyright (c) 2019 Arduino SA. All rights reserved.
33
*
4-
* Permission is hereby granted, free of charge, to any person obtaining
4+
* Permission is hereby granted, free of charge, to any person obtaining
55
* a copy of this software and associated documentation files (the
66
* "Software"), to deal in the Software without restriction, including
77
* without limitation the rights to use, copy, modify, merge, publish,
88
* distribute, sublicense, and/or sell copies of the Software, and to
99
* permit persons to whom the Software is furnished to do so, subject to
1010
* the following conditions:
1111
*
12-
* The above copyright notice and this permission notice shall be
12+
* The above copyright notice and this permission notice shall be
1313
* included in all copies or substantial portions of the Software.
1414
*
15-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1616
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1818
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1919
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2020
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2121
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
2424

25-
#include <ArduinoBearSSL.h>
2625
#include "SHA1.h"
26+
#include <ArduinoBearSSL.h>
2727

28-
SHA1Class::SHA1Class() :
29-
SHAClass(SHA1_BLOCK_SIZE, SHA1_DIGEST_SIZE)
30-
{
31-
}
28+
SHA1Class::SHA1Class() : SHAClass(SHA1_BLOCK_SIZE, SHA1_DIGEST_SIZE) {}
3229

33-
SHA1Class::~SHA1Class()
34-
{
35-
}
30+
SHA1Class::~SHA1Class() {}
3631

37-
int SHA1Class::begin()
38-
{
32+
int SHA1Class::begin() {
3933
br_sha1_init(&_ctx);
4034

4135
return 1;
4236
}
4337

44-
int SHA1Class::update(const uint8_t *buffer, size_t size)
45-
{
38+
int SHA1Class::update(const uint8_t *buffer, size_t size) {
4639
br_sha1_update(&_ctx, buffer, size);
4740

4841
return 1;
4942
}
5043

51-
int SHA1Class::end(uint8_t *digest)
52-
{
44+
int SHA1Class::end(uint8_t *digest) {
5345
br_sha1_out(&_ctx, digest);
5446

5547
return 1;
5648
}
5749

5850
#if !defined(ARDUINO_BEARSSL_DISABLE_SHA1)
59-
SHA1Class SHA1;
51+
SHA1Class BearSHA1;
6052
#endif

src/SHA1.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ class SHA1Class: public SHAClass {
4747
br_sha1_context _ctx;
4848
};
4949

50-
extern SHA1Class SHA1;
50+
extern SHA1Class BearSHA1;
5151

5252
#endif

0 commit comments

Comments
 (0)