# Path: azmq/crypto.py
# @requires_libsodium
# def curve_gen_keypair():
#     """
#     Generate and return a pair of (public, secret) keys for use with the CURVE
#     mechanism.
# 
#     :returns: A public, secret key pair, as a tuple.
#     """
#     return crypto_box_keypair()
# 
# Path: azmq/mechanisms/curve_client.py
# class CurveClient(object):
#     @requires_libsodium
#     def __init__(
#         self,
#         server_key,
#         public_key=None,
#         secret_key=None,
#     ):
#         self.set_permanent_server_key(server_key)
# 
#         if public_key or secret_key:
#             self.set_permanent_keypair(
#                 public_key=public_key,
#                 secret_key=secret_key,
#             )
#         else:
#             self.public_key = None
#             self.secret_key = None
# 
#     def set_permanent_server_key(self, server_key):
#         assert server_key and len(server_key) == 32, (
#             "A 32 bytes server key must be specified."
#         )
#         self.server_key = server_key
# 
#     def set_permanent_keypair(self, public_key, secret_key):
#         assert public_key and len(public_key) == 32, (
#             "A 32 bytes public key must be specified."
#         )
#         assert secret_key and len(secret_key) == 32, (
#             "A 32 bytes secret key must be specified."
#         )
#         self.public_key = public_key
#         self.secret_key = secret_key
# 
#     def __call__(self):
#         assert self.server_key, "No server key was specified."
# 
#         if not self.public_key:
#             logger.info(
#                 "No keypair was specified for CURVE client. Generating a "
#                 "random one.",
#             )
#             self.public_key, self.secret_key = crypto_box_keypair()
# 
#         return CurveClientMechanism(
#             server_key=self.server_key,
#             public_key=self.public_key,
#             secret_key=self.secret_key,
#         )
# 
# Path: azmq/mechanisms/curve_server.py
# class CurveServer(object):
#     @requires_libsodium
#     def __init__(self, public_key=None, secret_key=None):
#         self.set_permanent_keypair(
#             public_key=public_key,
#             secret_key=secret_key,
#         )
# 
#     def set_permanent_keypair(self, public_key, secret_key):
#         assert public_key and len(public_key) == 32, (
#             "A 32 bytes public key must be specified."
#         )
#         assert secret_key and len(secret_key) == 32, (
#             "A 32 bytes secret key must be specified."
#         )
#         self.public_key = public_key
#         self.secret_key = secret_key
# 
#     def __call__(self):
#         return CurveServerMechanism(
#             public_key=self.public_key,
#             secret_key=self.secret_key,
#         )
# 
# Path: azmq/mechanisms/plain_client.py
# class PlainClient(object):
#     def __init__(self, username, password):
#         assert len(username) < 256, "username can't exceed 255 bytes"
#         assert len(password) < 256, "password can't exceed 255 bytes"
# 
#         self.username = username
#         self.password = password
# 
#     def __call__(self):
#         return PlainClientMechanism(
#             username=self.username,
#             password=self.password,
#         )
# 
# Path: azmq/mechanisms/plain_server.py
# class PlainServer(object):
#     def __call__(self):
#         return PlainServerMechanism()
# 
# Path: tests/conftest.py
# def event_loop():
# def reader():
#     async def readexactly(count):
# def writer():
# ENDPOINTS = [
#     'inproc://mypath',
#     'tcp://127.0.0.1:3333',
# ]


import asyncio
import pytest
import zmq
import zmq.auth
import azmq
from zmq.auth.thread import ThreadAuthenticator
from contextlib import (
    ExitStack,
    contextmanager,
)
from concurrent.futures import Future
from threading import (
    Event,
    Thread,
)
from azmq.crypto import curve_gen_keypair
from azmq.mechanisms import (
    CurveClient,
    CurveServer,
    PlainClient,
    PlainServer,
)
from ..conftest import requires_libsodium
        assert frames == [b'1' * 500, b'2' * 100000]
        rep_socket.send_multipart([b'3' * 500, b'4' * 100000])

    with run_in_background(run):
        async with azmq.Context(loop=event_loop) as context:
            socket = context.socket(azmq.REQ)
            connect_or_bind(socket, 'tcp://127.0.0.1:3333')
            await asyncio.wait_for(
                socket.send_multipart([b'1' * 500, b'2' * 100000]),
                1,
            )
            frames = await asyncio.wait_for(socket.recv_multipart(), 1)
            assert frames == [b'3' * 500, b'4' * 100000]


@requires_libsodium
@pytest.mark.parametrize("link", [
    'bind',
    'connect',
])
@pytest.mark.asyncio
async def test_tcp_socket_curve_server(
    event_loop,
    socket_factory,
    connect_or_bind,
):
    rep_socket = socket_factory.create(zmq.REP)
    cpublic, csecret = curve_gen_keypair()
    rep_socket.curve_publickey = cpublic
    rep_socket.curve_secretkey = csecret

