hannestschofenig / mbedtls

An open source, portable, easy to use, readable and flexible SSL library
https://tls.mbed.org
Apache License 2.0
15 stars 8 forks source link

Add wrapper to have MPS/non-MPS agnostic message parsers #348

Closed hanno-becker closed 3 years ago

hanno-becker commented 3 years ago

This PR introduces a helper function for fetching handshake messages of a given expected type,

int mbedtls_ssl_fetch_handshake_msg( mbedtls_ssl_context *ssl,
                                     unsigned hs_type,
                                     unsigned char **buf,
                                     size_t *buflen )

which is implemented based on either MPS or the legacy messaging layer, depending on MBEDTLS_SSL_USE_MPS. The handshake state handlers now use primarily this function instead of the previous MPS/non-MPS #ifdef-salad, which makes the code both shorter and easier to read.