Skip to content

Commit

Permalink
Fixed generic SHA1 name causing conflicts with other libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanclief committed Jul 20, 2024
1 parent b48e9d3 commit 8283d4f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
16 changes: 8 additions & 8 deletions examples/SHA1/SHA1.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void printSHA1(const char* str) {
Serial.print(str);
Serial.print("' is 0x");

SHA1.beginHash();
SHA1.print(str);
SHA1.endHash();
BearSHA1.beginHash();
BearSHA1.print(str);
BearSHA1.endHash();

printResult();
}
Expand All @@ -48,17 +48,17 @@ void printHMACSHA1(const char* secret, const char* str) {
Serial.print(secret);
Serial.print("' is 0x");

SHA1.beginHmac(secret);
SHA1.print(str);
SHA1.endHmac();
BearSHA1.beginHmac(secret);
BearSHA1.print(str);
BearSHA1.endHmac();

printResult();
}

void printResult()
{
while (SHA1.available()) {
byte b = SHA1.read();
while (BearSHA1.available()) {
byte b = BearSHA1.read();

if (b < 16) {
Serial.print("0");
Expand Down
30 changes: 11 additions & 19 deletions src/SHA1.cpp
Original file line number Diff line number Diff line change
@@ -1,60 +1,52 @@
/*
* Copyright (c) 2019 Arduino SA. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include <ArduinoBearSSL.h>
#include "SHA1.h"
#include <ArduinoBearSSL.h>

SHA1Class::SHA1Class() :
SHAClass(SHA1_BLOCK_SIZE, SHA1_DIGEST_SIZE)
{
}
SHA1Class::SHA1Class() : SHAClass(SHA1_BLOCK_SIZE, SHA1_DIGEST_SIZE) {}

SHA1Class::~SHA1Class()
{
}
SHA1Class::~SHA1Class() {}

int SHA1Class::begin()
{
int SHA1Class::begin() {
br_sha1_init(&_ctx);

return 1;
}

int SHA1Class::update(const uint8_t *buffer, size_t size)
{
int SHA1Class::update(const uint8_t *buffer, size_t size) {
br_sha1_update(&_ctx, buffer, size);

return 1;
}

int SHA1Class::end(uint8_t *digest)
{
int SHA1Class::end(uint8_t *digest) {
br_sha1_out(&_ctx, digest);

return 1;
}

#if !defined(ARDUINO_BEARSSL_DISABLE_SHA1)
SHA1Class SHA1;
SHA1Class BearSHA1;
#endif
2 changes: 1 addition & 1 deletion src/SHA1.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ class SHA1Class: public SHAClass {
br_sha1_context _ctx;
};

extern SHA1Class SHA1;
extern SHA1Class BearSHA1;

#endif

0 comments on commit 8283d4f

Please sign in to comment.