Factored IMC/V Attestation build/process of Component Functional Name
[strongswan.git] / src / libpts / pts / components / pts_comp_func_name.c
1 /*
2 * Copyright (C) 2011 Andreas Steffen
3 *
4 * HSR Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include "pts/components/pts_comp_func_name.h"
18
19 #include <debug.h>
20
21 typedef struct private_pts_comp_func_name_t private_pts_comp_func_name_t;
22
23 /**
24 * Private data of a pts_comp_func_name_t object.
25 *
26 */
27 struct private_pts_comp_func_name_t {
28
29 /**
30 * Public pts_comp_func_name_t interface.
31 */
32 pts_comp_func_name_t public;
33
34 /**
35 * PTS Component Functional Name Vendor ID
36 */
37 u_int32_t vendor_id;
38
39 /**
40 * PTS Component Functional Name
41 */
42 u_int32_t name;
43
44 /**
45 * PTS Component Functional Name Qualifier
46 */
47 u_int8_t qualifier;
48
49 };
50
51 METHOD(pts_comp_func_name_t, get_vendor_id, u_int32_t,
52 private_pts_comp_func_name_t *this)
53 {
54 return this->vendor_id;
55 }
56
57 METHOD(pts_comp_func_name_t, get_name, u_int32_t,
58 private_pts_comp_func_name_t *this)
59 {
60 return this->name;
61 }
62
63 METHOD(pts_comp_func_name_t, get_qualifier, u_int8_t,
64 private_pts_comp_func_name_t *this)
65 {
66 return this->qualifier;
67 }
68
69 static bool equals(private_pts_comp_func_name_t *this,
70 private_pts_comp_func_name_t *other)
71 {
72 if (this->vendor_id != other->vendor_id ||
73 this->name != other->name)
74 {
75 return FALSE;
76 }
77 if (this->qualifier == PTS_QUALIFIER_UNKNOWN ||
78 other->qualifier == PTS_QUALIFIER_UNKNOWN)
79 {
80 return TRUE;
81 }
82 /* TODO handle qualifier wildcards */
83
84 return this->qualifier == other->qualifier;
85 }
86
87 METHOD(pts_comp_func_name_t, clone_, pts_comp_func_name_t*,
88 private_pts_comp_func_name_t *this)
89 {
90 private_pts_comp_func_name_t *clone;
91
92 clone = malloc_thing(private_pts_comp_func_name_t);
93 memcpy(clone, this, sizeof(private_pts_comp_func_name_t));
94
95 return &clone->public;
96 }
97
98 METHOD(pts_comp_func_name_t, destroy, void,
99 private_pts_comp_func_name_t *this)
100 {
101 free(this);
102 }
103
104 /**
105 * See header
106 */
107 pts_comp_func_name_t* pts_comp_func_name_create(u_int32_t vendor_id,
108 u_int32_t name,
109 u_int8_t qualifier)
110 {
111 private_pts_comp_func_name_t *this;
112
113 INIT(this,
114 .public = {
115 .get_vendor_id = _get_vendor_id,
116 .get_name = _get_name,
117 .get_qualifier = _get_qualifier,
118 .equals = (bool(*)(pts_comp_func_name_t*,pts_comp_func_name_t*))equals,
119 .clone = _clone_,
120 .destroy = _destroy,
121 },
122 .vendor_id = vendor_id,
123 .name = name,
124 .qualifier = qualifier,
125 );
126
127 return &this->public;
128 }
129