1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
// Copyright (C) 2012-2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef OPTION_DATA_TYPES_H
#define OPTION_DATA_TYPES_H

#include <asiolink/io_address.h>
#include <dhcp/opaque_data_tuple.h>
#include <dhcp/option.h>
#include <exceptions/exceptions.h>
#include <util/io.h>

#include <stdint.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <utility><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace isc {
namespace dhcp {

/// @brief Exception to be thrown when invalid type specified as template parameter.
class InvalidDataType : public Exception {
public:
    InvalidDataType(const char* file, size_t line, const char* what) :
        isc::Exception(file, line, what) { };
};

/// @brief Exception to be thrown when cast to the data type was unsuccessful.
class BadDataTypeCast : public Exception {
public:
    BadDataTypeCast(const char* file, size_t line, const char* what) :
        isc::Exception(file, line, what) { };
};

/// @brief Data types of DHCP option fields.
///
/// @warning The order of data types matters: OPT_UNKNOWN_TYPE
/// must always be the last position. Also, OPT_RECORD_TYPE
/// must be at last but one position. This is because some
/// functions perform sanity checks on data type values using
/// '>' operators, assuming that all values beyond the
/// OPT_RECORD_TYPE are invalid.
enum OptionDataType {
    OPT_EMPTY_TYPE,
    OPT_BINARY_TYPE,
    OPT_BOOLEAN_TYPE,
    OPT_INT8_TYPE,
    OPT_INT16_TYPE,
    OPT_INT32_TYPE,
    OPT_UINT8_TYPE,
    OPT_UINT16_TYPE,
    OPT_UINT32_TYPE,
    OPT_ANY_ADDRESS_TYPE,
    OPT_IPV4_ADDRESS_TYPE,
    OPT_IPV6_ADDRESS_TYPE,
    OPT_IPV6_PREFIX_TYPE,
    OPT_PSID_TYPE,
    OPT_STRING_TYPE,
    OPT_TUPLE_TYPE,
    OPT_FQDN_TYPE,
    // Type to be used only internally. Allows convenient notation of the option config.
    OPT_INTERNAL_TYPE,
    OPT_RECORD_TYPE,
    OPT_UNKNOWN_TYPE
};

/// @brief Parameters being used to make up an option definition.
struct OptionDefParams {
    const char*             name;           // option name
    uint16_t                code;           // option code
    const char*             space;          // option space
    OptionDataType          type;           // data type
    bool                    array;          // is array
    const OptionDataType*   records;        // record fields
    size_t                  records_size;   // number of fields in a record
    const char*             encapsulates;   // option space encapsulated by the
                                            // particular option.
};

/// @brief Encapsulation of option definition parameters and the structure size.
struct OptionDefParamsEncapsulation {
    const struct OptionDefParams*   optionDefParams;    // parameters structure
    const int                       size;               // structure size
    const char*                     space;              // option space
};

/// @brief Trait class for data types supported in DHCP option definitions.
///
/// This is useful to check whether the type specified as template parameter
/// is supported by classes like OptionInt, OptionIntArray and some template
/// factory functions in OptionDefinition class.
template<typename T>
struct OptionDataTypeTraits {
    static const bool valid = false;
    static const int len = 0;
    static const bool integer_type = false;
    static const OptionDataType type = OPT_UNKNOWN_TYPE;
};

/// binary type is supported
template<>
struct OptionDataTypeTraits<OptionBuffer> {
    static const bool valid = true;
    static const int len = 0;
    static const bool integer_type = false;
    static const OptionDataType type = OPT_BINARY_TYPE;
};

/// bool type is supported
template<>
struct OptionDataTypeTraits<bool> {
    static const bool valid = true;
    static const int len = sizeof(uint8_t);
    static const bool integer_type = false;
    static const OptionDataType type = OPT_BOOLEAN_TYPE;
};

/// int8_t type is supported.
template<>
struct OptionDataTypeTraits<int8_t> {
    static const bool valid = true;
    static const int len = 1;
    static const bool integer_type = true;
    static const OptionDataType type = OPT_INT8_TYPE;
};

/// int16_t type is supported.
template<>
struct OptionDataTypeTraits<int16_t> {
    static const bool valid = true;
    static const int len = 2;
    static const bool integer_type = true;
    static const OptionDataType type = OPT_INT16_TYPE;
};

/// int32_t type is supported.
template<>
struct OptionDataTypeTraits<int32_t> {
    static const bool valid = true;
    static const int len = 4;
    static const bool integer_type = true;
    static const OptionDataType type = OPT_INT32_TYPE;
};

/// uint8_t type is supported.
template<>
struct OptionDataTypeTraits<uint8_t> {
    static const bool valid = true;
    static const int len = 1;
    static const bool integer_type = true;
    static const OptionDataType type = OPT_UINT8_TYPE;
};

/// uint16_t type is supported.
template<>
struct OptionDataTypeTraits<uint16_t> {
    static const bool valid = true;
    static const int len = 2;
    static const bool integer_type = true;
    static const OptionDataType type = OPT_UINT16_TYPE;
};

/// uint32_t type is supported.
template<>
struct OptionDataTypeTraits<uint32_t> {
    static const bool valid = true;
    static const int len = 4;
    static const bool integer_type = true;
    static const OptionDataType type = OPT_UINT32_TYPE;
};

/// IPv4 and IPv6 address type is supported
template<>
struct OptionDataTypeTraits<asiolink::IOAddress> {
    static const bool valid = true;
    // The len value is used to determine the size of the data
    // to be written to an option buffer. IOAddress object may
    // either represent an IPv4 or IPv6 addresses which have
    // different lengths. Thus we can't put fixed value here.
    // The length of a data to be written into an option buffer
    // have to be determined in the runtime for a particular
    // IOAddress object. Thus setting len to zero.
    static const int len = 0;
    static const bool integer_type = false;
    static const OptionDataType type = OPT_ANY_ADDRESS_TYPE;
};

/// string type is supported
template<>
struct OptionDataTypeTraits<std::string> {
    static const bool valid = true;
    // The len value is used to determine the size of the data
    // to be written to an option buffer. For strings this
    // size is unknown until we actually deal with the particular
    // string to be written. Thus setting it to zero.
    static const int len = 0;
    static const bool integer_type = false;
    static const OptionDataType type = OPT_STRING_TYPE;
};

/// @brief Encapsulates PSID length.
class PSIDLen {
public:

