Merged libpts into libimcv
[strongswan.git] / src / libimcv / swid / swid_error.c
1 /*
2 * Copyright (C) 2011 Sansar Choinyambuu
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_error.h"
17
18 #include <bio/bio_writer.h>
19 #include <ietf/ietf_attr_pa_tnc_error.h>
20
21 ENUM(swid_error_code_names, TCG_SWID_ERROR, TCG_SWID_RESPONSE_TOO_LARGE,
22 "SWID Error",
23 "SWID Subscription Denied",
24 "SWID Response Too Large"
25 );
26
27 /**
28 * Described in header.
29 */
30 pa_tnc_attr_t* swid_error_create(swid_error_code_t code, u_int32_t request_id,
31 u_int32_t max_attr_size, char *description)
32 {
33 bio_writer_t *writer;
34 chunk_t msg_info;
35 pa_tnc_attr_t *attr;
36 pen_type_t error_code;
37
38 error_code = pen_type_create( PEN_TCG, code);
39 writer = bio_writer_create(4);
40 writer->write_uint32(writer, request_id);
41 if (code == TCG_SWID_RESPONSE_TOO_LARGE)
42 {
43 writer->write_uint32(writer, max_attr_size);
44 }
45 if (description)
46 {
47 writer->write_data(writer, chunk_from_str(description));
48 }
49 msg_info = writer->get_buf(writer);
50 attr = ietf_attr_pa_tnc_error_create(error_code, msg_info);
51 writer->destroy(writer);
52
53 return attr;
54 }
55