MCPcopy Create free account
hub / github.com/blinker-iot/blinker-library / acceptKey

Method acceptKey

src/modules/WebSockets/WebSockets.cpp:543–562  ·  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

541 * @return String Accept Key
542 */
543String WebSockets::acceptKey(String & clientKey) {
544 uint8_t sha1HashBin[20] = { 0 };
545#ifdef ESP8266
546 sha1(clientKey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", &sha1HashBin[0]);
547#elif defined(ESP32)
548 String data = clientKey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
549 esp_sha(SHA1, (unsigned char *)data.c_str(), data.length(), &sha1HashBin[0]);
550#else
551 clientKey += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
552 SHA1_CTX ctx;
553 SHA1Init(&ctx);
554 SHA1Update(&ctx, (const unsigned char *)clientKey.c_str(), clientKey.length());
555 SHA1Final(&sha1HashBin[0], &ctx);
556#endif
557
558 String key = base64_encode(sha1HashBin, 20);
559 key.trim();
560
561 return key;
562}
563
564/**
565 * base64_encode

Callers

nothing calls this directly

Calls 5

SHA1InitFunction · 0.85
SHA1UpdateFunction · 0.85
SHA1FinalFunction · 0.85
base64_encodeFunction · 0.85
c_strMethod · 0.80

Tested by

no test coverage detected