* generate the key for Sec-WebSocket-Accept * @param clientKey String * @return String Accept Key */
| 541 | * @return String Accept Key |
| 542 | */ |
| 543 | String 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 |
nothing calls this directly
no test coverage detected