LCOV - code coverage report
Current view: top level - spdk/module/keyring/file - keyring_rpc.c (source / functions) Hit Total Coverage
Test: Combined Lines: 30 34 88.2 %
Date: 2024-07-14 22:57:34 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 6 66.7 %

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

Generated by: LCOV version 1.14