LCOV - code coverage report
Current view: top level - module/keyring/file - keyring_rpc.c (source / functions) Hit Total Coverage
Test: ut_cov_unit.info Lines: 0 37 0.0 %
Date: 2024-12-16 00:18:56 Functions: 0 6 0.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: BSD-3-Clause
       2             :  * Copyright (c) 2024 Intel Corporation. All rights reserved.
       3             :  */
       4             : 
       5             : #include "spdk/json.h"
       6             : #include "spdk/module/keyring/file.h"
       7             : #include "spdk/rpc.h"
       8             : #include "spdk/string.h"
       9             : #include "spdk/util.h"
      10             : 
      11             : struct rpc_keyring_file_add_key {
      12             :         char *name;
      13             :         char *path;
      14             : };
      15             : 
      16             : static const struct spdk_json_object_decoder rpc_keyring_file_add_key_decoders[] = {
      17             :         {"name", offsetof(struct rpc_keyring_file_add_key, name), spdk_json_decode_string},
      18             :         {"path", offsetof(struct rpc_keyring_file_add_key, path), spdk_json_decode_string},
      19             : };
      20             : 
      21             : static void
      22           0 : free_rpc_keyring_file_add_key(struct rpc_keyring_file_add_key *opts)
      23             : {
      24           0 :         free(opts->name);
      25           0 :         free(opts->path);
      26           0 : }
      27             : 
      28             : static void
      29           0 : rpc_keyring_file_add_key(struct spdk_jsonrpc_request *request,
      30             :                          const struct spdk_json_val *params)
      31             : {
      32           0 :         struct rpc_keyring_file_add_key opts = {};
      33           0 :         int rc;
      34             : 
      35           0 :         if (spdk_json_decode_object_relaxed(params, rpc_keyring_file_add_key_decoders,
      36             :                                             SPDK_COUNTOF(rpc_keyring_file_add_key_decoders),
      37             :                                             &opts)) {
      38           0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
      39           0 :                                                  spdk_strerror(EINVAL));
      40           0 :                 return;
      41             :         }
      42             : 
      43           0 :         rc = spdk_keyring_file_add_key(opts.name, opts.path);
      44           0 :         if (rc != 0) {
      45           0 :                 spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
      46           0 :                 goto out;
      47             :         }
      48             : 
      49           0 :         spdk_jsonrpc_send_bool_response(request, true);
      50             : out:
      51           0 :         free_rpc_keyring_file_add_key(&opts);
      52           0 : }
      53           0 : SPDK_RPC_REGISTER("keyring_file_add_key", rpc_keyring_file_add_key, SPDK_RPC_RUNTIME)
      54             : 
      55             : struct rpc_keyring_file_remove_key {
      56             :         char *name;
      57             : };
      58             : 
      59             : static const struct spdk_json_object_decoder rpc_keyring_file_remove_key_decoders[] = {
      60             :         {"name", offsetof(struct rpc_keyring_file_remove_key, name), spdk_json_decode_string},
      61             : };
      62             : 
      63             : static void
      64           0 : free_rpc_keyring_file_remove_key(struct rpc_keyring_file_remove_key *r)
      65             : {
      66           0 :         free(r->name);
      67           0 : }
      68             : 
      69             : static void
      70           0 : rpc_keyring_file_remove_key(struct spdk_jsonrpc_request *request,
      71             :                             const struct spdk_json_val *params)
      72             : {
      73           0 :         struct rpc_keyring_file_remove_key req = {};
      74           0 :         int rc;
      75             : 
      76           0 :         if (spdk_json_decode_object(params, rpc_keyring_file_remove_key_decoders,
      77             :                                     SPDK_COUNTOF(rpc_keyring_file_remove_key_decoders),
      78             :                                     &req)) {
      79           0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
      80           0 :                                                  spdk_strerror(EINVAL));
      81           0 :                 return;
      82             :         }
      83             : 
      84           0 :         rc = spdk_keyring_file_remove_key(req.name);
      85           0 :         if (rc != 0) {
      86           0 :                 spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
      87           0 :                 goto out;
      88             :         }
      89             : 
      90           0 :         spdk_jsonrpc_send_bool_response(request, true);
      91             : out:
      92           0 :         free_rpc_keyring_file_remove_key(&req);
      93           0 : }
      94           0 : SPDK_RPC_REGISTER("keyring_file_remove_key", rpc_keyring_file_remove_key, SPDK_RPC_RUNTIME)

Generated by: LCOV version 1.15