Skip to content

Commit 72a3603

Browse files
author
ficeto
committed
Merge pull request #31 from esp8266/esp8266
pull master
2 parents d7679d8 + 73f6f28 commit 72a3603

File tree

8 files changed

+442
-1
lines changed

8 files changed

+442
-1
lines changed

libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ void ESP8266WebServer::_handleRequest() {
251251

252252
const char* ESP8266WebServer::_responseCodeToString(int code) {
253253
switch (code) {
254+
case 101: return "Switching Protocols";
254255
case 200: return "OK";
256+
case 403: return "Forbidden";
255257
case 404: return "Not found";
256258
case 500: return "Fail";
257259
default: return "";

libraries/Hash/examples/sha1.ino

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* simple demo to show sha1 calculation
3+
*/
4+
#include <Arduino.h>
5+
#include <Hash.h>
6+
7+
void setup() {
8+
Serial.begin(921600);
9+
}
10+
11+
void loop() {
12+
13+
// usage as String
14+
// SHA1:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
15+
16+
Serial.print("SHA1:");
17+
Serial.println(sha1("abc"));
18+
19+
// usage as ptr
20+
// SHA1:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
21+
uint8_t hash[20];
22+
sha1("abc", &hash[0]);
23+
24+
Serial.print("SHA1:");
25+
for(uint16_t i = 0; i < 20; i++) {
26+
Serial.printf("%02x", hash[i]);
27+
}
28+
Serial.println();
29+
30+
delay(1000);
31+
}
32+

libraries/Hash/library.properties

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name=Hash
2+
version=1.0
3+
author=Markus Sattler
4+
maintainer=Markus Sattler
5+
sentence=Generate Hash from data
6+
paragraph=
7+
url=
8+
architectures=esp8266

libraries/Hash/src/Hash.cpp

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* @file Hash.cpp
3+
* @date 20.05.2015
4+
* @author Markus Sattler
5+
*
6+
* Copyright (c) 2015 Markus Sattler. All rights reserved.
7+
* This file is part of the esp8266 core for Arduino environment.
8+
*
9+
* This library is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* This library is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with this library; if not, write to the Free Software
21+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22+
*
23+
*/
24+
25+
#include <Arduino.h>
26+
27+
#include "Hash.h"
28+
29+
extern "C" {
30+
#include "sha1/sha1.h"
31+
}
32+
33+
/**
34+
* create a sha1 hash from data
35+
* @param data uint8_t *
36+
* @param size uint32_t
37+
* @param hash uint8_t[20]
38+
*/
39+
void sha1(uint8_t * data, uint32_t size, uint8_t hash[20]) {
40+
41+
SHA1_CTX ctx;
42+
43+
#ifdef DEBUG_SHA1
44+
os_printf("DATA:");
45+
for(uint16_t i = 0; i < size; i++) {
46+
os_printf("%02X", data[i]);
47+
}
48+
os_printf("\n");
49+
os_printf("DATA:");
50+
for(uint16_t i = 0; i < size; i++) {
51+
os_printf("%c", data[i]);
52+
}
53+
os_printf("\n");
54+
#endif
55+
56+
SHA1Init(&ctx);
57+
SHA1Update(&ctx, data, size);
58+
SHA1Final(hash, &ctx);
59+
60+
#ifdef DEBUG_SHA1
61+
os_printf("SHA1:");
62+
for(uint16_t i = 0; i < 20; i++) {
63+
os_printf("%02X", hash[i]);
64+
}
65+
os_printf("\n\n");
66+
#endif
67+
}
68+
69+
void sha1(char * data, uint32_t size, uint8_t hash[20]) {
70+
sha1((uint8_t *) data, size, hash);
71+
}
72+
73+
void sha1(const uint8_t * data, uint32_t size, uint8_t hash[20]) {
74+
sha1((uint8_t *) data, size, hash);
75+
}
76+
77+
void sha1(const char * data, uint32_t size, uint8_t hash[20]) {
78+
sha1((uint8_t *) data, size, hash);
79+
}
80+
81+
void sha1(String data, uint8_t hash[20]) {
82+
sha1(data.c_str(), data.length(), hash);
83+
}
84+
85+
String sha1(uint8_t* data, uint32_t size) {
86+
uint8_t hash[20];
87+
String hashStr = "";
88+
89+
sha1(&data[0], size, &hash[0]);
90+
91+
for(uint16_t i = 0; i < 20; i++) {
92+
String hex = String(hash[i], HEX);
93+
if(hex.length() < 2) {
94+
hex = "0" + hex;
95+
}
96+
hashStr += hex;
97+
}
98+
99+
return hashStr;
100+
}
101+
102+
String sha1(char* data, uint32_t size) {
103+
return sha1((uint8_t*) data, size);
104+
}
105+
106+
String sha1(const uint8_t* data, uint32_t size) {
107+
return sha1((uint8_t*) data, size);
108+
}
109+
110+
String sha1(const char* data, uint32_t size) {
111+
return sha1((uint8_t*) data, size);
112+
}
113+
114+
String sha1(String data) {
115+
return sha1(data.c_str(), data.length());
116+
}
117+

libraries/Hash/src/Hash.h

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @file Hash.h
3+
* @date 20.05.2015
4+
* @author Markus Sattler
5+
*
6+
* Copyright (c) 2015 Markus Sattler. All rights reserved.
7+
* This file is part of the esp8266 core for Arduino environment.
8+
*
9+
* This library is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* This library is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with this library; if not, write to the Free Software
21+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22+
*
23+
*/
24+
25+
#ifndef HASH_H_
26+
#define HASH_H_
27+
28+
//#define DEBUG_SHA1
29+
30+
void sha1(uint8_t * data, uint32_t size, uint8_t hash[20]);
31+
void sha1(char * data, uint32_t size, uint8_t hash[20]);
32+
void sha1(const uint8_t * data, uint32_t size, uint8_t hash[20]);
33+
void sha1(const char * data, uint32_t size, uint8_t hash[20]);
34+
void sha1(String data, uint8_t hash[20]);
35+
36+
String sha1(uint8_t* data, uint32_t size);
37+
String sha1(char* data, uint32_t size);
38+
String sha1(const uint8_t* data, uint32_t size);
39+
String sha1(const char* data, uint32_t size);
40+
String sha1(String data);
41+
42+
#endif /* HASH_H_ */

0 commit comments

Comments
 (0)