    /// @brief Default constructor.
    PSIDLen() : psid_len_(0) { }

    /// @brief Constructor.
    ///
    /// It checks that the specified value is not greater than
    /// 16, which is a maximum value for the PSID length.
    ///
    /// @param psid_len PSID length.
    /// @throw isc::OutOfRange If specified PSID length is greater than 16.
    explicit PSIDLen(const uint8_t psid_len)
        : psid_len_(psid_len) {
        if (psid_len_ > sizeof(uint16_t) * 8) {
            isc_throw(isc::OutOfRange, "invalid value "
                      << asUnsigned() << " of PSID length");
        }
    }

    /// @brief Returns PSID length as uint8_t value.
    uint8_t asUint8() const {
        return (psid_len_);
    }

    /// @brief Returns PSID length as unsigned int.
    ///
    /// This is useful to convert the value to a numeric type which
    /// can be logged directly. Note that the uint8_t value has to
    /// be cast to an integer value to be logged as a number. This
    /// is because the uint8_t is often implemented as char, in which
    /// case directly logging an uint8_t value prints a character rather
    /// than a number.
    unsigned int asUnsigned() const {
        return (static_cast<unsigned>(psid_len_));
    }

private:

    /// @brief PSID length.
    uint8_t psid_len_;
};

/// @brief Encapsulates PSID value.
class PSID {
public:

