MCPcopy Create free account
hub / github.com/JoaoLopesF/RemoteDebug / acceptKey

Method acceptKey

src/utility/WebSockets.cpp:485–504  ·  view source on GitHub ↗

* generate the key for Sec-WebSocket-Accept * @param clientKey String * @return String Accept Key */

Source from the content-addressed store, hash-verified

483 * @return String Accept Key
484 */
485String WebSockets::acceptKey(String & clientKey) {
486 uint8_t sha1HashBin[20] = { 0 };
487#ifdef ESP8266
488 sha1(clientKey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", &sha1HashBin[0]);
489#elif defined(ESP32)
490 String data = clientKey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
491 esp_sha(SHA1, (unsigned char*)data.c_str(), data.length(), &sha1HashBin[0]);
492#else
493 clientKey += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
494 SHA1_CTX ctx;
495 SHA1Init(&ctx);
496 SHA1Update(&ctx, (const unsigned char*)clientKey.c_str(), clientKey.length());
497 SHA1Final(&sha1HashBin[0], &ctx);
498#endif
499
500 String key = base64_encode(sha1HashBin, 20);
501 key.trim();
502
503 return key;
504}
505
506/**
507 * base64_encode

Callers

nothing calls this directly

Calls 3

SHA1InitFunction · 0.85
SHA1UpdateFunction · 0.85
SHA1FinalFunction · 0.85

Tested by

no test coverage detected