OLD | NEW |
(Empty) | |
| 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC) |
| 4 * |
| 5 * This program is free software; you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 2 as |
| 7 * published by the Free Software Foundation; |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software |
| 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 * |
| 18 * Author: Lluis Parcerisa <lparcerisa@cttc.cat> |
| 19 */ |
| 20 |
| 21 #ifndef NIST_ASN1_HEADER_H |
| 22 #define NIST_ASN1_HEADER_H |
| 23 |
| 24 #include "ns3/header.h" |
| 25 |
| 26 #include <bitset> |
| 27 #include <string> |
| 28 |
| 29 namespace ns3 { |
| 30 |
| 31 /** |
| 32 * This class has the purpose to encode Information Elements according |
| 33 * to ASN.1 syntax, as defined in ITU-T X-691. |
| 34 * IMPORTANT: The encoding is done following the UNALIGNED variant. |
| 35 */ |
| 36 class NistAsn1Header : public Header |
| 37 { |
| 38 public: |
| 39 NistAsn1Header (); |
| 40 virtual ~NistAsn1Header (); |
| 41 |
| 42 /** |
| 43 * \brief Get the type ID. |
| 44 * \return the object TypeId |
| 45 */ |
| 46 static TypeId GetTypeId (void); |
| 47 virtual TypeId GetInstanceTypeId (void) const; |
| 48 uint32_t GetSerializedSize (void) const; |
| 49 void Serialize (Buffer::Iterator bIterator) const; |
| 50 |
| 51 // Inherited from ns3::Header base class |
| 52 // Pure virtual methods, to be implemented in child classes |
| 53 virtual uint32_t Deserialize (Buffer::Iterator bIterator) = 0; |
| 54 virtual void Print (std::ostream &os) const = 0; |
| 55 ···· |
| 56 /** |
| 57 * This function serializes class attributes to m_serializationResult |
| 58 * local Buffer. As ASN1 encoding produces a bitstream that does not have |
| 59 * a fixed length, this function is needed to store the result, so |
| 60 * its length can be retrieved with Header::GetSerializedSize() function. |
| 61 * This method is pure virtual in this class (needs to be implemented |
| 62 * in child classes) as the meaningful information elements are in |
| 63 * the subclasses. |
| 64 */ |
| 65 virtual void PreSerialize (void) const = 0; |
| 66 |
| 67 protected: |
| 68 mutable uint8_t m_serializationPendingBits; //!< pending bits |
| 69 mutable uint8_t m_numSerializationPendingBits; //!< number of pending bits |
| 70 mutable bool m_isDataSerialized; //!< true if data is serialized |
| 71 mutable Buffer m_serializationResult; //!< serialization result |
| 72 |
| 73 /** |
| 74 * Function to write in m_serializationResult, after resizing its size |
| 75 * \param octet bits to write |
| 76 */ |
| 77 void WriteOctet (uint8_t octet) const; |
| 78 |
| 79 // Serialization functions |
| 80 |
| 81 /** |
| 82 * Serialize a bool |
| 83 * \param value value to serialize |
| 84 */ |
| 85 void SerializeBoolean (bool value) const; |
| 86 /** |
| 87 * Serialize an Integer |
| 88 * \param n value to serialize |
| 89 * \param nmin min value to serialize |
| 90 * \param nmax max value to serialize |
| 91 */ |
| 92 void SerializeInteger (int n, int nmin, int nmax) const; |
| 93 // void SerializeOctetstring (std::string s) const; |
| 94 /** |
| 95 * Serialize a Sequence |
| 96 * \param numElems element number to serialize |
| 97 * \param nMax max value to serialize |
| 98 * \param nMin min value to serialize |
| 99 */ |
| 100 void SerializeSequenceOf (int numElems, int nMax, int nMin) const; |
| 101 /** |
| 102 * Serialize a Choice (set of options) |
| 103 * \param numOptions number of options |
| 104 * \param selectedOption selected option |
| 105 * \param isExtensionMarkerPresent true if extension mark is present |
| 106 */ |
| 107 void SerializeChoice (int numOptions, int selectedOption, |
| 108 bool isExtensionMarkerPresent) const; |
| 109 /** |
| 110 * Serialize an Enum |
| 111 * \param numElems number of elements in the enum |
| 112 * \param selectedElem selected element |
| 113 */ |
| 114 void SerializeEnum (int numElems, int selectedElem) const; |
| 115 /** |
| 116 * Serialize nothing (null op) |
| 117 */ |
| 118 void SerializeNull () const; |
| 119 /** |
| 120 * Finalizes an in progress serialization. |
| 121 */ |
| 122 void FinalizeSerialization () const; |
| 123 |
| 124 /** |
| 125 * Serialize a bitset |
| 126 * \param data data to serialize |
| 127 */ |
| 128 template <int N> |
| 129 void SerializeBitset (std::bitset<N> data) const; |
| 130 |
| 131 /** |
| 132 * Serialize a sequence |
| 133 * \param optionalOrDefaultMask Mask to serialize |
| 134 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 135 */ |
| 136 template <int N> |
| 137 void SerializeSequence (std::bitset<N> optionalOrDefaultMask, |
| 138 bool isExtensionMarkerPresent) const; |
| 139 /** |
| 140 * Serialize a sequence |
| 141 * \param optionalOrDefaultMask Mask to serialize |
| 142 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 143 */ |
| 144 void SerializeSequence (std::bitset<0> optionalOrDefaultMask, |
| 145 bool isExtensionMarkerPresent) const; |
| 146 /** |
| 147 * Serialize a sequence |
| 148 * \param optionalOrDefaultMask Mask to serialize |
| 149 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 150 */ |
| 151 void SerializeSequence (std::bitset<1> optionalOrDefaultMask, |
| 152 bool isExtensionMarkerPresent) const; |
| 153 /** |
| 154 * Serialize a sequence |
| 155 * \param optionalOrDefaultMask Mask to serialize |
| 156 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 157 */ |
| 158 void SerializeSequence (std::bitset<2> optionalOrDefaultMask, |
| 159 bool isExtensionMarkerPresent) const; |
| 160 /** |
| 161 * Serialize a sequence |
| 162 * \param optionalOrDefaultMask Mask to serialize |
| 163 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 164 */ |
| 165 void SerializeSequence (std::bitset<3> optionalOrDefaultMask, |
| 166 bool isExtensionMarkerPresent) const; |
| 167 /** |
| 168 * Serialize a sequence |
| 169 * \param optionalOrDefaultMask Mask to serialize |
| 170 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 171 */ |
| 172 void SerializeSequence (std::bitset<4> optionalOrDefaultMask, |
| 173 bool isExtensionMarkerPresent) const; |
| 174 /** |
| 175 * Serialize a sequence |
| 176 * \param optionalOrDefaultMask Mask to serialize |
| 177 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 178 */ |
| 179 void SerializeSequence (std::bitset<5> optionalOrDefaultMask, |
| 180 bool isExtensionMarkerPresent) const; |
| 181 /** |
| 182 * Serialize a sequence |
| 183 * \param optionalOrDefaultMask Mask to serialize |
| 184 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 185 */ |
| 186 void SerializeSequence (std::bitset<6> optionalOrDefaultMask, |
| 187 bool isExtensionMarkerPresent) const; |
| 188 /** |
| 189 * Serialize a sequence |
| 190 * \param optionalOrDefaultMask Mask to serialize |
| 191 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 192 */ |
| 193 void SerializeSequence (std::bitset<9> optionalOrDefaultMask, |
| 194 bool isExtensionMarkerPresent) const; |
| 195 /** |
| 196 * Serialize a sequence |
| 197 * \param optionalOrDefaultMask Mask to serialize |
| 198 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 199 */ |
| 200 void SerializeSequence (std::bitset<10> optionalOrDefaultMask, |
| 201 bool isExtensionMarkerPresent) const; |
| 202 /** |
| 203 * Serialize a sequence |
| 204 * \param optionalOrDefaultMask Mask to serialize |
| 205 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 206 */ |
| 207 void SerializeSequence (std::bitset<11> optionalOrDefaultMask, |
| 208 bool isExtensionMarkerPresent) const; |
| 209 |
| 210 /** |
| 211 * Serialize a bitstring |
| 212 * \param bitstring bitstring to serialize |
| 213 */ |
| 214 template <int N> |
| 215 void SerializeBitstring (std::bitset<N> bitstring) const; |
| 216 /** |
| 217 * Serialize a bitstring |
| 218 * \param bitstring bitstring to serialize |
| 219 */ |
| 220 void SerializeBitstring (std::bitset<1> bitstring) const; |
| 221 /** |
| 222 * Serialize a bitstring |
| 223 * \param bitstring bitstring to serialize |
| 224 */ |
| 225 void SerializeBitstring (std::bitset<2> bitstring) const; |
| 226 /** |
| 227 * Serialize a bitstring |
| 228 * \param bitstring bitstring to serialize |
| 229 */ |
| 230 void SerializeBitstring (std::bitset<8> bitstring) const; |
| 231 /** |
| 232 * Serialize a bitstring |
| 233 * \param bitstring bitstring to serialize |
| 234 */ |
| 235 void SerializeBitstring (std::bitset<10> bitstring) const; |
| 236 /** |
| 237 * Serialize a bitstring |
| 238 * \param bitstring bitstring to serialize |
| 239 */ |
| 240 void SerializeBitstring (std::bitset<16> bitstring) const; |
| 241 /** |
| 242 * Serialize a bitstring |
| 243 * \param bitstring bitstring to serialize |
| 244 */ |
| 245 void SerializeBitstring (std::bitset<27> bitstring) const; |
| 246 /** |
| 247 * Serialize a bitstring |
| 248 * \param bitstring bitstring to serialize |
| 249 */ |
| 250 void SerializeBitstring (std::bitset<28> bitstring) const; |
| 251 /** |
| 252 * Serialize a bitstring |
| 253 * \param bitstring bitstring to serialize |
| 254 */ |
| 255 void SerializeBitstring (std::bitset<32> bitstring) const; |
| 256 |
| 257 // Deserialization functions |
| 258 |
| 259 /** |
| 260 * Deserialize a bitset |
| 261 * \param data buffer to store the result |
| 262 * \param bIterator buffer iterator |
| 263 * \returns the modified buffer iterator |
| 264 */ |
| 265 template <int N> |
| 266 Buffer::Iterator DeserializeBitset (std::bitset<N> *data, |
| 267 Buffer::Iterator bIterator); |
| 268 /** |
| 269 * Deserialize a bitset |
| 270 * \param data buffer to store the result |
| 271 * \param bIterator buffer iterator |
| 272 * \returns the modified buffer iterator |
| 273 */ |
| 274 Buffer::Iterator DeserializeBitset (std::bitset<8> *data, |
| 275 Buffer::Iterator bIterator); |
| 276 |
| 277 /** |
| 278 * Deserialize a boolean |
| 279 * \param value buffer to store the result |
| 280 * \param bIterator buffer iterator |
| 281 * \returns the modified buffer iterator |
| 282 */ |
| 283 Buffer::Iterator DeserializeBoolean (bool *value, |
| 284 Buffer::Iterator bIterator); |
| 285 /** |
| 286 * Deserialize an integer |
| 287 * \param n buffer to store the result |
| 288 * \param nmin min value to serialize |
| 289 * \param nmax max value to serialize |
| 290 * \param bIterator buffer iterator |
| 291 * \returns the modified buffer iterator |
| 292 */ |
| 293 Buffer::Iterator DeserializeInteger (int *n, int nmin, int nmax, |
| 294 Buffer::Iterator bIterator); |
| 295 /** |
| 296 * Deserialize a Choice (set of options) |
| 297 * \param numOptions number of options |
| 298 * \param isExtensionMarkerPresent true if extension mark is present |
| 299 * \param selectedOption buffer to store the result |
| 300 * \param bIterator buffer iterator |
| 301 * \returns the modified buffer iterator |
| 302 */ |
| 303 Buffer::Iterator DeserializeChoice (int numOptions, |
| 304 bool isExtensionMarkerPresent, |
| 305 int *selectedOption, |
| 306 Buffer::Iterator bIterator); |
| 307 /** |
| 308 * Deserialize an Enum |
| 309 * \param numElems number of elements in the enum |
| 310 * \param selectedElem buffer to store the result |
| 311 * \param bIterator buffer iterator |
| 312 * \returns the modified buffer iterator |
| 313 */ |
| 314 Buffer::Iterator DeserializeEnum (int numElems, int *selectedElem, |
| 315 Buffer::Iterator bIterator); |
| 316 |
| 317 /** |
| 318 * Deserialize a sequence |
| 319 * \param optionalOrDefaultMask buffer to store the result |
| 320 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 321 * \param bIterator buffer iterator |
| 322 * \returns the modified buffer iterator |
| 323 */ |
| 324 template <int N> |
| 325 /** |
| 326 * Deserialize a sequence |
| 327 * \param optionalOrDefaultMask buffer to store the result |
| 328 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 329 * \param bIterator buffer iterator |
| 330 * \returns the modified buffer iterator |
| 331 */ |
| 332 Buffer::Iterator DeserializeSequence (std::bitset<N> *optionalOrDefaultMask, |
| 333 bool isExtensionMarkerPresent, |
| 334 Buffer::Iterator bIterator); |
| 335 /** |
| 336 * Deserialize a sequence |
| 337 * \param optionalOrDefaultMask buffer to store the result |
| 338 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 339 * \param bIterator buffer iterator |
| 340 * \returns the modified buffer iterator |
| 341 */ |
| 342 Buffer::Iterator DeserializeSequence (std::bitset<0> *optionalOrDefaultMask, |
| 343 bool isExtensionMarkerPresent, |
| 344 Buffer::Iterator bIterator); |
| 345 /** |
| 346 * Deserialize a sequence |
| 347 * \param optionalOrDefaultMask buffer to store the result |
| 348 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 349 * \param bIterator buffer iterator |
| 350 * \returns the modified buffer iterator |
| 351 */ |
| 352 Buffer::Iterator DeserializeSequence (std::bitset<1> *optionalOrDefaultMask, |
| 353 bool isExtensionMarkerPresent, |
| 354 Buffer::Iterator bIterator); |
| 355 /** |
| 356 * Deserialize a sequence |
| 357 * \param optionalOrDefaultMask buffer to store the result |
| 358 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 359 * \param bIterator buffer iterator |
| 360 * \returns the modified buffer iterator |
| 361 */ |
| 362 Buffer::Iterator DeserializeSequence (std::bitset<2> *optionalOrDefaultMask, |
| 363 bool isExtensionMarkerPresent, |
| 364 Buffer::Iterator bIterator); |
| 365 /** |
| 366 * Deserialize a sequence |
| 367 * \param optionalOrDefaultMask buffer to store the result |
| 368 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 369 * \param bIterator buffer iterator |
| 370 * \returns the modified buffer iterator |
| 371 */ |
| 372 Buffer::Iterator DeserializeSequence (std::bitset<3> *optionalOrDefaultMask, |
| 373 bool isExtensionMarkerPresent, |
| 374 Buffer::Iterator bIterator); |
| 375 /** |
| 376 * Deserialize a sequence |
| 377 * \param optionalOrDefaultMask buffer to store the result |
| 378 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 379 * \param bIterator buffer iterator |
| 380 * \returns the modified buffer iterator |
| 381 */ |
| 382 Buffer::Iterator DeserializeSequence (std::bitset<4> *optionalOrDefaultMask, |
| 383 bool isExtensionMarkerPresent, |
| 384 Buffer::Iterator bIterator); |
| 385 /** |
| 386 * Deserialize a sequence |
| 387 * \param optionalOrDefaultMask buffer to store the result |
| 388 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 389 * \param bIterator buffer iterator |
| 390 * \returns the modified buffer iterator |
| 391 */ |
| 392 Buffer::Iterator DeserializeSequence (std::bitset<5> *optionalOrDefaultMask, |
| 393 bool isExtensionMarkerPresent, |
| 394 Buffer::Iterator bIterator); |
| 395 /** |
| 396 * Deserialize a sequence |
| 397 * \param optionalOrDefaultMask buffer to store the result |
| 398 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 399 * \param bIterator buffer iterator |
| 400 * \returns the modified buffer iterator |
| 401 */ |
| 402 Buffer::Iterator DeserializeSequence (std::bitset<6> *optionalOrDefaultMask, |
| 403 bool isExtensionMarkerPresent, |
| 404 Buffer::Iterator bIterator); |
| 405 /** |
| 406 * Deserialize a sequence |
| 407 * \param optionalOrDefaultMask buffer to store the result |
| 408 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 409 * \param bIterator buffer iterator |
| 410 * \returns the modified buffer iterator |
| 411 */ |
| 412 Buffer::Iterator DeserializeSequence (std::bitset<9> *optionalOrDefaultMask, |
| 413 bool isExtensionMarkerPresent, |
| 414 Buffer::Iterator bIterator); |
| 415 /** |
| 416 * Deserialize a sequence |
| 417 * \param optionalOrDefaultMask buffer to store the result |
| 418 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 419 * \param bIterator buffer iterator |
| 420 * \returns the modified buffer iterator |
| 421 */ |
| 422 Buffer::Iterator DeserializeSequence (std::bitset<10> *optionalOrDefaultMask, |
| 423 bool isExtensionMarkerPresent, |
| 424 Buffer::Iterator bIterator); |
| 425 /** |
| 426 * Deserialize a sequence |
| 427 * \param optionalOrDefaultMask buffer to store the result |
| 428 * \param isExtensionMarkerPresent true if Extension Marker is present |
| 429 * \param bIterator buffer iterator |
| 430 * \returns the modified buffer iterator |
| 431 */ |
| 432 Buffer::Iterator DeserializeSequence (std::bitset<11> *optionalOrDefaultMask, |
| 433 bool isExtensionMarkerPresent, |
| 434 Buffer::Iterator bIterator); |
| 435 |
| 436 /** |
| 437 * Deserialize a bitstring |
| 438 * \param bitstring buffer to store the result |
| 439 * \param bIterator buffer iterator |
| 440 * \returns the modified buffer iterator |
| 441 */ |
| 442 template <int N> |
| 443 Buffer::Iterator DeserializeBitstring (std::bitset<N> *bitstring, |
| 444 Buffer::Iterator bIterator); |
| 445 /** |
| 446 * Deserialize a bitstring |
| 447 * \param bitstring buffer to store the result |
| 448 * \param bIterator buffer iterator |
| 449 * \returns the modified buffer iterator |
| 450 */ |
| 451 Buffer::Iterator DeserializeBitstring (std::bitset<1> *bitstring, |
| 452 Buffer::Iterator bIterator); |
| 453 /** |
| 454 * Deserialize a bitstring |
| 455 * \param bitstring buffer to store the result |
| 456 * \param bIterator buffer iterator |
| 457 * \returns the modified buffer iterator |
| 458 */ |
| 459 Buffer::Iterator DeserializeBitstring (std::bitset<2> *bitstring, |
| 460 Buffer::Iterator bIterator); |
| 461 /** |
| 462 * Deserialize a bitstring |
| 463 * \param bitstring buffer to store the result |
| 464 * \param bIterator buffer iterator |
| 465 * \returns the modified buffer iterator |
| 466 */ |
| 467 Buffer::Iterator DeserializeBitstring (std::bitset<8> *bitstring, |
| 468 Buffer::Iterator bIterator); |
| 469 /** |
| 470 * Deserialize a bitstring |
| 471 * \param bitstring buffer to store the result |
| 472 * \param bIterator buffer iterator |
| 473 * \returns the modified buffer iterator |
| 474 */ |
| 475 Buffer::Iterator DeserializeBitstring (std::bitset<10> *bitstring, |
| 476 Buffer::Iterator bIterator); |
| 477 /** |
| 478 * Deserialize a bitstring |
| 479 * \param bitstring buffer to store the result |
| 480 * \param bIterator buffer iterator |
| 481 * \returns the modified buffer iterator |
| 482 */ |
| 483 Buffer::Iterator DeserializeBitstring (std::bitset<16> *bitstring, |
| 484 Buffer::Iterator bIterator); |
| 485 /** |
| 486 * Deserialize a bitstring |
| 487 * \param bitstring buffer to store the result |
| 488 * \param bIterator buffer iterator |
| 489 * \returns the modified buffer iterator |
| 490 */ |
| 491 Buffer::Iterator DeserializeBitstring (std::bitset<27> *bitstring, |
| 492 Buffer::Iterator bIterator); |
| 493 /** |
| 494 * Deserialize a bitstring |
| 495 * \param bitstring buffer to store the result |
| 496 * \param bIterator buffer iterator |
| 497 * \returns the modified buffer iterator |
| 498 */ |
| 499 Buffer::Iterator DeserializeBitstring (std::bitset<28> *bitstring, |
| 500 Buffer::Iterator bIterator); |
| 501 /** |
| 502 * Deserialize a bitstring |
| 503 * \param bitstring buffer to store the result |
| 504 * \param bIterator buffer iterator |
| 505 * \returns the modified buffer iterator |
| 506 */ |
| 507 Buffer::Iterator DeserializeBitstring (std::bitset<32> *bitstring, |
| 508 Buffer::Iterator bIterator); |
| 509 |
| 510 /** |
| 511 * Deserialize nothing (null op) |
| 512 * \param bIterator buffer iterator |
| 513 * \returns the modified buffer iterator |
| 514 */ |
| 515 Buffer::Iterator DeserializeNull (Buffer::Iterator bIterator); |
| 516 /** |
| 517 * Deserialize a Sequence |
| 518 * \param numElems buffer to store the result |
| 519 * \param nMax max value to serialize |
| 520 * \param nMin min value to serialize |
| 521 * \param bIterator buffer iterator |
| 522 * \returns the modified buffer iterator |
| 523 */ |
| 524 Buffer::Iterator DeserializeSequenceOf (int *numElems, int nMax, int nMin, |
| 525 Buffer::Iterator bIterator); |
| 526 }; |
| 527 |
| 528 } // namespace ns3 |
| 529 |
| 530 #endif // NIST_ASN1_HEADER_H |
| 531 |
OLD | NEW |