    /// @brief Default constructor.
    PSID() : psid_(0) { }

    /// @brief Constructor.
    ///
    /// This constructor doesn't perform any checks on the input data.
    ///
    /// @param psid PSID value.
    explicit PSID(const uint16_t psid)
        : psid_(psid) {
    }

    /// @brief Returns PSID value as a number.
    uint16_t asUint16() const {
        return (psid_);
    }

private:

    /// @brief PSID value.
    uint16_t psid_;

};

/// @brief Defines a pair of PSID length / value.
typedef std::pair<PSIDLen, PSID> PSIDTuple;

/// @brief Encapsulates prefix length.
class PrefixLen {
public:

    /// @brief Default constructor.
    PrefixLen() : prefix_len_(0) { }

    /// @brief Constructor.
    ///
    /// This constructor checks if the specified prefix length is
    /// in the range of 0 to 128.
    ///
    /// @param prefix_len Prefix length value.
    /// @throw isc::OutOfRange If specified prefix length is greater than 128.
    explicit PrefixLen(const uint8_t prefix_len)
        : prefix_len_(prefix_len) {
    }

    /// @brief Returns prefix length as uint8_t value.
    uint8_t asUint8() const {
        return (prefix_len_);
    }

    /// @brief Returns prefix length as unsigned int.
    ///
    /// This is useful to convert the value to a numeric type which
    /// can be logged directly. See @ref PSIDLen::asUnsigned for the
    /// use cases of this accessor.
    unsigned int asUnsigned() const {
        return (static_cast<unsigned>(prefix_len_));
    }

private:

    /// @brief Prefix length.
    uint8_t prefix_len_;
};

/// @brief Defines a pair of prefix length / value.
typedef std::pair<PrefixLen, asiolink::IOAddress> PrefixTuple;

/// @brief Utility class for option data types.
///
/// This class provides a set of utility functions to operate on
/// supported DHCP option data types. It includes conversion
/// between enumerator values representing data types and data
/// type names. It also includes a set of functions that write
/// data into option buffers and read data from option buffers.
/// The data being written and read are converted from/to actual
/// data types.
/// @note This is a singleton class but it can be accessed via
/// static methods only.
class OptionDataTypeUtil {
public:

    /// @brief Return option data type from its name.
    ///
    /// @param data_type data type name.
    /// @return option data type.
    static OptionDataType getDataType(const std::string& data_type);

    /// @brief Return option data type name from the data type enumerator.
    ///
    /// @param data_type option data type.
    /// @return option data type name.
    static const std::string& getDataTypeName(const OptionDataType data_type);

    /// @brief Get data type buffer length.
    ///
    /// This function returns the size of a particular data type.
    /// Values returned by this function correspond to the data type
    /// sizes defined in OptionDataTypeTraits (IPV4_ADDRESS_TYPE and
    /// IPV6_ADDRESS_TYPE are exceptions here) so they rather indicate
    /// the fixed length of the data being written into the buffer,
    /// not the size of the particular data type. Thus for data types
    /// such as string, binary etc. for which the buffer length can't
    /// be determined this function returns 0.
    /// In addition, this function returns the data sizes for
    /// IPV4_ADDRESS_TYPE and IPV6_ADDRESS_TYPE as their buffer
    /// representations have fixed data lengths: 4 and 16 respectively.
    ///
    /// @param data_type data type which size is to be returned.
    /// @return data type size or zero for variable length types.
    static int getDataTypeLen(const OptionDataType data_type);

    /// @brief Read IPv4 or IPv6 address from a buffer.
    ///
    /// @param buf input buffer.
    /// @param family address family: AF_INET or AF_INET6.
    ///
    /// @throw isc::dhcp::BadDataTypeCast when the data being read
    /// is truncated.
    /// @return address being read.
    static asiolink::IOAddress readAddress(const std::vector<uint8_t>& buf,
                                           const short family);

