summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2015-09-10 10:22:29 +0000
committerBob Beck <beck@cvs.openbsd.org>2015-09-10 10:22:29 +0000
commit88a0937d27b2170a227eb731fc6e2c03e1e6f221 (patch)
tree30f73b08ad1a7ed69f276553b2c29f492371ff55
parentcf62476995aa2d557f8c44d6cfdbcae71adc3378 (diff)
Change tls_read and tls_write semantics to return an ssize_t to better
match read() and write() semantics to make porting existing code using read/write easier.. requested by bluhm@ who convinced jsing and I to break the api ok jsing@ bluhm@
-rw-r--r--lib/libtls/tls.c28
-rw-r--r--lib/libtls/tls.h7
2 files changed, 14 insertions, 21 deletions
diff --git a/lib/libtls/tls.c b/lib/libtls/tls.c
index fe5bc964e29..c89b805af90 100644
--- a/lib/libtls/tls.c
+++ b/lib/libtls/tls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tls.c,v 1.20 2015/09/10 10:14:20 jsing Exp $ */
+/* $OpenBSD: tls.c,v 1.21 2015/09/10 10:22:28 beck Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@@ -383,13 +383,11 @@ tls_handshake(struct tls *ctx)
return (rv);
}
-int
-tls_read(struct tls *ctx, void *buf, size_t buflen, size_t *outlen)
+ssize_t
+tls_read(struct tls *ctx, void *buf, size_t buflen)
{
+ ssize_t rv = -1;
int ssl_ret;
- int rv = -1;
-
- *outlen = 0;
if ((ctx->state & TLS_HANDSHAKE_COMPLETE) == 0) {
if ((rv = tls_handshake(ctx)) != 0)
@@ -402,24 +400,21 @@ tls_read(struct tls *ctx, void *buf, size_t buflen, size_t *outlen)
}
if ((ssl_ret = SSL_read(ctx->ssl_conn, buf, buflen)) > 0) {
- *outlen = (size_t)ssl_ret;
- rv = 0;
+ rv = (ssize_t)ssl_ret;
goto out;
}
- rv = tls_ssl_error(ctx, ctx->ssl_conn, ssl_ret, "read");
+ rv = (ssize_t)tls_ssl_error(ctx, ctx->ssl_conn, ssl_ret, "read");
out:
errno = 0;
return (rv);
}
-int
-tls_write(struct tls *ctx, const void *buf, size_t buflen, size_t *outlen)
+ssize_t
+tls_write(struct tls *ctx, const void *buf, size_t buflen)
{
+ ssize_t rv = -1;
int ssl_ret;
- int rv = -1;
-
- *outlen = 0;
if ((ctx->state & TLS_HANDSHAKE_COMPLETE) == 0) {
if ((rv = tls_handshake(ctx)) != 0)
@@ -432,12 +427,11 @@ tls_write(struct tls *ctx, const void *buf, size_t buflen, size_t *outlen)
}
if ((ssl_ret = SSL_write(ctx->ssl_conn, buf, buflen)) > 0) {
- *outlen = (size_t)ssl_ret;
- rv = 0;
+ rv = (ssize_t)ssl_ret;
goto out;
}
- rv = tls_ssl_error(ctx, ctx->ssl_conn, ssl_ret, "write");
+ rv = (ssize_t)tls_ssl_error(ctx, ctx->ssl_conn, ssl_ret, "write");
out:
errno = 0;
return (rv);
diff --git a/lib/libtls/tls.h b/lib/libtls/tls.h
index 8548fe1d831..13b88c31d47 100644
--- a/lib/libtls/tls.h
+++ b/lib/libtls/tls.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tls.h,v 1.16 2015/09/10 10:14:20 jsing Exp $ */
+/* $OpenBSD: tls.h,v 1.17 2015/09/10 10:22:28 beck Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@@ -95,9 +95,8 @@ int tls_connect_servername(struct tls *_ctx, const char *_host,
const char *_port, const char *_servername);
int tls_connect_socket(struct tls *_ctx, int _s, const char *_servername);
int tls_handshake(struct tls *_ctx);
-int tls_read(struct tls *_ctx, void *_buf, size_t _buflen, size_t *_outlen);
-int tls_write(struct tls *_ctx, const void *_buf, size_t _buflen,
- size_t *_outlen);
+ssize_t tls_read(struct tls *_ctx, void *_buf, size_t _buflen);
+ssize_t tls_write(struct tls *_ctx, const void *_buf, size_t _buflen);
int tls_close(struct tls *_ctx);
uint8_t *tls_load_file(const char *_file, size_t *_len, char *_password);