| 174 | } |
| 175 | |
| 176 | std::size_t CryptoKeyHandler::decrypt( |
| 177 | const CryptoKeyHandler::in_slice_t& in, |
| 178 | const CryptoKeyHandler::out_slice_t& out) const |
| 179 | { |
| 180 | ceph::bufferptr inptr(reinterpret_cast<const char*>(in.buf), in.length); |
| 181 | ceph::bufferlist ciphertext; |
| 182 | ciphertext.append(std::move(inptr)); |
| 183 | |
| 184 | ceph::bufferlist plaintext; |
| 185 | std::string error; |
| 186 | const int ret = decrypt(ciphertext, plaintext, &error); |
| 187 | if (ret != 0 || !error.empty()) { |
| 188 | throw std::runtime_error(std::move(error)); |
| 189 | } |
| 190 | |
| 191 | // we need to specify the template parameter explicitly as ::length() |
| 192 | // returns unsigned int, not size_t. |
| 193 | const auto todo_len = \ |
| 194 | std::min<std::size_t>(plaintext.length(), out.max_length); |
| 195 | memcpy(out.buf, plaintext.c_str(), todo_len); |
| 196 | |
| 197 | return todo_len; |
| 198 | } |
| 199 | |
| 200 | sha256_digest_t CryptoKeyHandler::hmac_sha256( |
| 201 | const ceph::bufferlist& in) const |
no test coverage detected