Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move "portable_endian.h" to Soter We're going to need these functions in both Soter and Themis, so move the header to Soter. Keep a stub in Themis to avoid breaking existing code. Also note that <sys/param.h> is a POSIX header and it is not available on Windows. Remove it. All conversions are provided by <WinSock2.h>. * Avoid usage of <arpa/inet.h> Unfortunately, Windows systems do not provide this header normally. We use to get access to htonl() and ntohl() functions. On Windows these functions are provided by <WinSock2.h> header (and ws2_32.dll library). We could litter the code with ifdefs, but that's not nice. Instead, let's use the "portable_endian.h" header. It contains all necessary ifdefs, but provides slightly different (and explicit) API: - htonl == htobe32 - ntohl == be32toh Update all code to include common header and use new portable names. * Turn Soter container accessors into functions soter_container.h uses htonl() and ntohl() functions directly in macros. This is not nice because it leaks implementation details and requires POSIX API which is not available on Windows. Furthermore, this header does not even include relevant headers for these functions! Replace this macros with proper functions and move the implementation to soter_container.c which includes "portable_endian.h". This allows our API to not include private headers and does not unnecessarily expose implementation details. Theoretically, this will impact performance, but in practice the effect should be negligible. These macros are not used in any hot paths, and the compiler may even optimize these functions when using LTO. * Safety checks in Soter container accessors Now that we have replaced macros with functions, we can make them more resilient to invalid input. Check pointer parameters for null, return errors where appropriate. Also avoid integer overflow when computing data sizes.
- Loading branch information
Showing
16 changed files
with
264 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.