Data encoding/decoding, mask processing, etc.
More...
#include <sttnet_English.h>
|
| static std::string | base64_encode (const std::string &input) |
| | Base64 encode a string. More...
|
| |
| static std::string | base64_decode (const std::string &input) |
| | Decode a Base64 encoded string. More...
|
| |
| static std::string & | transfer_websocket_key (std::string &str) |
| | Generate the Sec-WebSocket-Accept field value in the WebSocket handshake response. More...
|
| |
| static std::string & | generateMask_4 (std::string &mask) |
| | Generate a 32-bit (4-byte) random mask. More...
|
| |
| static std::string & | maskCalculate (std::string &data, const std::string &mask) |
| | Perform XOR operation (XOR Masking) on a string using a given 4-byte mask. More...
|
| |
Data encoding/decoding, mask processing, etc.
| static std::string stt::data::EncodingUtil::base64_decode |
( |
const std::string & |
input | ) |
|
|
static |
Decode a Base64 encoded string.
Uses OpenSSL's BIO interface to decode the Base64 string. This function does not accept Base64 strings with line breaks.
- Parameters
-
| input | Base64 encoded string. |
- Returns
- Decoded original string.
| static std::string stt::data::EncodingUtil::base64_encode |
( |
const std::string & |
input | ) |
|
|
static |
Base64 encode a string.
Uses OpenSSL's BIO interface to Base64 encode the given string without inserting line breaks during encoding.
- Parameters
-
| input | Original string to be encoded (can contain any binary data). |
- Returns
- Encoded Base64 string.
| static std::string& stt::data::EncodingUtil::generateMask_4 |
( |
std::string & |
mask | ) |
|
|
static |
Generate a 32-bit (4-byte) random mask.
This function first randomly generates a 32-bit string composed of '0' and '1' (e.g., "010110..."), then converts it into the corresponding 4-byte binary data through the internal BitUtil::toBit() function.
The conversion result is returned via the mask parameter, which is typically used to generate packet masks, encryption masks, bitmap masks, etc.
- Parameters
-
| mask | Used to store the final generated 4-byte mask (binary string form). |
- Returns
- Reference to mask.
- Note
- Internally depends on the function
BitUtil::toBit(const std::string&, std::string&) to compress the 32-bit binary string into 4 bytes.
| static std::string& stt::data::EncodingUtil::maskCalculate |
( |
std::string & |
data, |
|
|
const std::string & |
mask |
|
) |
| |
|
static |
Perform XOR operation (XOR Masking) on a string using a given 4-byte mask.
This function XORs each byte of the input string data with the 4 bytes in the mask in sequence. This operation is reversible and can be used to encrypt or decrypt masked data frames in WebSocket.
- Parameters
-
| data | The data string to be XOR processed, which will be modified directly. |
| mask | The string used as the mask, typically at least 4 bytes. |
- Returns
- Reference to the processed data string.
| static std::string& stt::data::EncodingUtil::transfer_websocket_key |
( |
std::string & |
str | ) |
|
|
static |
Generate the Sec-WebSocket-Accept field value in the WebSocket handshake response.
Based on the Sec-WebSocket-Key provided by the client, this function concatenates the WebSocket-specified magic GUID, then performs SHA-1 hashing and Base64 encoding to obtain the accept string required for the handshake response.
- Parameters
-
| str | The input is the Sec-WebSocket-Key provided by the client, which will be modified in place to the result string (Sec-WebSocket-Accept). |
- Returns
- Reference to the modified str.
- Note
- The implementation refers to the handshake process in Section 4.2.2 of RFC 6455.
The documentation for this class was generated from the following file: