/src/strongswan/src/libstrongswan/credentials/keys/shared_key.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2007 Martin Willi |
3 | | * |
4 | | * Copyright (C) secunet Security Networks AG |
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 "shared_key.h" |
18 | | |
19 | | ENUM(shared_key_type_names, SHARED_ANY, SHARED_PPK, |
20 | | "ANY", |
21 | | "IKE", |
22 | | "EAP", |
23 | | "PRIVATE_KEY_PASS", |
24 | | "PIN", |
25 | | "NTLM", |
26 | | "PPK", |
27 | | ); |
28 | | |
29 | | typedef struct private_shared_key_t private_shared_key_t; |
30 | | |
31 | | /** |
32 | | * private data of shared_key |
33 | | */ |
34 | | struct private_shared_key_t { |
35 | | |
36 | | /** |
37 | | * public functions |
38 | | */ |
39 | | shared_key_t public; |
40 | | |
41 | | /** |
42 | | * type of this shared key |
43 | | */ |
44 | | shared_key_type_t type; |
45 | | |
46 | | /** |
47 | | * associated shared key data |
48 | | */ |
49 | | chunk_t key; |
50 | | |
51 | | /** |
52 | | * reference counter |
53 | | */ |
54 | | refcount_t ref; |
55 | | }; |
56 | | |
57 | | METHOD(shared_key_t, get_type, shared_key_type_t, |
58 | | private_shared_key_t *this) |
59 | 0 | { |
60 | 0 | return this->type; |
61 | 0 | } |
62 | | |
63 | | METHOD(shared_key_t, get_key, chunk_t, |
64 | | private_shared_key_t *this) |
65 | 0 | { |
66 | 0 | return this->key; |
67 | 0 | } |
68 | | |
69 | | METHOD(shared_key_t, get_ref, shared_key_t*, |
70 | | private_shared_key_t *this) |
71 | 0 | { |
72 | 0 | ref_get(&this->ref); |
73 | 0 | return &this->public; |
74 | 0 | } |
75 | | |
76 | | METHOD(shared_key_t, destroy, void, |
77 | | private_shared_key_t *this) |
78 | 0 | { |
79 | 0 | if (ref_put(&this->ref)) |
80 | 0 | { |
81 | 0 | chunk_clear(&this->key); |
82 | 0 | free(this); |
83 | 0 | } |
84 | 0 | } |
85 | | |
86 | | /* |
87 | | * see header file |
88 | | */ |
89 | | shared_key_t *shared_key_create(shared_key_type_t type, chunk_t key) |
90 | 0 | { |
91 | 0 | private_shared_key_t *this; |
92 | |
|
93 | 0 | INIT(this, |
94 | 0 | .public = { |
95 | 0 | .get_type = _get_type, |
96 | 0 | .get_key = _get_key, |
97 | 0 | .get_ref = _get_ref, |
98 | 0 | .destroy = _destroy, |
99 | 0 | }, |
100 | 0 | .type = type, |
101 | 0 | .key = key, |
102 | 0 | .ref = 1, |
103 | 0 | ); |
104 | |
|
105 | 0 | return &this->public; |
106 | 0 | } |
107 | | |