# Path: azmq/crypto.py
# @requires_libsodium
# def curve_gen_keypair():
#     """
#     Generate and return a pair of (public, secret) keys for use with the CURVE
#     mechanism.
# 
#     :returns: A public, secret key pair, as a tuple.
#     """
#     return crypto_box_keypair()
# 
# Path: azmq/mechanisms/curve_client.py
# class CurveClient(object):
#     @requires_libsodium
#     def __init__(
#         self,
#         server_key,
#         public_key=None,
#         secret_key=None,
#     ):
#         self.set_permanent_server_key(server_key)
# 
#         if public_key or secret_key:
#             self.set_permanent_keypair(
#                 public_key=public_key,
#                 secret_key=secret_key,
#             )
#         else:
#             self.public_key = None
#             self.secret_key = None
# 
#     def set_permanent_server_key(self, server_key):
#         assert server_key and len(server_key) == 32, (
#             "A 32 bytes server key must be specified."
#         )
#         self.server_key = server_key
# 
#     def set_permanent_keypair(self, public_key, secret_key):
#         assert public_key and len(public_key) == 32, (
#             "A 32 bytes public key must be specified."
#         )
#         assert secret_key and len(secret_key) == 32, (
#             "A 32 bytes secret key must be specified."
#         )
#         self.public_key = public_key
#         self.secret_key = secret_key
# 
#     def __call__(self):
#         assert self.server_key, "No server key was specified."
# 
#         if not self.public_key:
#             logger.info(
#                 "No keypair was specified for CURVE client. Generating a "
#                 "random one.",
#             )
#             self.public_key, self.secret_key = crypto_box_keypair()
# 
#         return CurveClientMechanism(
#             server_key=self.server_key,
#             public_key=self.public_key,
#             secret_key=self.secret_key,
#         )
# 
# Path: azmq/mechanisms/curve_server.py
# class CurveServer(object):
#     @requires_libsodium
#     def __init__(self, public_key=None, secret_key=None):
#         self.set_permanent_keypair(
#             public_key=public_key,
#             secret_key=secret_key,
#         )
# 
#     def set_permanent_keypair(self, public_key, secret_key):
#         assert public_key and len(public_key) == 32, (
#             "A 32 bytes public key must be specified."
#         )
#         assert secret_key and len(secret_key) == 32, (
#             "A 32 bytes secret key must be specified."
#         )
#         self.public_key = public_key
#         self.secret_key = secret_key
# 
#     def __call__(self):
#         return CurveServerMechanism(
#             public_key=self.public_key,
#             secret_key=self.secret_key,
#         )
# 
# Path: azmq/mechanisms/plain_client.py
# class PlainClient(object):
#     def __init__(self, username, password):
#         assert len(username) < 256, "username can't exceed 255 bytes"
#         assert len(password) < 256, "password can't exceed 255 bytes"
# 
#         self.username = username
#         self.password = password
# 
#     def __call__(self):
#         return PlainClientMechanism(
#             username=self.username,
#             password=self.password,
#         )
# 
# Path: azmq/mechanisms/plain_server.py
# class PlainServer(object):
#     def __call__(self):
#         return PlainServerMechanism()
# 
# Path: tests/conftest.py
# def event_loop():
# def reader():
#     async def readexactly(count):
# def writer():
# ENDPOINTS = [
#     'inproc://mypath',
#     'tcp://127.0.0.1:3333',
# ]


# Path: tests/integration/test_interoperability.py
import asyncio
import pytest
import zmq
import zmq.auth
import azmq
from zmq.auth.thread import ThreadAuthenticator
from contextlib import (
    ExitStack,
    contextmanager,
)
from concurrent.futures import Future
from threading import (
    Event,
    Thread,
)
from azmq.crypto import curve_gen_keypair
from azmq.mechanisms import (
    CurveClient,
    CurveServer,
    PlainClient,
    PlainServer,
)
from ..conftest import requires_libsodium

        assert frames == [b'1' * 500, b'2' * 100000]
        rep_socket.send_multipart([b'3' * 500, b'4' * 100000])

    with run_in_background(run):
        async with azmq.Context(loop=event_loop) as context:
            socket = context.socket(azmq.REQ)
            connect_or_bind(socket, 'tcp://127.0.0.1:3333')
            await asyncio.wait_for(
                socket.send_multipart([b'1' * 500, b'2' * 100000]),
                1,
            )
            frames = await asyncio.wait_for(socket.recv_multipart(), 1)
            assert frames == [b'3' * 500, b'4' * 100000]


@requires_libsodium
@pytest.mark.parametrize("link", [
    'bind',
    'connect',
])
@pytest.mark.asyncio
async def test_tcp_socket_curve_server(
    event_loop,
    socket_factory,
    connect_or_bind,
):
    rep_socket = socket_factory.create(zmq.REP)
    cpublic, csecret = curve_gen_keypair()
    rep_socket.curve_publickey = cpublic
    rep_socket.curve_secretkey = csecret

    public, secret = curve_gen_keypair()