| 150 | // interface. |
| 151 | |
| 152 | std::size_t CryptoKeyHandler::encrypt( |
| 153 | const CryptoKeyHandler::in_slice_t& in, |
| 154 | const CryptoKeyHandler::out_slice_t& out) const |
| 155 | { |
| 156 | ceph::bufferptr inptr(reinterpret_cast<const char*>(in.buf), in.length); |
| 157 | ceph::bufferlist plaintext; |
| 158 | plaintext.append(std::move(inptr)); |
| 159 | |
| 160 | ceph::bufferlist ciphertext; |
| 161 | std::string error; |
| 162 | const int ret = encrypt(plaintext, ciphertext, &error); |
| 163 | if (ret != 0 || !error.empty()) { |
| 164 | throw std::runtime_error(std::move(error)); |
| 165 | } |
| 166 | |
| 167 | // we need to specify the template parameter explicitly as ::length() |
| 168 | // returns unsigned int, not size_t. |
| 169 | const auto todo_len = \ |
| 170 | std::min<std::size_t>(ciphertext.length(), out.max_length); |
| 171 | memcpy(out.buf, ciphertext.c_str(), todo_len); |
| 172 | |
| 173 | return todo_len; |
| 174 | } |
| 175 | |
| 176 | std::size_t CryptoKeyHandler::decrypt( |
| 177 | const CryptoKeyHandler::in_slice_t& in, |
no test coverage detected