curve_mechanism_base.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #ifndef __ZMQ_CURVE_MECHANISM_BASE_HPP_INCLUDED__
4 #define __ZMQ_CURVE_MECHANISM_BASE_HPP_INCLUDED__
5 
6 #ifdef ZMQ_HAVE_CURVE
7 
8 #if defined(ZMQ_USE_LIBSODIUM)
9 #include "sodium.h"
10 #endif
11 
12 #if crypto_box_NONCEBYTES != 24 || crypto_box_PUBLICKEYBYTES != 32 \
13  || crypto_box_SECRETKEYBYTES != 32 || crypto_box_ZEROBYTES != 32 \
14  || crypto_box_BOXZEROBYTES != 16 || crypto_secretbox_NONCEBYTES != 24 \
15  || crypto_secretbox_ZEROBYTES != 32 || crypto_secretbox_BOXZEROBYTES != 16
16 #error "CURVE library not built properly"
17 #endif
18 
19 #include "mechanism_base.hpp"
20 #include "options.hpp"
21 
22 #include <memory>
23 
24 namespace zmq
25 {
26 class curve_encoding_t
27 {
28  public:
29  curve_encoding_t (const char *encode_nonce_prefix_,
30  const char *decode_nonce_prefix_,
31  const bool downgrade_sub_);
32 
33  int encode (msg_t *msg_);
34  int decode (msg_t *msg_, int *error_event_code_);
35 
36  uint8_t *get_writable_precom_buffer () { return _cn_precom; }
37  const uint8_t *get_precom_buffer () const { return _cn_precom; }
38 
39  typedef uint64_t nonce_t;
40 
41  nonce_t get_and_inc_nonce () { return _cn_nonce++; }
42  void set_peer_nonce (nonce_t peer_nonce_) { _cn_peer_nonce = peer_nonce_; };
43 
44  private:
45  int check_validity (msg_t *msg_, int *error_event_code_);
46 
47  const char *_encode_nonce_prefix;
48  const char *_decode_nonce_prefix;
49 
50  nonce_t _cn_nonce;
51  nonce_t _cn_peer_nonce;
52 
53  // Intermediary buffer used to speed up boxing and unboxing.
54  uint8_t _cn_precom[crypto_box_BEFORENMBYTES];
55 
56  const bool _downgrade_sub;
57 
58  ZMQ_NON_COPYABLE_NOR_MOVABLE (curve_encoding_t)
59 };
60 
61 class curve_mechanism_base_t : public virtual mechanism_base_t,
62  public curve_encoding_t
63 {
64  public:
65  curve_mechanism_base_t (session_base_t *session_,
66  const options_t &options_,
67  const char *encode_nonce_prefix_,
68  const char *decode_nonce_prefix_,
69  const bool downgrade_sub_);
70 
71  // mechanism implementation
72  int encode (msg_t *msg_) ZMQ_OVERRIDE;
73  int decode (msg_t *msg_) ZMQ_OVERRIDE;
74 };
75 }
76 
77 #endif
78 
79 #endif
zmq
Definition: zmq.hpp:229
ZMQ_OVERRIDE
#define ZMQ_OVERRIDE
Definition: zmq.hpp:91
ZMQ_NON_COPYABLE_NOR_MOVABLE
#define ZMQ_NON_COPYABLE_NOR_MOVABLE(classname)
Definition: macros.hpp:58
options.hpp
mechanism_base.hpp
options_
DebugStringOptions options_
Definition: src/google/protobuf/descriptor.cc:2410


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:49