xref: /optee_os/ta/pkcs11/src/serializer.h (revision 850b477246714f90e5eb86e1046ea7bd0a423e79)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2017-2020, Linaro Limited
4  */
5 
6 #ifndef PKCS11_TA_SERIALIZER_H
7 #define PKCS11_TA_SERIALIZER_H
8 
9 #include <stdbool.h>
10 #include <stdint.h>
11 
12 struct pkcs11_client;
13 struct pkcs11_session;
14 
15 /*
16  * Util routines for serializes unformated arguments in a client memref
17  */
18 struct serialargs {
19 	char *start;
20 	char *next;
21 	size_t size;
22 };
23 
24 void serialargs_init(struct serialargs *args, void *in, size_t size);
25 
26 uint32_t serialargs_get(struct serialargs *args, void *out, size_t sz);
27 
28 uint32_t serialargs_get_ptr(struct serialargs *args, void **out, size_t size);
29 
30 uint32_t serialargs_alloc_and_get(struct serialargs *args,
31 				  void **out, size_t size);
32 
33 bool serialargs_remaining_bytes(struct serialargs *args);
34 
35 enum pkcs11_rc serialargs_get_session_from_handle(struct serialargs *args,
36 						  struct pkcs11_client *client,
37 						  struct pkcs11_session **sess);
38 #endif /*PKCS11_TA_SERIALIZER_H*/
39