Protocol::ZMTP
ZMTP 3.1 wire protocol: codec, connection, NULL and CURVE mechanisms. No runtime dependencies.
What's in the box
- Codec::Frame: ZMTP frame encode/decode (flags, size, body)
- Codec::Greeting: 64-byte greeting exchange
- Codec::Command: READY, PING/PONG, SUBSCRIBE, etc.
- Connection: per-connection frame I/O, handshake, PING/PONG
- Mechanism::Null: NULL security (no encryption)
- Mechanism::Curve: CurveZMQ (RFC 26) with pluggable crypto backend
- Z85: ZeroMQ RFC 32 encoding
Usage
require "protocol/zmtp"
# NULL mechanism, no encryption
conn = Protocol::ZMTP::Connection.new(
io,
socket_type: "REQ",
mechanism: Protocol::ZMTP::Mechanism::Null.new,
)
conn.handshake!
conn.(["hello"])
msg = conn.
# CURVE mechanism, pass any NaCl-compatible backend
require "protocol/zmtp/mechanism/curve"
require "nuckle" # or: require "rbnacl"
server_mech = Protocol::ZMTP::Mechanism::Curve.server(
public_key, secret_key, crypto: Nuckle,
)
CURVE crypto backend
Mechanism::Curve accepts a crypto: parameter. Any module that
provides the NaCl API:
# RbNaCl (libsodium, fast, constant-time)
Protocol::ZMTP::Mechanism::Curve.server(pub, sec, crypto: RbNaCl)
# Nuckle (pure Ruby, no C dependencies, don't use in production)
Protocol::ZMTP::Mechanism::Curve.server(pub, sec, crypto: Nuckle)
The backend must provide: PrivateKey, PublicKey, Box, SecretBox,
Random, Util, and CryptoError.
License
ISC