mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-09 07:16:04 +00:00
Added z85 codec to ZMQ API
* 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
This commit is contained in:
parent
193d0bb634
commit
576e3ca5e0
@ -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
|
||||
|
@ -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]
|
||||
|
50
doc/zmq_z85_decode.txt
Normal file
50
doc/zmq_z85_decode.txt
Normal file
@ -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
doc/zmq_z85_encode.txt
Normal file
56
doc/zmq_z85_encode.txt
Normal file
@ -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>.
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -90,7 +90,6 @@ libzmq_la_SOURCES = \
|
||||
ypipe.hpp \
|
||||
ypipe_flat.hpp \
|
||||
yqueue.hpp \
|
||||
z85_codec.hpp \
|
||||
address.cpp \
|
||||
clock.cpp \
|
||||
ctx.cpp \
|
||||
|
@ -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),
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
|
@ -1,109 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
|
||||
|
||||
This file is part of 0MQ.
|
||||
|
||||
0MQ is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
0MQ is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Z85 codec, taken from 0MQ RFC project, implements RFC32 Z85 encoding
|
||||
|
||||
#ifndef __ZMQ_Z85_CODEC_HPP_INCLUDED__
|
||||
#define __ZMQ_Z85_CODEC_HPP_INCLUDED__
|
||||
|
||||
// Maps base 256 to base 85
|
||||
static char encoder [85 + 1] = {
|
||||
"0123456789" "abcdefghij" "klmnopqrst" "uvwxyzABCD"
|
||||
"EFGHIJKLMN" "OPQRSTUVWX" "YZ.-:+=^!/" "*?&<>()[]{"
|
||||
"}@%$#"
|
||||
};
|
||||
|
||||
// Maps base 85 to base 256
|
||||
// We chop off lower 32 and higher 128 ranges
|
||||
static uint8_t decoder [96] = {
|
||||
0x00, 0x44, 0x00, 0x54, 0x53, 0x52, 0x48, 0x00,
|
||||
0x4B, 0x4C, 0x46, 0x41, 0x00, 0x3F, 0x3E, 0x45,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x40, 0x00, 0x49, 0x42, 0x4A, 0x47,
|
||||
0x51, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A,
|
||||
0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32,
|
||||
0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A,
|
||||
0x3B, 0x3C, 0x3D, 0x4D, 0x00, 0x4E, 0x43, 0x00,
|
||||
0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,
|
||||
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
|
||||
0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
|
||||
0x21, 0x22, 0x23, 0x4F, 0x00, 0x50, 0x00, 0x00
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Encode a binary frame as a string; destination string MUST be at least
|
||||
// size * 5 / 4 bytes long plus 1 byte for the null terminator. Returns
|
||||
// dest. Size must be a multiple of 4.
|
||||
|
||||
static char *
|
||||
Z85_encode (char *dest, uint8_t *data, size_t size)
|
||||
{
|
||||
assert (size % 4 == 0);
|
||||
unsigned int char_nbr = 0;
|
||||
unsigned int byte_nbr = 0;
|
||||
uint32_t value = 0;
|
||||
while (byte_nbr < size) {
|
||||
// Accumulate value in base 256 (binary)
|
||||
value = value * 256 + data [byte_nbr++];
|
||||
if (byte_nbr % 4 == 0) {
|
||||
// Output value in base 85
|
||||
unsigned int divisor = 85 * 85 * 85 * 85;
|
||||
while (divisor) {
|
||||
dest [char_nbr++] = encoder [value / divisor % 85];
|
||||
divisor /= 85;
|
||||
}
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
assert (char_nbr == size * 5 / 4);
|
||||
dest [char_nbr] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Decode an encoded string into a binary frame; dest must be at least
|
||||
// strlen (string) * 4 / 5 bytes long. Returns dest. strlen (string)
|
||||
// must be a multiple of 5.
|
||||
|
||||
static uint8_t *
|
||||
Z85_decode (uint8_t *dest, char *string)
|
||||
{
|
||||
assert (strlen (string) % 5 == 0);
|
||||
unsigned int byte_nbr = 0;
|
||||
unsigned int char_nbr = 0;
|
||||
uint32_t value = 0;
|
||||
while (char_nbr < strlen (string)) {
|
||||
// Accumulate value in base 85
|
||||
value = value * 85 + decoder [(uint8_t) string [char_nbr++] - 32];
|
||||
if (char_nbr % 5 == 0) {
|
||||
// Output value in base 256
|
||||
unsigned int divisor = 256 * 256 * 256;
|
||||
while (divisor) {
|
||||
dest [byte_nbr++] = value / divisor % 256;
|
||||
divisor /= 256;
|
||||
}
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
assert (byte_nbr == strlen (string) * 4 / 5);
|
||||
return dest;
|
||||
}
|
||||
|
||||
#endif
|
@ -19,14 +19,11 @@
|
||||
|
||||
#include "platform.hpp"
|
||||
|
||||
#include "../include/zmq_utils.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "stdint.hpp"
|
||||
#include "clock.hpp"
|
||||
#include "err.hpp"
|
||||
#include "thread.hpp"
|
||||
#include <assert.h>
|
||||
#include "../include/zmq_utils.h"
|
||||
|
||||
#if !defined ZMQ_HAVE_WINDOWS
|
||||
#include <unistd.h>
|
||||
@ -72,3 +69,87 @@ void zmq_threadclose(void* thread)
|
||||
pThread->stop();
|
||||
delete pThread;
|
||||
}
|
||||
|
||||
// Z85 codec, taken from 0MQ RFC project, implements RFC32 Z85 encoding
|
||||
|
||||
// Maps base 256 to base 85
|
||||
static char encoder [85 + 1] = {
|
||||
"0123456789" "abcdefghij" "klmnopqrst" "uvwxyzABCD"
|
||||
"EFGHIJKLMN" "OPQRSTUVWX" "YZ.-:+=^!/" "*?&<>()[]{"
|
||||
"}@%$#"
|
||||
};
|
||||
|
||||
// Maps base 85 to base 256
|
||||
// We chop off lower 32 and higher 128 ranges
|
||||
static uint8_t decoder [96] = {
|
||||
0x00, 0x44, 0x00, 0x54, 0x53, 0x52, 0x48, 0x00,
|
||||
0x4B, 0x4C, 0x46, 0x41, 0x00, 0x3F, 0x3E, 0x45,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x40, 0x00, 0x49, 0x42, 0x4A, 0x47,
|
||||
0x51, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A,
|
||||
0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32,
|
||||
0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A,
|
||||
0x3B, 0x3C, 0x3D, 0x4D, 0x00, 0x4E, 0x43, 0x00,
|
||||
0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,
|
||||
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
|
||||
0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
|
||||
0x21, 0x22, 0x23, 0x4F, 0x00, 0x50, 0x00, 0x00
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Encode a binary frame as a string; destination string MUST be at least
|
||||
// size * 5 / 4 bytes long plus 1 byte for the null terminator. Returns
|
||||
// dest. Size must be a multiple of 4.
|
||||
|
||||
char *zmq_z85_encode (char *dest, uint8_t *data, size_t size)
|
||||
{
|
||||
assert (size % 4 == 0);
|
||||
unsigned int char_nbr = 0;
|
||||
unsigned int byte_nbr = 0;
|
||||
uint32_t value = 0;
|
||||
while (byte_nbr < size) {
|
||||
// Accumulate value in base 256 (binary)
|
||||
value = value * 256 + data [byte_nbr++];
|
||||
if (byte_nbr % 4 == 0) {
|
||||
// Output value in base 85
|
||||
unsigned int divisor = 85 * 85 * 85 * 85;
|
||||
while (divisor) {
|
||||
dest [char_nbr++] = encoder [value / divisor % 85];
|
||||
divisor /= 85;
|
||||
}
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
assert (char_nbr == size * 5 / 4);
|
||||
dest [char_nbr] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Decode an encoded string into a binary frame; dest must be at least
|
||||
// strlen (string) * 4 / 5 bytes long. Returns dest. strlen (string)
|
||||
// must be a multiple of 5.
|
||||
|
||||
uint8_t *zmq_z85_decode (uint8_t *dest, char *string)
|
||||
{
|
||||
assert (strlen (string) % 5 == 0);
|
||||
unsigned int byte_nbr = 0;
|
||||
unsigned int char_nbr = 0;
|
||||
uint32_t value = 0;
|
||||
while (char_nbr < strlen (string)) {
|
||||
// Accumulate value in base 85
|
||||
value = value * 85 + decoder [(uint8_t) string [char_nbr++] - 32];
|
||||
if (char_nbr % 5 == 0) {
|
||||
// Output value in base 256
|
||||
unsigned int divisor = 256 * 256 * 256;
|
||||
while (divisor) {
|
||||
dest [byte_nbr++] = value / divisor % 256;
|
||||
divisor /= 256;
|
||||
}
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
assert (byte_nbr == strlen (string) * 4 / 5);
|
||||
return dest;
|
||||
}
|
||||
|
@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../include/zmq_utils.h"
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (int argc, char *argv [])
|
||||
|
@ -17,12 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,9 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,9 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
static void receiver (void *socket)
|
||||
|
@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <zmq.h>
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
/// Initialize a zeromq message with a given null-terminated string
|
||||
|
@ -17,15 +17,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
const char *address = "tcp://127.0.0.1:6571";
|
||||
|
||||
|
@ -17,9 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
const int MAX_SENDS = 10000;
|
||||
|
@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <stdio.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
static void pusher (void *ctx)
|
||||
|
@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include <stdio.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,11 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
// XSI vector I/O
|
||||
|
@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
static void do_bind_and_verify (void *s, const char *endpoint)
|
||||
|
@ -21,9 +21,6 @@
|
||||
// or alternatively we can change policy that issue test cases should be
|
||||
// added to the main build when they're useful. -- PH 2013/09/02
|
||||
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
#define URL "tcp://127.0.0.1:5560"
|
||||
|
@ -17,10 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include "../include/zmq.h"
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
// REQ socket events handled
|
||||
|
@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,7 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,7 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,7 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,9 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,9 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,9 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,7 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,7 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,7 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,9 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,11 +17,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "testutil.hpp"
|
||||
#include "../include/zmq_utils.h"
|
||||
#include "platform.hpp"
|
||||
|
||||
// Test keys from the zmq_curve man page
|
||||
static char client_public [] = "Yne@$w-vo<fVvi]a<NY6T1ed:M$fCG*[IaLV{hID";
|
||||
|
@ -17,9 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
static void
|
||||
|
@ -17,9 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
static void
|
||||
|
@ -17,10 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
#define THREAD_COUNT 100
|
||||
|
@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
const char *bind_address = 0;
|
||||
|
@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
const char *bind_address = 0;
|
||||
|
@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
const char *bind_address = 0;
|
||||
|
@ -17,9 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
const char *bind_address = 0;
|
||||
|
@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
const char *bind_address = 0;
|
||||
|
@ -17,8 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
// ZMTP protocol greeting structure
|
||||
|
@ -17,10 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,8 +17,8 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include "platform.hpp"
|
||||
#include "testutil.hpp"
|
||||
|
||||
#if defined (ZMQ_HAVE_WINDOWS)
|
||||
# include <WinSock2.h>
|
||||
# include <stdexcept>
|
||||
@ -26,7 +26,6 @@
|
||||
# include <sys/socket.h>
|
||||
# include <netinet/in.h>
|
||||
# include <unistd.h>
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
#if defined (ZMQ_HAVE_WINDOWS)
|
||||
|
@ -17,10 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
int main (void)
|
||||
|
@ -17,13 +17,8 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include "../include/zmq_utils.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
setup_test_environment();
|
||||
|
@ -21,15 +21,23 @@
|
||||
#define __TESTUTIL_HPP_INCLUDED__
|
||||
|
||||
#include "../include/zmq.h"
|
||||
#include <string.h>
|
||||
#include "../include/zmq_utils.h"
|
||||
#include "../src/platform.hpp"
|
||||
|
||||
#undef NDEBUG
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <string>
|
||||
|
||||
#if defined _WIN32
|
||||
# include <crtdbg.h>
|
||||
# pragma warning(disable:4996)
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# include <signal.h>
|
||||
# include <stdlib.h>
|
||||
# include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
// Bounce a message from client to server and back
|
||||
|
@ -24,51 +24,11 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "../src/platform.hpp"
|
||||
#include <zmq_utils.h>
|
||||
#ifdef HAVE_LIBSODIUM
|
||||
# include <sodium.h>
|
||||
#endif
|
||||
|
||||
// Maps base 256 to base 85
|
||||
static char encoder [85 + 1] = {
|
||||
"0123456789" "abcdefghij" "klmnopqrst" "uvwxyzABCD"
|
||||
"EFGHIJKLMN" "OPQRSTUVWX" "YZ.-:+=^!/" "*?&<>()[]{"
|
||||
"}@%$#"
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Encode a binary frame as a string; destination string MUST be at least
|
||||
// size * 5 / 4 bytes long plus 1 byte for the null terminator. Returns
|
||||
// dest. Size must be a multiple of 4.
|
||||
|
||||
static char *
|
||||
Z85_encode (char *dest, uint8_t *data, size_t size)
|
||||
{
|
||||
assert (size % 4 == 0);
|
||||
uint char_nbr = 0;
|
||||
uint byte_nbr = 0;
|
||||
uint32_t value = 0;
|
||||
while (byte_nbr < size) {
|
||||
// Accumulate value in base 256 (binary)
|
||||
value = value * 256 + data [byte_nbr++];
|
||||
if (byte_nbr % 4 == 0) {
|
||||
// Output value in base 85
|
||||
uint divisor = 85 * 85 * 85 * 85;
|
||||
while (divisor) {
|
||||
dest [char_nbr++] = encoder [value / divisor % 85];
|
||||
divisor /= 85;
|
||||
}
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
assert (char_nbr == size * 5 / 4);
|
||||
dest [char_nbr] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
#ifdef HAVE_LIBSODIUM
|
||||
@ -91,11 +51,11 @@ int main (void)
|
||||
assert (rc == 0);
|
||||
|
||||
char encoded [41];
|
||||
Z85_encode (encoded, public_key, 32);
|
||||
zmq_z85_encode (encoded, public_key, 32);
|
||||
puts ("\n== CURVE PUBLIC KEY ==");
|
||||
puts (encoded);
|
||||
|
||||
Z85_encode (encoded, secret_key, 32);
|
||||
zmq_z85_encode (encoded, secret_key, 32);
|
||||
puts ("\n== CURVE SECRET KEY ==");
|
||||
puts (encoded);
|
||||
|
||||
|
@ -1,109 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
|
||||
|
||||
This file is part of 0MQ.
|
||||
|
||||
0MQ is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
0MQ is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Z85 codec, taken from 0MQ RFC project, implements RFC32 Z85 encoding
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
// Maps base 256 to base 85
|
||||
static char encoder [85 + 1] = {
|
||||
"0123456789" "abcdefghij" "klmnopqrst" "uvwxyzABCD"
|
||||
"EFGHIJKLMN" "OPQRSTUVWX" "YZ.-:+=^!/" "*?&<>()[]{"
|
||||
"}@%$#"
|
||||
};
|
||||
|
||||
// Maps base 85 to base 256
|
||||
// We chop off lower 32 and higher 128 ranges
|
||||
static uint8_t decoder [96] = {
|
||||
0x00, 0x44, 0x00, 0x54, 0x53, 0x52, 0x48, 0x00,
|
||||
0x4B, 0x4C, 0x46, 0x41, 0x00, 0x3F, 0x3E, 0x45,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x40, 0x00, 0x49, 0x42, 0x4A, 0x47,
|
||||
0x51, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A,
|
||||
0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32,
|
||||
0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A,
|
||||
0x3B, 0x3C, 0x3D, 0x4D, 0x00, 0x4E, 0x43, 0x00,
|
||||
0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,
|
||||
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
|
||||
0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
|
||||
0x21, 0x22, 0x23, 0x4F, 0x00, 0x50, 0x00, 0x00
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Encode a binary frame as a string; destination string MUST be at least
|
||||
// size * 5 / 4 bytes long plus 1 byte for the null terminator. Returns
|
||||
// dest. Size must be a multiple of 4.
|
||||
|
||||
static char *
|
||||
Z85_encode (char *dest, uint8_t *data, size_t size)
|
||||
{
|
||||
assert (size % 4 == 0);
|
||||
uint char_nbr = 0;
|
||||
uint byte_nbr = 0;
|
||||
uint32_t value = 0;
|
||||
while (byte_nbr < size) {
|
||||
// Accumulate value in base 256 (binary)
|
||||
value = value * 256 + data [byte_nbr++];
|
||||
if (byte_nbr % 4 == 0) {
|
||||
// Output value in base 85
|
||||
uint divisor = 85 * 85 * 85 * 85;
|
||||
while (divisor) {
|
||||
dest [char_nbr++] = encoder [value / divisor % 85];
|
||||
divisor /= 85;
|
||||
}
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
assert (char_nbr == size * 5 / 4);
|
||||
dest [char_nbr] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Decode an encoded string into a binary frame; dest must be at least
|
||||
// strlen (string) * 4 / 5 bytes long. Returns dest. strlen (string)
|
||||
// must be a multiple of 5.
|
||||
|
||||
static uint8_t *
|
||||
Z85_decode (uint8_t *dest, char *string)
|
||||
{
|
||||
assert (strlen (string) % 5 == 0);
|
||||
uint byte_nbr = 0;
|
||||
uint char_nbr = 0;
|
||||
uint32_t value = 0;
|
||||
while (char_nbr < strlen (string)) {
|
||||
// Accumulate value in base 85
|
||||
value = value * 85 + decoder [(uint8_t) string [char_nbr++] - 32];
|
||||
if (char_nbr % 5 == 0) {
|
||||
// Output value in base 256
|
||||
uint divisor = 256 * 256 * 256;
|
||||
while (divisor) {
|
||||
dest [byte_nbr++] = value / divisor % 256;
|
||||
divisor /= 256;
|
||||
}
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
assert (byte_nbr == strlen (string) * 4 / 5);
|
||||
return dest;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user