Function curveKeyPair

Generates a new Curve key pair.

std.typecons.Tuple!(char[],"publicKey",char[],"secretKey") curveKeyPair (
  char[] publicKeyBuf = null,
  char[] secretKeyBuf = null
) @safe;

To avoid a memory allocation, preallocated buffers may optionally be supplied for the two keys. Each of these must have a length of at least 41 bytes, enough for a 40-character Z85-encoded key plus a terminating zero byte. If either buffer is omitted/null, a new one will be created.

Returns

A tuple that contains the two keys. Each of these will have a length of 40 characters, and will be slices of the input buffers if such have been provided.

Throws

core.exception.RangeError if publicKeyBuf or secretKeyBuf are not null but have a length of less than 41 characters. ZmqException if ZeroMQ reports an error.

Corresponds to

zmq_curve_keypair()

Example

auto server = Socket(SocketType.rep);
auto serverKeys = curveKeyPair();
server.curveServer = true;
server.curveSecretKeyZ85 = serverKeys.secretKey;
server.bind("inproc://curveKeyPair_test");

auto client = Socket(SocketType.req);
auto clientKeys = curveKeyPair();
client.curvePublicKeyZ85 = clientKeys.publicKey;
client.curveSecretKeyZ85 = clientKeys.secretKey;
client.curveServerKeyZ85 = serverKeys.publicKey;
client.connect("inproc://curveKeyPair_test");
client.send("hello");

ubyte[5] buf;
assert (server.receive(buf) == 5);
assert (buf.asString() == "hello");