2 // Copyright (C) 2008 Francesco Salvestrini
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
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.
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef LIBS_NET_UUID_H
20 #define LIBS_NET_UUID_H
25 #include "libs/misc/exception.h"
33 IETF_RFC4122_TIMEBASED
= 1,
34 DCE_SECURITY_POSIX_UID
= 2,
35 IETF_RFC4122_NAMEBASED_MD5
= 3,
36 IETF_RFC4122_RANDOM
= 4,
37 IETF_RFC4122_NAMEBASED_SHA1
= 5
43 UUID(const std::string
& u
);
44 UUID(version_t version
);
49 operator std::string(void);
50 bool operator ==(const UUID
& rhs
);
51 UUID
& operator =(const UUID
& rhs
);
52 friend std::ostream
& operator <<(std::ostream
& stream
,
54 friend std::istream
& operator >>(std::istream
& stream
,
58 class invalid_version
: public Exception
{
62 invalid_version(version_t ver
,
63 const std::string
& description
) :
64 Exception(description
),
67 ~invalid_version(void) throw () {};
70 invalid_version(void);
72 // nothing more for the time being
75 class invalid_hexfield
: public Exception
{
79 invalid_hexfield(uint8_t pos
,
80 const std::string
& description
) :
81 Exception(description
),
85 ~invalid_hexfield(void) throw () {};
88 invalid_hexfield(void);
90 // nothing more for the time being
93 class formatting_problem
: public Exception
{
97 formatting_problem(version_t ver
,
98 const std::string
& description
) :
99 Exception(description
),
103 ~formatting_problem(void) throw () {};
106 formatting_problem(void);
108 // nothing more for the time being
111 class scrambling_problem
: public Exception
{
115 scrambling_problem(version_t ver
,
116 const std::string
& description
) :
117 Exception(description
),
121 ~scrambling_problem(void) throw () {};
124 scrambling_problem(void);
126 // nothing more for the time being
129 class generic_problem
: public Exception
{
131 generic_problem(const std::string
& description
) :
132 Exception(description
)
135 ~generic_problem(void) throw () {};
138 generic_problem(void);
140 // nothing more for the time being
148 // The fields are encoded as 16 octets, with the sizes and order of the
149 // fields defined above, and with each field encoded with the Most
150 // Significant Byte first (known as network byte order). Note that the
151 // field names, particularly for multiplexed fields, follow historical
155 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
156 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
158 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
159 // | time_mid | time_hi_and_version |
160 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
161 // |clk_seq_hi_res | clk_seq_low | node (0-1) |
162 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
164 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
169 uint16_t time_hi_and_version
;
174 bool grab_4hex(const std::string
& u
,
175 std::string::size_type s
,
176 std::string::size_type e
,
178 bool grab_8hex(const std::string
& u
,
179 std::string::size_type s
,
180 std::string::size_type e
,
182 bool grab_12hex(const std::string
& u
,
183 std::string::size_type s
,
184 std::string::size_type e
,
187 void format_uuid_tb(void);
188 void format_uuid_nb(void);
189 void format_uuid_random(void);
190 void scramble_sha1(void);
191 void scramble_md5(void);
195 #endif // LIBS_NET_UUID_H