News
Shop
Learn
Community
Ein Bild oder sowas
LUCIDAC Documentation
User Docs
Pybrid
Julia
C++
Firmware
REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
websockets.cpp
Go to the documentation of this file.
1
2
// Code from https://github.com/gilmaimon/TinyWebsockets
3
#include <Arduino.h>
4
#include <utils/dcp.h>
5
#include <utils/etl_base64.h>
6
#include <utils/logging.h>
7
#include <web/websockets.h>
8
9
/*
10
11
This can be manually unit tested with these two example fixtures
12
13
websocketsHandshakeEncodeKey("dGhlIHNhbXBsZSBub25jZQ==") == "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="
14
websocketsHandshakeEncodeKey("x3JJHMbDL1EzLkh9GBhXDw==") == "HSmrc0sMlYUkAGmm5OPpG2HaGWk=");
15
16
i.e. with curl:
17
18
curl --verbose -H "Upgrade: websocket" -H "Connection: Upgrade" -H "Sec-Websocket-Version: 13" -H
19
"Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==" http://lucidac-17-40-f4.fritz.box/websocket
20
21
*/
22
FLASHMEM
23
std::string web::websocketsHandshakeEncodeKey(
const
char
*key) {
24
if
(!key)
25
return
""
;
26
27
std::string input(key);
28
input +=
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
;
29
30
utils::sha1 sha1((
const
uint8_t *)input.c_str(), input.size());
31
// LOGMEV("sha1('%s') = '%s'\n", key, sha1.to_string());
32
33
char
retkey[30 + 1] = {0};
34
etl::base64::encode(sha1.checksum.data(), 20, retkey, 30);
35
36
// LOGMEV("base64encode('%s') = '%s'\n", sha1.to_string(), retkey);
37
38
return
retkey;
39
}
lib
core
src
web
websockets.cpp
Generated by
1.12.0