example: rename to ustream-example-server
[project/ustream-ssl.git] / ustream-polarssl.c
index 2117189..d55fe04 100644 (file)
@@ -51,12 +51,13 @@ static int s_ustream_read(void *ctx, unsigned char *buf, size_t len)
 static int s_ustream_write(void *ctx, const unsigned char *buf, size_t len)
 {
        struct ustream *s = ctx;
+       int ret;
 
-       len = ustream_write(s, (const char *) buf, len, false);
-       if (len < 0 || s->write_error)
+       ret = ustream_write(s, (const char *) buf, len, false);
+       if (ret < 0 || s->write_error)
                return POLARSSL_ERR_NET_SEND_FAILED;
 
-       return len;
+       return ret;
 }
 
 __hidden void ustream_set_io(void *ctx, void *ssl, struct ustream *conn)
@@ -94,7 +95,11 @@ __hidden void * __ustream_ssl_context_new(bool server)
                return NULL;
 
        uctx->server = server;
+#ifdef USE_VERSION_1_3
+       pk_init(&uctx->key);
+#else
        rsa_init(&uctx->key, RSA_PKCS_V15, 0);
+#endif
 
        return uctx;
 }
@@ -102,8 +107,14 @@ __hidden void * __ustream_ssl_context_new(bool server)
 __hidden int __ustream_ssl_set_crt_file(void *ctx, const char *file)
 {
        struct ustream_polarssl_ctx *uctx = ctx;
+       int ret;
 
-       if (x509parse_crtfile(&uctx->cert, file))
+#ifdef USE_VERSION_1_3
+       ret = x509_crt_parse_file(&uctx->cert, file);
+#else
+       ret = x509parse_crtfile(&uctx->cert, file);
+#endif
+       if (ret)
                return -1;
 
        return 0;
@@ -112,8 +123,14 @@ __hidden int __ustream_ssl_set_crt_file(void *ctx, const char *file)
 __hidden int __ustream_ssl_set_key_file(void *ctx, const char *file)
 {
        struct ustream_polarssl_ctx *uctx = ctx;
+       int ret;
 
-       if (x509parse_keyfile(&uctx->key, file, NULL))
+#ifdef USE_VERSION_1_3
+       ret = pk_parse_keyfile(&uctx->key, file, NULL);
+#else
+       ret = x509parse_keyfile(&uctx->key, file, NULL);
+#endif
+       if (ret)
                return -1;
 
        return 0;
@@ -123,8 +140,13 @@ __hidden void __ustream_ssl_context_free(void *ctx)
 {
        struct ustream_polarssl_ctx *uctx = ctx;
 
+#ifdef USE_VERSION_1_3
+       pk_free(&uctx->key);
+       x509_crt_free(&uctx->cert);
+#else
        rsa_free(&uctx->key);
        x509_free(&uctx->cert);
+#endif
        free(ctx);
 }