    /// @brief Append IPv4 or IPv6 address to a buffer.
    ///
    /// @param address IPv4 or IPv6 address.
    /// @param [out] buf output buffer.
    static void writeAddress(const asiolink::IOAddress& address,
                             std::vector<uint8_t>& buf);

    /// @brief Append hex-encoded binary values to a buffer.
    ///
    /// @param hex_str string representing a binary value encoded
    /// with hexadecimal digits (without 0x prefix).
    /// @param [out] buf output buffer.
    static void writeBinary(const std::string& hex_str,
                            std::vector<uint8_t>& buf);

    /// @brief Read length and string tuple from a buffer.
    ///
    /// @param buf input buffer.
    /// @param lengthfieldtype LENGTH_1_BYTE (DHCPv4) or LENGTH_2_BYTES (DHCPv6)
    /// @throw isc::dhcp::BadDataTypeCast when the data being read
    /// is truncated.
    /// @return string being read.
    static std::string readTuple(const std::vector<uint8_t>& buf,
                                 OpaqueDataTuple::LengthFieldType lengthfieldtype);

    /// @brief Read length and string tuple from a buffer.
    ///
    /// @param buf input buffer.
    /// @param tuple reference of the tuple to read into
    /// @throw isc::dhcp::BadDataTypeCast when the data being read
    /// is truncated.
    static void readTuple(const std::vector<uint8_t>& buf,
                          OpaqueDataTuple& tuple);

    /// @brief Append length and string tuple to a buffer
    ///
    /// @param value length and string tuple
    /// @param lengthfieldtype LENGTH_1_BYTE (DHCPv4) or LENGTH_2_BYTES (DHCPv6)
    /// @param [out] buf output buffer.
    static void writeTuple(const std::string& value,
                           OpaqueDataTuple::LengthFieldType lengthfieldtype,
                           std::vector<uint8_t>& buf);

    /// @brief Append length and string tuple to a buffer
    ///
    /// @param tuple length and string tuple
    /// @param [out] buf output buffer.
    static void writeTuple(const OpaqueDataTuple& tuple,
                           std::vector<uint8_t>& buf);

    /// @brief Returns Length Field Type for a tuple.
    ///
    /// Returns Length Field Type for a tuple basing on the given
    /// Option v4/v6 Universe.
    ///
    /// @param u specifies universe (V4 or V6)
    /// @return By default 1 octet Length Field Type for V4 option
    /// or 2 octets Length Field Type for V6 option
    static OpaqueDataTuple::LengthFieldType getTupleLenFieldType(Option::Universe u);

    /// @brief Read boolean value from a buffer.
    ///
    /// @param buf input buffer.
    ///
    /// @throw isc::dhcp::BadDataTypeCast when the data being read
    /// is truncated or the value is invalid (neither 1 nor 0).
    /// @return boolean value read from a buffer.
    static bool readBool(const std::vector<uint8_t>& buf);

    /// @brief Append boolean value into a buffer.
    ///
    /// The bool value is encoded in a buffer in such a way that
    /// "1" means "true" and "0" means "false".
    ///
    /// @param value boolean value to be written.
    /// @param [out] buf output buffer.
    static void writeBool(const bool value, std::vector<uint8_t>& buf);

