curveKeyPair

Generates a new Curve key pair.

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.

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

Return Value

Type: Tuple!(char[], "publicKey", char[], "secretKey")

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

$(COREF exception,RangeError) if publicKeyBuf or secretKeyBuf are not null but have a length of less than 41 characters.
ZmqException if $(ZMQ) reports an error.

Corresponds to

$(ZMQREF zmq_curve_keypair())

Examples

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");

Meta