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 "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 : 222 : free_rpc_keyring_file_add_key(struct rpc_keyring_file_add_key *opts)
23 : : {
24 [ # # # # ]: 222 : free(opts->name);
25 [ # # # # ]: 222 : free(opts->path);
26 : 222 : }
27 : :
28 : : static void
29 : 222 : rpc_keyring_file_add_key(struct spdk_jsonrpc_request *request,
30 : : const struct spdk_json_val *params)
31 : : {
32 : 222 : struct rpc_keyring_file_add_key opts = {};
33 : : int rc;
34 : :
35 [ - + ]: 222 : 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 [ # # ]: 222 : rc = spdk_keyring_file_add_key(opts.name, opts.path);
44 [ + + ]: 222 : if (rc != 0) {
45 [ # # ]: 12 : spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
46 : 12 : goto out;
47 : : }
48 : :
49 : 210 : spdk_jsonrpc_send_bool_response(request, true);
50 : 222 : out:
51 : 222 : free_rpc_keyring_file_add_key(&opts);
52 : 0 : }
53 : 2319 : 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 : 12 : free_rpc_keyring_file_remove_key(struct rpc_keyring_file_remove_key *r)
65 : : {
66 [ # # # # ]: 12 : free(r->name);
67 : 12 : }
68 : :
69 : : static void
70 : 12 : rpc_keyring_file_remove_key(struct spdk_jsonrpc_request *request,
71 : : const struct spdk_json_val *params)
72 : : {
73 : 12 : struct rpc_keyring_file_remove_key req = {};
74 : : int rc;
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 : 0 : spdk_strerror(EINVAL));
81 : 0 : return;
82 : : }
83 : :
84 : 12 : rc = spdk_keyring_file_remove_key(req.name);
85 [ - + ]: 12 : if (rc != 0) {
86 [ # # ]: 0 : spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
87 : 0 : goto out;
88 : : }
89 : :
90 : 12 : spdk_jsonrpc_send_bool_response(request, true);
91 : 12 : out:
92 : 12 : free_rpc_keyring_file_remove_key(&req);
93 : 0 : }
94 : 2319 : SPDK_RPC_REGISTER("keyring_file_remove_key", rpc_keyring_file_remove_key, SPDK_RPC_RUNTIME)
|