Skip to content

Commit

Permalink
Added z85 codec to ZMQ API
Browse files Browse the repository at this point in the history
* Removed redundant Z85 code and include files from project
* Simplified use of headers in test cases (now they all just use testutil.hpp)
* Export zmq_z85_encode() and zmq_z85_decode() in API
* Added man pages for these two functions
  • Loading branch information
hintjens committed Sep 15, 2013
1 parent 193d0bb commit 576e3ca
Show file tree
Hide file tree
Showing 53 changed files with 237 additions and 397 deletions.
3 changes: 2 additions & 1 deletion doc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ MAN3 = zmq_bind.3 zmq_unbind.3 zmq_connect.3 zmq_disconnect.3 zmq_close.3 \
zmq_getsockopt.3 zmq_setsockopt.3 \
zmq_socket.3 zmq_socket_monitor.3 zmq_poll.3 \
zmq_errno.3 zmq_strerror.3 zmq_version.3 zmq_proxy.3 \
zmq_sendmsg.3 zmq_recvmsg.3 zmq_init.3 zmq_term.3
zmq_sendmsg.3 zmq_recvmsg.3 zmq_init.3 zmq_term.3 \
zmq_z85_encode.3 zmq_z85_decode.3

MAN7 = zmq.7 zmq_tcp.7 zmq_pgm.7 zmq_epgm.7 zmq_inproc.7 zmq_ipc.7 \
zmq_null.7 zmq_plain.7 zmq_curve.7
Expand Down
2 changes: 2 additions & 0 deletions doc/zmq_curve.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ secret:

SEE ALSO
--------
linkzmq:zmq_z85_encode[3]
linkzmq:zmq_z85_decode[3]
linkzmq:zmq_setsockopt[3]
linkzmq:zmq_null[7]
linkzmq:zmq_plain[7]
Expand Down
50 changes: 50 additions & 0 deletions doc/zmq_z85_decode.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
zmq_z85_decode(3)
=================


NAME
----
zmq_z85_decode - decode a binary key from Z85 printable text


SYNOPSIS
--------
*uint8_t *zmq_z85_decode (uint8_t *dest, char *string);*


DESCRIPTION
-----------
The _zmq_z85_decode()_ function shall decode 'string' into 'dest'.
The length of 'string' shall be divisible by 5. 'dest' must be large
enough for the decoded value (0.8 x strlen (string)).

The encoding shall follow the ZMQ RFC 32 specification.


RETURN VALUE
------------
The _zmq_z85_decode()_ function shall return 'dest' if successful, else it
shall return NULL.


EXAMPLE
-------
.Decoding a CURVE key
----
#include <sodium.h>
char decoded [] = "rq:rM>}U?@Lns47E1%kR.o@n%FcmmsL/@{H8]yf7";
uint8_t public_key [32];
zmq_z85_decode (public_key, decoded);
----


SEE ALSO
--------
linkzmq:zmq_z85_decode[3]
linkzmq:zmq_curve[7]


AUTHORS
-------
This page was written by the 0MQ community. To make a change please
read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.
56 changes: 56 additions & 0 deletions doc/zmq_z85_encode.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
zmq_z85_encode(3)
=================


NAME
----
zmq_z85_encode - encode a binary key as Z85 printable text


SYNOPSIS
--------
*char *zmq_z85_encode (char *dest, uint8_t *data, size_t size);*


DESCRIPTION
-----------
The _zmq_z85_encode()_ function shall encode the binary block specified
by 'data' and 'size' into a string in 'dest'. The size of the binary block
must be divisible by 4. The 'dest' must have sufficient space for size * 1.25
plus 1 for a null terminator. A 32-byte CURVE key is encoded as 40 ASCII
characters plus a null terminator.

The encoding shall follow the ZMQ RFC 32 specification.


RETURN VALUE
------------
The _zmq_z85_encode()_ function shall return 'dest' if successful, else it
shall return NULL.


