Skip to content

Commit f1282fc

Browse files
committed
Fix hex conversion
1 parent 48814ad commit f1282fc

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

libraries/WebServer/examples/HttpBasicAuthSHA1orBearerToken/HttpBasicAuthSHA1orBearerToken.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void setup() {
8787
Serial.println("Bearer token does not look like a hex string ?!");
8888
}
8989

90-
#define _H2D(x) (((x)>='0' && ((x) <='9')) ? ((x)-'0') : (((x)>='a' && (x)<='f') ? ((x)-'a') : 0))
90+
#define _H2D(x) (((x)>='0' && ((x) <='9')) ? ((x)-'0') : (((x)>='a' && (x)<='f') ? ((x)-'a'+10) : 0))
9191
#define H2D(x) (_H2D(tolower((x))))
9292
const char * _shaBase64 = secret_token_hex.c_str();
9393
for (int i = 0; i < 20; i++) {
@@ -116,4 +116,4 @@ void loop() {
116116
ArduinoOTA.handle();
117117
server.handleClient();
118118
delay(2);//allow the cpu to switch to other tasks
119-
}
119+
}

libraries/WebServer/src/WebServer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ bool WebServer::authenticateBasicSHA1(const char * _username, const char * _sha1
161161
// or encode the sha we calculated. We pick the latter as encoding of a
162162
// fixed array of 20 bytes s safer than operating on something external.
163163
//
164-
#define _H2D(x) (((x)>='0' && ((x) <='9')) ? ((x)-'0') : (((x)>='a' && (x)<='f') ? ((x)-'a') : 0))
164+
#define _H2D(x) (((x)>='0' && ((x) <='9')) ? ((x)-'0') : (((x)>='a' && (x)<='f') ? ((x)-'a'+10) : 0))
165165
#define H2D(x) (_H2D(tolower((x))))
166166
if (strlen(_sha1Base64orHex) == 20 * 2) {
167167
for(int i = 0; i < 20; i++) {

0 commit comments

Comments
 (0)