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