1 #ifndef EVENT_ENCRYPTER_H 2 #define EVENT_ENCRYPTER_H 3 4 #include "my_global.h" 5 #include "my_crypt.h" 6 #include "rpl_constants.h" 7 #include "binlog_event.h" 8 #include "binlog_crypt_data.h" 9 10 bool encrypt_event(uint32 offs, const Binlog_crypt_data &crypto, uchar* buf, uchar *ebuf, size_t buf_len); 11 bool decrypt_event(uint32 offs, const Binlog_crypt_data &crypto, uchar* buf, uchar *ebuf, size_t buf_len); 12 13 class Event_encrypter 14 { 15 public: Event_encrypter()16 Event_encrypter() 17 : event_len(0) 18 , ctx(NULL) 19 , crypto(NULL) 20 {} 21 ~Event_encrypter()22 ~Event_encrypter() 23 { 24 if (ctx != NULL) 25 { 26 my_aes_crypt_free_ctx(ctx); 27 ctx = NULL; 28 } 29 } 30 31 bool init(IO_CACHE *output_cache, uchar* &header, size_t &buf_len); 32 bool encrypt_and_write(IO_CACHE *output_cache, const uchar *pos, size_t len); 33 bool finish(IO_CACHE *output_cache); 34 enable_encryption(Binlog_crypt_data * crypto)35 void enable_encryption(Binlog_crypt_data* crypto) 36 { 37 assert(crypto != NULL); 38 this->crypto = crypto; 39 } 40 is_encryption_enabled()41 bool is_encryption_enabled() const 42 { 43 return crypto != NULL; 44 } 45 46 private: 47 bool maybe_write_event_len(IO_CACHE *output_cache, uchar *pos, size_t len); 48 uint event_len; 49 50 MyEncryptionCTX *ctx; 51 /** 52 Encryption data (key, nonce). Only used if ctx != 0. 53 */ 54 Binlog_crypt_data *crypto; 55 56 Event_encrypter(const Event_encrypter&); 57 Event_encrypter& operator=(const Event_encrypter&); 58 }; 59 60 #endif //EVENT_ENCRYPTER_H 61