-
Notifications
You must be signed in to change notification settings - Fork 51
Change mbedtls_platform_context parameter to NULL #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,13 +47,8 @@ static const char hello_str[] = "Hello, world!"; | |
static const unsigned char *hello_buffer = (const unsigned char *) hello_str; | ||
static const size_t hello_len = strlen(hello_str); | ||
|
||
static int example(mbedtls_platform_context* ctx) | ||
static int example() | ||
{ | ||
// The call below is used to avoid the "unused parameter" warning. | ||
// The context itself can be used by cryptographic calls which require it. | ||
// Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more information. | ||
(void)ctx; | ||
|
||
mbedtls_printf("\n\n"); | ||
|
||
/* | ||
|
@@ -157,20 +152,19 @@ static int example(mbedtls_platform_context* ctx) | |
} | ||
|
||
int main() { | ||
mbedtls_platform_context platform_ctx; | ||
int exit_code = MBEDTLS_EXIT_FAILURE; | ||
|
||
if((exit_code = mbedtls_platform_setup(&platform_ctx)) != 0) { | ||
if((exit_code = mbedtls_platform_setup(NULL)) != 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same review comment as before - remove the assignment to |
||
printf("Platform initialization failed with error %d\n", exit_code); | ||
return MBEDTLS_EXIT_FAILURE; | ||
} | ||
|
||
exit_code = example(&platform_ctx); | ||
exit_code = example(); | ||
if (exit_code != 0) { | ||
mbedtls_printf("Example failed with error %d\n", exit_code); | ||
exit_code = MBEDTLS_EXIT_FAILURE; | ||
} | ||
|
||
mbedtls_platform_teardown(&platform_ctx); | ||
mbedtls_platform_teardown(NULL); | ||
return exit_code; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,10 +50,9 @@ const int SERVER_PORT = 443; | |
*/ | ||
int main() | ||
{ | ||
mbedtls_platform_context platform_ctx; | ||
int exit_code = MBEDTLS_EXIT_FAILURE; | ||
|
||
if((exit_code = mbedtls_platform_setup(&platform_ctx)) != 0) { | ||
if((exit_code = mbedtls_platform_setup(NULL)) != 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above - remove the assignment to |
||
printf("Platform initialization failed with error %d\r\n", exit_code); | ||
return MBEDTLS_EXIT_FAILURE; | ||
} | ||
|
@@ -74,13 +73,12 @@ int main() | |
#endif /* MBEDTLS_MAJOR_VERSION */ | ||
|
||
/* Allocate a HTTPS client */ | ||
client = new (std::nothrow) HelloHttpsClient(SERVER_NAME, SERVER_ADDR, SERVER_PORT, | ||
&platform_ctx); | ||
client = new (std::nothrow) HelloHttpsClient(SERVER_NAME, SERVER_ADDR, SERVER_PORT); | ||
|
||
if (client == NULL) { | ||
mbedtls_printf("Failed to allocate HelloHttpsClient object\n" | ||
"\nFAIL\n"); | ||
mbedtls_platform_teardown(&platform_ctx); | ||
mbedtls_platform_teardown(NULL); | ||
return exit_code; | ||
} | ||
|
||
|
@@ -94,6 +92,6 @@ int main() | |
|
||
delete client; | ||
|
||
mbedtls_platform_teardown(&platform_ctx); | ||
mbedtls_platform_teardown(NULL); | ||
return exit_code; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is assigning an error code from
mbedtls_platform_setup()
to anexit_code
used to exitmain()
. They are two different sets of values - and the error values don't map to valid exit codes. Initialiseexit_code
toMBEDTLS_EXIT_SUCCESS
and remove these follow on assignments. They're not needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbutcher-arm I disagree.
Although the exit code is not the return code of the functions, we use it for logging the error code. When we exit the application upon failure, the return code will always be
MBEDTLS_EXIT_FAILURE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I disagree. ;) I think it's reusing the variable for two different purposes with sets of values that don't necessarily mix. But it's a pre-existing problem, so I think I can ignore it for the moment, as the code works, just doesn't match my expectations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I created #205 to track this