    /// @brief Read integer value from a buffer.
    ///
    /// @param buf input buffer.
    /// @tparam integer type of the returned value.
    ///
    /// @throw isc::dhcp::BadDataTypeCast when the data in the buffer
    /// is truncated.
    /// @return integer value being read.
    template<typename T>
    static T readInt(const std::vector<uint8_t>& buf) {
        if (!OptionDataTypeTraits<T>::integer_type) {
            isc_throw(isc::dhcp::InvalidDataType, "specified data type to be returned"
                      " by readInteger is unsupported integer type");
        }

        if (buf.size() < OptionDataTypeTraits<T>::len) {<--- Unsigned less than zero
            isc_throw(isc::dhcp::BadDataTypeCast,
                      "failed to read an integer value from a buffer"
                      << " - buffer is truncated.");
        }

        T value;
        switch (OptionDataTypeTraits<T>::len) {
        case 1:
            value = *(buf.begin());
            break;
        case 2:
            // Calling readUint16 works either for unsigned
            // or signed types.
            value = isc::util::readUint16(&(*buf.begin()), buf.size());
            break;
        case 4:
            // Calling readUint32 works either for unsigned
            // or signed types.
            value = isc::util::readUint32(&(*buf.begin()), buf.size());
            break;
        default:
            // This should not happen because we made checks on data types
            // but it does not hurt to keep throw statement here.
            isc_throw(isc::dhcp::InvalidDataType,
                      "invalid size of the data type to be read as integer.");
        }
        return (value);
    }

    /// @brief Append integer or unsigned integer value to a buffer.
    ///
    /// @param value an integer value to be written into a buffer.
    /// @param [out] buf output buffer.
    /// @tparam data type of the value.
    template<typename T>
    static void writeInt(const T value,
                         std::vector<uint8_t>& buf) {
        if (!OptionDataTypeTraits<T>::integer_type) {
            isc_throw(InvalidDataType, "provided data type is not the supported.");
        }
        switch (OptionDataTypeTraits<T>::len) {
        case 1:
            buf.push_back(static_cast<uint8_t>(value));
            break;
        case 2:
            buf.resize(buf.size() + 2);
            isc::util::writeUint16(static_cast<uint16_t>(value), &buf[buf.size() - 2], 2);
            break;
        case 4:
            buf.resize(buf.size() + 4);
            isc::util::writeUint32(static_cast<uint32_t>(value), &buf[buf.size() - 4], 4);
            break;
        default:
            // The cases above cover whole range of possible data lengths because
            // we check at the beginning of this function that given data type is
            // a supported integer type which can be only 1,2 or 4 bytes long.
            ;
        }
    }

    /// @brief Read FQDN from a buffer as a string value.
    ///
    /// The format of an FQDN within a buffer complies with RFC1035,
    /// section 3.1.
    ///
    /// @param buf input buffer holding a FQDN.
    ///
    /// @throw BadDataTypeCast if a FQDN stored within a buffer is
    /// invalid (e.g. empty, contains invalid characters, truncated).
    /// @return fully qualified domain name in a text form.
    static std::string readFqdn(const std::vector<uint8_t>& buf);

    /// @brief Append FQDN into a buffer.
    ///
    /// This method appends the Fully Qualified Domain Name (FQDN)
    /// represented as string value into a buffer. The format of
    /// the FQDN being stored into a buffer complies with RFC1035,
    /// section 3.1.
    ///
    /// @param fqdn fully qualified domain name to be written.
    /// @param [out] buf output buffer.
    /// @param downcase indicates if the FQDN should be converted to lower
    /// case (if true). By default it is not converted.
    ///
    /// @throw isc::dhcp::BadDataTypeCast if provided FQDN
    /// is invalid.
    static void writeFqdn(const std::string& fqdn,
                          std::vector<uint8_t>& buf,
                          const bool downcase = false);

    /// @brief Return the number of labels in the Name.
    ///
    /// If the specified name is empty the 0 is returned.
    ///
    /// @param text_name A text representation of the name.
    ///
    /// @return A number of labels in the provided name or 0 if the
    /// name string is empty.
    /// @throw isc::dhcp::BadDataTypeCast if provided name is malformed.
    static unsigned int getLabelCount(const std::string& text_name);

