check consistency of `ptls_context_t` upon instantiation
diff --git a/lib/picotls.c b/lib/picotls.c
index f44d253..6c86295 100644
--- a/lib/picotls.c
+++ b/lib/picotls.c
@@ -2353,7 +2353,6 @@
/* use external PSK if provided */
if (tls->ctx->pre_shared_key.identity.base != NULL) {
if (!is_second_flight) {
- assert(tls->ctx->pre_shared_key.hash != NULL);
tls->client.offered_psk = 1;
for (size_t i = 0; tls->ctx->cipher_suites[i] != NULL; ++i) {
if (tls->ctx->cipher_suites[i]->hash == tls->ctx->pre_shared_key.hash) {
@@ -4092,9 +4091,7 @@
ptls_client_hello_psk_identity_t *identity = ch->psk.identities.list + *psk_index;
/* negotiate using fixed pre-shared key */
- if (tls->ctx->pre_shared_key.secret.base != NULL) {
- assert(tls->ctx->pre_shared_key.secret.len != 0 && tls->ctx->pre_shared_key.identity.len != 0 &&
- tls->ctx->pre_shared_key.hash != NULL && "`ptls_context_t::pre_shared_key` in incosistent state");
+ if (tls->ctx->pre_shared_key.identity.base != NULL) {
if (identity->identity.len == tls->ctx->pre_shared_key.identity.len &&
memcmp(identity->identity.base, tls->ctx->pre_shared_key.identity.base, identity->identity.len) == 0) {
*accept_early_data = ch->psk.early_data_indication && *psk_index == 0;
@@ -5074,7 +5071,17 @@
{
ptls_t *tls;
+ /* check consistency of `ptls_context_t` before instantiating a connection object */
assert(ctx->get_time != NULL && "please set ctx->get_time to `&ptls_get_time`; see #92");
+ if (ctx->pre_shared_key.identity.base != NULL) {
+ assert(ctx->pre_shared_key.identity.len != 0 && ctx->pre_shared_key.secret.base != NULL &&
+ ctx->pre_shared_key.secret.len != 0 && ctx->pre_shared_key.hash != NULL &&
+ "`ptls_context_t::pre_shared_key` in incosistent state");
+ } else {
+ assert(ctx->pre_shared_key.identity.len == 0 && ctx->pre_shared_key.secret.base == NULL &&
+ ctx->pre_shared_key.secret.len == 0 && ctx->pre_shared_key.hash == NULL &&
+ "`ptls_context_t::pre_shared_key` in inconsitent state");
+ }
if ((tls = malloc(sizeof(*tls))) == NULL)
return NULL;