Merged libpts into libimcv
[strongswan.git] / src / libimcv / swid / swid_tag_id.c
1 /*
2 * Copyright (C) 2013-2014 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "swid_tag_id.h"
17
18 typedef struct private_swid_tag_id_t private_swid_tag_id_t;
19
20 /**
21 * Private data of a swid_tag_id_t object.
22 *
23 */
24 struct private_swid_tag_id_t {
25
26 /**
27 * Public swid_tag_id_t interface.
28 */
29 swid_tag_id_t public;
30
31 /**
32 * Tag Creator
33 */
34 chunk_t tag_creator;
35
36 /**
37 * Unique Software ID
38 */
39 chunk_t unique_sw_id;
40
41 /**
42 * Optional Tag Identifier Instance ID
43 */
44 chunk_t instance_id;
45
46 /**
47 * Reference count
48 */
49 refcount_t ref;
50 };
51
52 METHOD(swid_tag_id_t, get_tag_creator, chunk_t,
53 private_swid_tag_id_t *this)
54 {
55 return this->tag_creator;
56 }
57
58 METHOD(swid_tag_id_t, get_unique_sw_id, chunk_t,
59 private_swid_tag_id_t *this, chunk_t *instance_id)
60 {
61 if (instance_id)
62 {
63 *instance_id = this->instance_id;
64 }
65 return this->unique_sw_id;
66 }
67
68 METHOD(swid_tag_id_t, get_ref, swid_tag_id_t*,
69 private_swid_tag_id_t *this)
70 {
71 ref_get(&this->ref);
72 return &this->public;
73 }
74
75 METHOD(swid_tag_id_t, destroy, void,
76 private_swid_tag_id_t *this)
77 {
78 if (ref_put(&this->ref))
79 {
80 free(this->tag_creator.ptr);
81 free(this->unique_sw_id.ptr);
82 free(this->instance_id.ptr);
83 free(this);
84 }
85 }
86
87 /**
88 * See header
89 */
90 swid_tag_id_t *swid_tag_id_create(chunk_t tag_creator, chunk_t unique_sw_id,
91 chunk_t instance_id)
92 {
93 private_swid_tag_id_t *this;
94
95 INIT(this,
96 .public = {
97 .get_tag_creator = _get_tag_creator,
98 .get_unique_sw_id = _get_unique_sw_id,
99 .get_ref = _get_ref,
100 .destroy = _destroy,
101 },
102 .tag_creator = chunk_clone(tag_creator),
103 .unique_sw_id = chunk_clone(unique_sw_id),
104 .ref = 1,
105 );
106
107 if (instance_id.len > 0)
108 {
109 this->instance_id = chunk_clone(instance_id);
110 }
111
112 return &this->public;
113 }
114