EXAMPLE
-------
.Encoding a CURVE key
----
#include <sodium.h>
uint8_t public_key [32];
uint8_t secret_key [32];
int rc = crypto_box_keypair (public_key, secret_key);
assert (rc == 0);
char encoded [41];
zmq_z85_encode (encoded, public_key, 32);
puts (encoded);
----


SEE ALSO
--------
linkzmq:zmq_z85_decode[3]
linkzmq:zmq_curve[7]


AUTHORS
-------
This page was written by the 0MQ community. To make a change please
read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.
6 changes: 6 additions & 0 deletions include/zmq.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,12 @@ ZMQ_EXPORT int zmq_poll (zmq_pollitem_t *items, int nitems, long timeout);

ZMQ_EXPORT int zmq_proxy (void *frontend, void *backend, void *capture);

/* Encode a binary key as printable text using ZMQ RFC 32 */
ZMQ_EXPORT char *zmq_z85_encode (char *dest, uint8_t *data, size_t size);

/* Encode a binary key from printable text per ZMQ RFC 32 */
ZMQ_EXPORT uint8_t *zmq_z85_decode (uint8_t *dest, char *string);

/* Deprecated aliases */
#define ZMQ_STREAMER 1
#define ZMQ_FORWARDER 2
Expand Down
5 changes: 5 additions & 0 deletions include/zmq_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#ifndef __ZMQ_UTILS_H_INCLUDED__
#define __ZMQ_UTILS_H_INCLUDED__

#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
1 change: 0 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ libzmq_la_SOURCES = \
ypipe.hpp \
ypipe_flat.hpp \
yqueue.hpp \
z85_codec.hpp \
address.cpp \
clock.cpp \
ctx.cpp \
Expand Down
14 changes: 7 additions & 7 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "options.hpp"
#include "err.hpp"
#include "z85_codec.hpp"
#include "../include/zmq_utils.h"

zmq::options_t::options_t () :
sndhwm (1000),
Expand Down Expand Up @@ -310,7 +310,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
}
else
if (optvallen_ == CURVE_KEYSIZE_Z85) {
Z85_decode (curve_public_key, (char *) optval_);
zmq_z85_decode (curve_public_key, (char *) optval_);
mechanism = ZMQ_CURVE;
return 0;
}
Expand All @@ -324,7 +324,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
}
else
if (optvallen_ == CURVE_KEYSIZE_Z85) {
Z85_decode (curve_secret_key, (char *) optval_);
zmq_z85_decode (curve_secret_key, (char *) optval_);
mechanism = ZMQ_CURVE;
return 0;
}
Expand All @@ -339,7 +339,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
}
else
if (optvallen_ == CURVE_KEYSIZE_Z85) {
Z85_decode (curve_server_key, (char *) optval_);
zmq_z85_decode (curve_server_key, (char *) optval_);
as_server = 0;
mechanism = ZMQ_CURVE;
return 0;
Expand Down Expand Up @@ -591,7 +591,7 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
}
else
if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
Z85_encode ((char *) optval_, curve_public_key, CURVE_KEYSIZE);
zmq_z85_encode ((char *) optval_, curve_public_key, CURVE_KEYSIZE);
return 0;
}
break;
Expand All @@ -603,7 +603,7 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
}
else
if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
Z85_encode ((char *) optval_, curve_secret_key, CURVE_KEYSIZE);
zmq_z85_encode ((char *) optval_, curve_secret_key, CURVE_KEYSIZE);
return 0;
}
break;
Expand All @@ -615,7 +615,7 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
}
else
if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
Z85_encode ((char *) optval_, curve_server_key, CURVE_KEYSIZE);
zmq_z85_encode ((char *) optval_, curve_server_key, CURVE_KEYSIZE);
return 0;
}
break;
Expand Down
109 changes: 0 additions & 109 deletions src/z85_codec.hpp

This file was deleted.

Loading

0 comments on commit 576e3ca

Please sign in to comment.