easy-uuid 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/uuid.rb +40 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b199e86c6f8ebe25bbee9619c8ae6bc55c2ee1fb60ed39f7094663c3146e1b2
|
4
|
+
data.tar.gz: 779053987990cba37a7680cc1ca551049ccae9429e400e77cb01e17b39f3f43a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48d208c940f5e1569adfbaa4f1fe9a609bbfe68d661bcc67202c21a0484445cf0b4b3ced0da704bfe90eb65a840a7c347488f3f28d0c910a5665c8ebe60de7b3
|
7
|
+
data.tar.gz: 9b6fa9a013391e18878c4f26e3c032be4d7f3f3bea7f4d3dc1c70a69f05091abe2b7d0164a28ced6950cb430eccedcf037d1df92a6ee7ee97e83b83358457150
|
data/lib/uuid.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'digest/md5'
|
3
|
+
require 'digest/sha1'
|
4
|
+
|
1
5
|
module Kernel
|
2
6
|
# Cast to UUID
|
3
7
|
#
|
@@ -16,7 +20,7 @@ end
|
|
16
20
|
|
17
21
|
class UUID
|
18
22
|
# Version
|
19
|
-
VERSION = '0.
|
23
|
+
VERSION = '0.3.0'
|
20
24
|
|
21
25
|
# Basic regex for validating UUID formatted string
|
22
26
|
REGEX = /\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/
|
@@ -38,7 +42,19 @@ class UUID
|
|
38
42
|
self.new( [str.delete('-')].pack('H32') )
|
39
43
|
end
|
40
44
|
|
45
|
+
def self.create_v3(namespace, name)
|
46
|
+
self.create_v3_v5(Digest::MD5, '3', namespace, name)
|
47
|
+
end
|
41
48
|
|
49
|
+
def self.generate_v4
|
50
|
+
UUID(SecureRandom.uuid)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.create_v5(namespace, name)
|
54
|
+
self.create_v3_v5(Digest::SHA1, '5', namespace, name)
|
55
|
+
end
|
56
|
+
|
57
|
+
|
42
58
|
# Create UUID
|
43
59
|
#
|
44
60
|
# @param [String,Integer] UUID value
|
@@ -60,11 +76,12 @@ class UUID
|
|
60
76
|
raise ArgumentError,
|
61
77
|
"need to be a 16 byte ASCII-8BIT string (#{v})"
|
62
78
|
end
|
63
|
-
@raw = v.dup
|
79
|
+
@raw = v.dup
|
64
80
|
else
|
65
81
|
raise ArgumentError,
|
66
82
|
"expected 128-bit integer or 16-byte string"
|
67
83
|
end
|
84
|
+
@raw.freeze
|
68
85
|
end
|
69
86
|
|
70
87
|
|
@@ -150,9 +167,28 @@ class UUID
|
|
150
167
|
|
151
168
|
|
152
169
|
# Nil/Empty UUID
|
153
|
-
NIL
|
170
|
+
NIL = UUID('00000000-0000-0000-0000-000000000000')
|
154
171
|
|
155
172
|
# UUID with all bit set.
|
156
173
|
# @note It is not a valid UUID but can be usefull
|
157
|
-
FFF
|
174
|
+
FFF = UUID('ffffffff-ffff-ffff-ffff-ffffffffffff')
|
175
|
+
|
176
|
+
# Known namespace for version 3 and 5
|
177
|
+
DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
|
178
|
+
URL = UUID('6ba7b811-9dad-11d1-80b4-00c04fd430c8')
|
179
|
+
OID = UUID('6ba7b812-9dad-11d1-80b4-00c04fd430c8')
|
180
|
+
X500 = UUID('6ba7b814-9dad-11d1-80b4-00c04fd430c8')
|
181
|
+
|
182
|
+
|
183
|
+
def self.create_v3_v5(h, v, namespace, name)
|
184
|
+
namespace_str = namespace.to_raw
|
185
|
+
name_str = name.to_s
|
186
|
+
digest = h.hexdigest(namespace_str + name_str)
|
187
|
+
UUID([digest.tap {|s| s[12] = v }].pack('H32'))
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
private_class_method :create_v3_v5
|
192
|
+
|
193
|
+
|
158
194
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy-uuid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephane D'Alu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
|
-
rubygems_version: 3.
|
68
|
+
rubygems_version: 3.4.5
|
69
69
|
signing_key:
|
70
70
|
specification_version: 4
|
71
71
|
summary: UUID library for Ruby
|