IBR-DTN  1.0.0
KeyExchangeData.cpp
Go to the documentation of this file.
1 /*
2  * KeyExchangeData.cpp
3  *
4  * Copyright (C) 2014 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  * Thomas Schrader <schrader.thomas@gmail.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22 
25 
26 namespace dtn
27 {
28  namespace security
29  {
31  : _session_id(-1), _action(ERROR), _protocol(-1), _step(-1)
32  {}
33 
35  : _session_id(session.getUniqueId()), _action(action), _protocol(session.getProtocol()), _step(0)
36  {}
37 
38  KeyExchangeData::KeyExchangeData(const Action action, const int protocol)
39  : _session_id(-1), _action(action), _protocol(protocol), _step(0)
40  {
41  }
42 
44  {}
45 
47  : _session_id(obj._session_id), _action(obj._action), _protocol(obj._protocol), _step(obj._step)
48  {
49  str(obj.str());
50  }
51 
52  std::string KeyExchangeData::toString() const
53  {
54  std::stringstream sstm;
55 
56  switch (_protocol)
57  {
58  case 0:
59  sstm << "none";
60  break;
61  case 1:
62  sstm << "dh";
63  break;
64  case 2:
65  sstm << "jpake";
66  break;
67  case 3:
68  sstm << "hash";
69  break;
70  case 4:
71  sstm << "password";
72  break;
73  case 5:
74  sstm << "qr";
75  break;
76  case 6:
77  sstm << "nfc";
78  break;
79  }
80 
81  sstm << "::" << _session_id;
82  return sstm.str();
83  }
84 
86  {
87  return _action;
88  }
89 
91  {
92  _action = action;
93  }
94 
96  {
97  return _protocol;
98  }
99 
100  void KeyExchangeData::setProtocol(int protocol)
101  {
102  _protocol = protocol;
103  }
104 
106  {
107  _session_id = session.getUniqueId();
108  }
109 
110  void KeyExchangeData::setSessionId(unsigned int sessionId)
111  {
112  _session_id = sessionId;
113  }
114 
115  unsigned int KeyExchangeData::getSessionId() const
116  {
117  return _session_id;
118  }
119 
121  {
122  return _step;
123  }
124 
126  {
127  _step = step;
128  }
129 
131  {
132  _session_id = obj._session_id;
133  _action = obj._action;
134  _protocol = obj._protocol;
135  _step = obj._step;
136  str(obj.str());
137  return *this;
138  }
139 
140  std::ostream &operator<<(std::ostream &stream, const KeyExchangeData &obj)
141  {
142  stream << dtn::data::Number(obj._session_id);
143 
144  stream << (char)obj._action;
145 
146  stream << dtn::data::Number(obj._protocol);
147  stream << dtn::data::Number(obj._step);
148 
149  stream << dtn::data::BundleString(obj.str());
150 
151  return stream;
152  }
153 
154  std::istream &operator>>(std::istream &stream, KeyExchangeData &obj)
155  {
156  char action = 0;
158  dtn::data::Number sdnv;
159 
160  stream >> sdnv;
161  obj._session_id = sdnv.get<unsigned int>();
162 
163  stream >> action;
164  obj._action = KeyExchangeData::Action(action);
165 
166  stream >> sdnv;
167  obj._protocol = sdnv.get<int>();
168 
169  stream >> sdnv;
170  obj._step = sdnv.get<int>();
171 
172  stream >> bs;
173  obj.str(bs);
174 
175  return stream;
176  }
177  } /* namespace security */
178 } /* namespace dtn */
unsigned int getSessionId() const
void setSession(const KeyExchangeSession &session)
void setSessionId(unsigned int sessionId)
std::ostream & operator<<(std::ostream &stream, const SecurityBlock::TLVList &tlvlist)
std::istream & operator>>(std::istream &stream, SecurityBlock::TLVList &tlvlist)
dtn::data::SDNV< Size > Number
Definition: Number.h:38
KeyExchangeData & operator=(const KeyExchangeData &)