    /// @brief Read prefix from a buffer.
    ///
    /// This method reads prefix length and a prefix value from a buffer.
    /// The prefix value has variable length and this length is determined
    /// from the first byte of the buffer. If the length is not divisible
    /// by 8, the prefix is padded with zeros to the next byte boundary.
    ///
    /// @param buf input buffer holding a prefix length / prefix tuple.
    ///
    /// @return Prefix length and value.
    static PrefixTuple readPrefix(const std::vector<uint8_t>& buf);

    /// @brief Append prefix into a buffer.
    ///
    /// This method writes prefix length (1 byte) followed by a variable
    /// length prefix.
    ///
    /// @param prefix_len Prefix length in bits (0 to 128).
    /// @param prefix Prefix value.
    /// @param [out] buf Output buffer.
    static void writePrefix(const PrefixLen& prefix_len,
                            const asiolink::IOAddress& prefix,
                            std::vector<uint8_t>& buf);

    /// @brief Read PSID length / value tuple from a buffer.
    ///
    /// This method reads three bytes from a buffer. The first byte
    /// holds a PSID length value. The remaining two bytes contain a
    /// zero padded PSID value.
    ///
    /// @return PSID length / value tuple.
    /// @throw isc::dhcp::BadDataTypeCast if PSID length or value held
    /// in the buffer is incorrect or the buffer is truncated.
    static PSIDTuple readPsid(const std::vector<uint8_t>& buf);

    /// @brief Append PSID length/value into a buffer.
    ///
    /// This method appends 1 byte of PSID length and 2 bytes of PSID
    /// value into a buffer. The PSID value contains a PSID length
    /// number of significant bits, followed by 16 - PSID length
    /// zero bits.
    ///
    /// @param psid_len PSID length in the range of 0 to 16 holding the
    /// number of significant bits within the PSID value.
    /// @param psid PSID value, where the lowest value is 0, and the
    /// highest value is 2^(PSID length)-1.
    /// @param [out] buf output buffer.
    ///
    /// @throw isc::dhcp::BadDataTypeCast if specified psid_len or
    /// psid value is incorrect.
    static void writePsid(const PSIDLen& psid_len, const PSID& psid,
                          std::vector<uint8_t>& buf);

    /// @brief Read string value from a buffer.
    ///
    /// To be compliant with RFC 2132, Sec. 2, trailing NULLs are trimmed.
    /// @param buf input buffer.
    ///
    /// @return string value being read.
    /// @throw isc::dhcp::OutOfRange is the payload contains only NULLs.
    static std::string readString(const std::vector<uint8_t>& buf);

    /// @brief Write UTF8-encoded string into a buffer.
    ///
    /// @param value string value to be written into a buffer.
    /// @param [out] buf output buffer.
    static void writeString(const std::string& value,
                            std::vector<uint8_t>& buf);
private:

    /// The container holding mapping of data type names to
    /// data types enumerator.
    std::map<std::string, OptionDataType> data_types_;

    /// The container holding mapping of data types to data
    /// type names.
    std::map<OptionDataType, std::string> data_type_names_;

    /// @brief Private constructor.
    ///
    /// This constructor is private because this class should
    /// be used as singleton (through static public functions).
    OptionDataTypeUtil();

    /// @brief Return instance of OptionDataTypeUtil
    ///
    /// This function is used by some of the public static functions
    /// to create an instance of OptionDataTypeUtil class.
    /// When this instance is called it calls the classes constructor
    /// and initializes some of the private data members.
    ///
    /// @return instance of OptionDataTypeUtil singleton.
    static OptionDataTypeUtil& instance();

    /// @brief Return option data type from its name.
    ///
    /// @param data_type data type name.
    /// @return option data type.
    OptionDataType getDataTypeImpl(const std::string& data_type) const;

    /// @brief Return option data type name from the data type enumerator.
    ///
    /// @param data_type option data type.
    /// @return option data type name.
    const std::string& getDataTypeNameImpl(const OptionDataType data_type) const;
};


} // isc::dhcp namespace
} // isc namespace

#endif // OPTION_DATA_TYPES_H