summaryrefslogtreecommitdiff
path: root/ta/pkcs11/src/sanitize_object.h
blob: 6b170a20cefdd1515c79e42043bfbad953e05271 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* SPDX-License-Identifier: BSD-2-Clause */
/*
 * Copyright (c) 2017-2020, Linaro Limited
 */

#ifndef PKCS11_TA_SANITIZE_OBJECT_H
#define PKCS11_TA_SANITIZE_OBJECT_H

#include "serializer.h"

/*
 * sanitize_consistent_class_and_type - Check object type matches object class
 *
 * @attrs - object attributes
 * Return true if class/type matches, else return false
 */
bool sanitize_consistent_class_and_type(struct obj_attrs *attrs);

/**
 * sanitize_client_object - Setup a serializer from a serialized object
 *
 * @dst - output structure tracking the generated serial object
 * @head - pointer to the formatted serialized object (its head)
 * @size - byte size of the serialized binary blob
 * @class_hint - Hint for class to be added to template if not presnet
 *               in serialized object.
 * @type_hint - Hint for type to be added to template if not presnet
 *               in serialized object.
 *
 * This function copies an attribute list from a client API attribute head
 * into a PKCS11 TA internal attribute structure. It generates a serialized
 * attribute list with a consistent format and identified attribute IDs.
 *
 * @head points to a blob starting with a pkcs11 attribute header.
 * @head may point to an unaligned address.
 * This function allocates, fills and returns a serialized attribute list
 * into a serializer container.
 */
enum pkcs11_rc sanitize_client_object(struct obj_attrs **dst, void *head,
				      size_t size, uint32_t class_hint,
				      uint32_t type_hint);

/* Debug: dump attribute content as debug traces */
void trace_attributes_from_api_head(const char *prefix, void *ref, size_t size);

#endif /*PKCS11_TA_SANITIZE_OBJECT_H*/