Fix issue of conversion from size_t to int

ssl_helpers.c is treated with W3 warning level in MSVC complier.
So that it's reported as error for warning of conversion from
size_t to int. This change fixes all this type of warning seen in
Microsoft Visual Studio 12.0. Besides, some potential problems of
type conversion are also handled.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
diff --git a/tests/src/test_helpers/ssl_helpers.c b/tests/src/test_helpers/ssl_helpers.c
index 8dcb6d2..776755c 100644
--- a/tests/src/test_helpers/ssl_helpers.c
+++ b/tests/src/test_helpers/ssl_helpers.c
@@ -196,7 +196,7 @@
     }
 
     buf->content_length += input_len;
-    return input_len;
+    return (input_len > INT_MAX) ? INT_MAX : (int) input_len;
 }
 
 int mbedtls_test_ssl_buffer_get(mbedtls_test_ssl_buffer *buf,
@@ -230,7 +230,7 @@
     buf->content_length -= output_len;
     buf->start = (buf->start + output_len) % buf->capacity;
 
-    return output_len;
+    return (output_len > INT_MAX) ? INT_MAX : (int) output_len;
 }
 
 int mbedtls_test_ssl_message_queue_setup(mbedtls_test_ssl_message_queue *queue,
@@ -241,7 +241,7 @@
         return MBEDTLS_ERR_SSL_ALLOC_FAILED;
     }
 
-    queue->capacity = capacity;
+    queue->capacity = (capacity > INT_MAX) ? INT_MAX : (int) capacity;
     queue->pos = 0;
     queue->num = 0;
 
@@ -276,7 +276,7 @@
     place = (queue->pos + queue->num) % queue->capacity;
     queue->messages[place] = len;
     queue->num++;
-    return len;
+    return (len > INT_MAX) ? INT_MAX : (int) len;
 }
 
 int mbedtls_test_ssl_message_queue_pop_info(
@@ -299,7 +299,8 @@
         queue->pos += queue->capacity;
     }
 
-    return (message_length > buf_len) ? buf_len : message_length;
+    return (message_length > INT_MAX && buf_len > INT_MAX) ? INT_MAX :
+           (message_length > buf_len) ? (int) buf_len : (int) message_length;
 }
 
 /*
@@ -569,7 +570,7 @@
     }
     mbedtls_test_ssl_message_queue_pop_info(queue, buf_len);
 
-    return msg_len;
+    return (msg_len > INT_MAX) ? INT_MAX : (int) msg_len;
 }
 
 #if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
@@ -1151,13 +1152,21 @@
 #endif /* MBEDTLS_CIPHER_MODE_CBC */
 
     CHK(mbedtls_cipher_setkey(&t_in->cipher_ctx_enc, key0,
-                              keylen << 3, MBEDTLS_ENCRYPT) == 0);
+                              (keylen << 3 > INT_MAX) ? INT_MAX : (int) keylen << 3,
+                              MBEDTLS_ENCRYPT)
+        == 0);
     CHK(mbedtls_cipher_setkey(&t_in->cipher_ctx_dec, key1,
-                              keylen << 3, MBEDTLS_DECRYPT) == 0);
+                              (keylen << 3 > INT_MAX) ? INT_MAX : (int) keylen << 3,
+                              MBEDTLS_DECRYPT)
+        == 0);
     CHK(mbedtls_cipher_setkey(&t_out->cipher_ctx_enc, key1,
-                              keylen << 3, MBEDTLS_ENCRYPT) == 0);
+                              (keylen << 3 > INT_MAX) ? INT_MAX : (int) keylen << 3,
+                              MBEDTLS_ENCRYPT)
+        == 0);
     CHK(mbedtls_cipher_setkey(&t_out->cipher_ctx_dec, key0,
-                              keylen << 3, MBEDTLS_DECRYPT) == 0);
+                              (keylen << 3 > INT_MAX) ? INT_MAX : (int) keylen << 3,
+                              MBEDTLS_DECRYPT)
+        == 0);
 #endif
 
     /* Setup MAC contexts */
@@ -1344,12 +1353,12 @@
     /* Add CID */
     memcpy(&t_in->in_cid,  cid0, cid0_len);
     memcpy(&t_in->out_cid, cid1, cid1_len);
-    t_in->in_cid_len = cid0_len;
-    t_in->out_cid_len = cid1_len;
+    t_in->in_cid_len = (uint8_t) cid0_len;
+    t_in->out_cid_len = (uint8_t) cid1_len;
     memcpy(&t_out->in_cid,  cid1, cid1_len);
     memcpy(&t_out->out_cid, cid0, cid0_len);
-    t_out->in_cid_len = cid1_len;
-    t_out->out_cid_len = cid0_len;
+    t_out->in_cid_len = (uint8_t) cid1_len;
+    t_out->out_cid_len = (uint8_t) cid0_len;
 #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
 
 #if defined(MBEDTLS_USE_PSA_CRYPTO)
@@ -2169,7 +2178,7 @@
             /* Invalid certificate request context length.
              */
             *p_certificate_request_context_len =
-                certificate_request_context_len + 1;
+                (unsigned char) certificate_request_context_len + 1;
             reset_chk_buf_ptr_args(args);
             break;