Skip to content

Commit

Permalink
Return EINVAL when trying to use CURVE without libsodium
Browse files Browse the repository at this point in the history
  • Loading branch information
hintjens committed Jun 28, 2013
1 parent 357a9c4 commit 76df045
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,10 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
return 0;
}
break;


// If libsodium isn't installed, these options provoke EINVAL
# ifdef HAVE_LIBSODIUM
case ZMQ_CURVE_SERVER:
# ifndef HAVE_LIBSODIUM
puts ("E: libzmq was not built using libsodium, CURVE not available");
assert (false);
# endif
if (is_int && (value == 0 || value == 1)) {
as_server = value;
mechanism = value? ZMQ_CURVE: ZMQ_NULL;
Expand All @@ -298,10 +296,6 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
break;

case ZMQ_CURVE_PUBLICKEY:
# ifndef HAVE_LIBSODIUM
puts ("E: libzmq was not built using libsodium, CURVE not available");
assert (false);
# endif
if (optvallen_ == CURVE_KEYSIZE) {
memcpy (curve_public_key, optval_, CURVE_KEYSIZE);
mechanism = ZMQ_CURVE;
Expand All @@ -310,10 +304,6 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
break;

case ZMQ_CURVE_SECRETKEY:
# ifndef HAVE_LIBSODIUM
puts ("E: libzmq was not built using libsodium, CURVE not available");
assert (false);
# endif
if (optvallen_ == CURVE_KEYSIZE) {
memcpy (curve_secret_key, optval_, CURVE_KEYSIZE);
mechanism = ZMQ_CURVE;
Expand All @@ -322,20 +312,14 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
break;

case ZMQ_CURVE_SERVERKEY:
# ifndef HAVE_LIBSODIUM
puts ("E: libzmq was not built using libsodium, CURVE not available");
assert (false);
# endif
if (optvallen_ == CURVE_KEYSIZE) {
memcpy (curve_server_key, optval_, CURVE_KEYSIZE);
as_server = 0;
mechanism = ZMQ_CURVE;
return 0;
}
break;

default:
break;
# endif
}
errno = EINVAL;
return -1;
Expand Down Expand Up @@ -555,6 +539,8 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
}
break;

// If libsodium isn't installed, these options provoke EINVAL
# ifdef HAVE_LIBSODIUM
case ZMQ_CURVE_SERVER:
if (is_int) {
*value = as_server && mechanism == ZMQ_CURVE;
Expand Down Expand Up @@ -582,6 +568,7 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
return 0;
}
break;
# endif
}
errno = EINVAL;
return -1;
Expand Down

0 comments on commit 76df045

Please sign in to comment.