@@ -187,6 +187,13 @@ def self.parse_uri(uri)
187
187
parse_raw ( Rex ::Text . decode_base64url ( uri ) )
188
188
end
189
189
190
+
191
+ #
192
+ # Look up the numeric platform ID given a string or PlatformList as input
193
+ #
194
+ # @param platform [String] The name of the platform to lookup
195
+ # @return [Fixnum] The integer value of this platform
196
+ #
190
197
def self . find_platform_id ( platform )
191
198
# Handle a PlatformList input by grabbing the first entry
192
199
if platform . respond_to? :platforms
@@ -200,6 +207,12 @@ def self.find_platform_id(platform)
200
207
} . first || Platforms [ 0 ] ) . to_i
201
208
end
202
209
210
+ #
211
+ # Look up the numeric architecture ID given a string as input
212
+ #
213
+ # @param name [String] The name of the architecture to lookup
214
+ # @return [Fixnum] The integer value of this architecture
215
+ #
203
216
def self . find_architecture_id ( name )
204
217
name = name . first if name . kind_of? ::Array
205
218
( Architectures . keys . select { |k |
@@ -242,10 +255,22 @@ def initialize(opts=nil)
242
255
self . timestamp ||= Time . now . utc . to_i
243
256
end
244
257
258
+ #
259
+ # Initializes a UUID object given a raw 16+ byte blob
260
+ #
261
+ # @param raw [String] The string containing at least 16 bytes of encoded data
262
+ # @return [Hash] The attributes encoded into this UUID
263
+ #
245
264
def load_raw ( raw )
246
265
self . class . filter_invalid ( self . class . parse_raw ( raw ) )
247
266
end
248
267
268
+ #
269
+ # Initializes a UUID object given a 22+ byte URI
270
+ #
271
+ # @param uri [String] The URI containing at least 22 bytes of encoded data
272
+ # @return [Hash] The attributes encoded into this UUID
273
+ #
249
274
def load_uri ( uri )
250
275
self . class . filter_invalid ( self . class . parse_uri ( uri ) )
251
276
end
@@ -254,6 +279,11 @@ def load_new
254
279
self . class . parse_raw ( self . class . generate_raw ( ) )
255
280
end
256
281
282
+ #
283
+ # Provides a string representation of a UUID
284
+ #
285
+ # @return [String] The human-readable version of the UUID data
286
+ #
257
287
def to_s
258
288
arch_id = self . class . find_architecture_id ( self . arch ) . to_s
259
289
plat_id = self . class . find_platform_id ( self . platform ) . to_s
@@ -265,6 +295,11 @@ def to_s
265
295
] . join ( "/" )
266
296
end
267
297
298
+ #
299
+ # Provides a hash representation of a UUID
300
+ #
301
+ # @return [Hash] The hash representation of the UUID suitable for creating a new one
302
+ #
268
303
def to_h
269
304
{
270
305
puid : self . puid ,
@@ -274,18 +309,36 @@ def to_h
274
309
}
275
310
end
276
311
312
+ #
313
+ # Provides a raw byte representation of a UUID
314
+ #
315
+ # @return [String] The 16-byte raw encoded version of the UUID
316
+ #
277
317
def to_raw
278
318
self . class . generate_raw ( self . to_h )
279
319
end
280
320
321
+ #
322
+ # Provides a URI-encoded representation of a UUID
323
+ #
324
+ # @return [String] The 22-byte URI encoded version of the UUID
325
+ #
281
326
def to_uri
282
327
Rex ::Text . encode_base64url ( self . to_raw )
283
328
end
284
329
330
+ #
331
+ # Provides a hex representation of the Payload UID of the UUID
332
+ #
333
+ # @return [String] The 16-byte hex string representing the Payload UID
334
+ #
285
335
def puid_hex
286
336
self . puid . unpack ( 'H*' ) . first
287
337
end
288
338
339
+ #
340
+ # Clears the two random XOR keys used for obfuscation
341
+ #
289
342
def xor_reset
290
343
self . xor1 = self . xor2 = nil
291
344
self
0 commit comments