For both security and ease of use, we want to use crypto::string as much as possible. This makes it easy to run all our cryptographic functions on the handshake and transport, but it raises an issue in that these objects are not contiguous values in memory (Or, they are, but casting it into a character array isn't going to get you the bytes). If you tried to just cast the string and send it across the wire, you'd get garbage. Instead, we need to Serialize and Expand from a collection of crypto::strings making up a packet (Whether that be the handshake packets or transport packets), so that we can work with crypto::string, but be able to serialize it down when we need to send it, and construct it back from bytes when receiving it. To unify this functionality, the Packet object contains a list of crypto::string's in a vector and will serialize the contents of it, and construct a itself from bytes. Other objects derive from this class, and specify the size of the vector and its elements, and values to access specific parts.
More...
#include <wireguard.h>
|
std::string | Serialize () |
| Serialize the packet.
|
|
void | Expand (const std::string &buffer, const bool &fill=false) |
| Construct a Packet from a std::string.
|
|
For both security and ease of use, we want to use crypto::string as much as possible. This makes it easy to run all our cryptographic functions on the handshake and transport, but it raises an issue in that these objects are not contiguous values in memory (Or, they are, but casting it into a character array isn't going to get you the bytes). If you tried to just cast the string and send it across the wire, you'd get garbage. Instead, we need to Serialize and Expand from a collection of crypto::strings making up a packet (Whether that be the handshake packets or transport packets), so that we can work with crypto::string, but be able to serialize it down when we need to send it, and construct it back from bytes when receiving it. To unify this functionality, the Packet object contains a list of crypto::string's in a vector and will serialize the contents of it, and construct a itself from bytes. Other objects derive from this class, and specify the size of the vector and its elements, and values to access specific parts.
◆ Expand()
void wireguard::Packet::Expand |
( |
const std::string & | buffer, |
|
|
const bool & | fill = false ) |
|
inline |
Construct a Packet from a std::string.
- Parameters
-
buffer | The byte array obtained by Serialize. |
fill | Some Packets, like the TransportPacket, do not have a fixed size for the final element. When fill is enabled, the final member of the vector will be provided the remainder of the string's bytes. |
◆ Serialize()
std::string wireguard::Packet::Serialize |
( |
| ) |
|
|
inline |
Serialize the packet.
- Returns
- A std::string representation that can be sent across the wire.
The documentation for this class was generated from the following file: