modulewrapper.h
Go to the documentation of this file.
1 /* Copyright (c) 2021, Google Inc.
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #include <openssl/base.h>
16 
17 #include <functional>
18 #include <memory>
19 #include <vector>
20 
21 #include <openssl/span.h>
22 
23 
24 namespace bssl {
25 namespace acvp {
26 
27 // kMaxArgs is the maximum number of arguments (including the function name)
28 // that an ACVP request can contain.
29 constexpr size_t kMaxArgs = 8;
30 // kMaxNameLength is the maximum length of a function name in an ACVP request.
31 constexpr size_t kMaxNameLength = 30;
32 
33 // RequestBuffer holds various buffers needed for parsing an ACVP request. It
34 // can be reused between requests.
36  public:
37  virtual ~RequestBuffer();
38 
39  static std::unique_ptr<RequestBuffer> New();
40 };
41 
42 // ParseArgsFromFd returns a span of arguments, the first of which is the name
43 // of the requested function, from |fd|. The return values point into |buffer|
44 // and so must not be used after |buffer| has been freed or reused for a
45 // subsequent call. It returns an empty span on error, because std::optional
46 // is still too new.
48 
49 // WriteReplyToFd writes a reply to the given file descriptor.
50 bool WriteReplyToFd(int fd, const std::vector<Span<const uint8_t>> &spans);
51 
52 // ReplyCallback is the type of a callback that writes a reply to an ACVP
53 // request.
54 typedef std::function<bool(const std::vector<Span<const uint8_t>> &)>
56 
57 // Handler is the type of a function that handles a specific ACVP request. If
58 // successful it will call |write_reply| with the response arguments and return
59 // |write_reply|'s return value. Otherwise it will return false. The given args
60 // must not include the name at the beginning.
61 typedef bool (*Handler)(const Span<const uint8_t> args[],
62  ReplyCallback write_reply);
63 
64 // FindHandler returns a |Handler| that can process the given arguments, or logs
65 // a reason and returns |nullptr| if none is found.
67 
68 } // namespace acvp
69 } // namespace bssl
bssl::acvp::RequestBuffer::~RequestBuffer
virtual ~RequestBuffer()
bool
bool
Definition: setup_once.h:312
bssl
Definition: hpke_test.cc:37
base.h
bssl::acvp::kMaxNameLength
constexpr size_t kMaxNameLength
Definition: modulewrapper.h:31
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
bssl::acvp::RequestBuffer::New
static std::unique_ptr< RequestBuffer > New()
Definition: modulewrapper.cc:75
buffer
char buffer[1024]
Definition: libuv/docs/code/idle-compute/main.c:8
Span
Definition: boringssl-with-bazel/src/include/openssl/span.h:32
bssl::acvp::Handler
bool(* Handler)(const Span< const uint8_t > args[], ReplyCallback write_reply)
Definition: modulewrapper.h:61
bssl::acvp::ReplyCallback
std::function< bool(const std::vector< Span< const uint8_t >> &)> ReplyCallback
Definition: modulewrapper.h:55
bssl::acvp::WriteReplyToFd
bool WriteReplyToFd(int fd, const std::vector< Span< const uint8_t >> &spans)
Definition: modulewrapper.cc:166
bssl::acvp::kMaxArgs
constexpr size_t kMaxArgs
Definition: modulewrapper.h:29
bssl::acvp::RequestBuffer
Definition: modulewrapper.h:35
bssl::acvp::ParseArgsFromFd
Span< const Span< const uint8_t > > ParseArgsFromFd(int fd, RequestBuffer *in_buffer)
Definition: modulewrapper.cc:99
span.h
bssl::acvp::FindHandler
Handler FindHandler(Span< const Span< const uint8_t >> args)
Definition: modulewrapper.cc:1333
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:41