- result = EVP_EncryptUpdate(c->outctx, outbuf, &outlen, buffer, length);
- if(!result || outlen != length) {
- logger(LOG_ERR, _("Error while encrypting metadata to %s (%s): %s"),
- c->name, c->hostname, ERR_error_string(ERR_get_error(), NULL));
- return false;
- }
- bufp = outbuf;
- length = outlen;
- } else
- bufp = buffer;
-
- while(length) {
- result = send(c->socket, bufp, length, 0);
- if(result <= 0) {
- if(!errno || errno == EPIPE) {
- ifdebug(CONNECTIONS) logger(LOG_NOTICE, _("Connection closed by %s (%s)"),
- c->name, c->hostname);
- } else if(errno == EINTR)
- continue;
- else
- logger(LOG_ERR, _("Sending meta data to %s (%s) failed: %s"), c->name,
- c->hostname, strerror(errno));
+ size_t outlen = length;
+
+ if(!cipher_encrypt(&c->outcipher, buffer, length, buffer_prepare(&c->outbuf, length), &outlen, false) || outlen != length) {
+ logger(LOG_ERR, "Error while encrypting metadata to %s (%s)",
+ c->name, c->hostname);