sixarm_ruby_xid 3.4.1 → 3.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e04d2554f5e0367d86cef868442e8b447666d243
4
- data.tar.gz: 3ce100cfeffc29ec7b550d4758730f1901c4d292
3
+ metadata.gz: 2f5b6519a9ac4fad507d584b4e79e3a8acd07052
4
+ data.tar.gz: ae6ae65995d3091262ce3444951ede3437335a4e
5
5
  SHA512:
6
- metadata.gz: 251fa94b70e8f7cae7b5c401e9373d4de82ab423668e9b37ae73b94ddc12904e30a2d654fe56f0144c30c3347e8090e0ca30d8b82459a03ca8592c69d36bac21
7
- data.tar.gz: 6c63340b6c8b3992c0c80d8abc9482361ac3e3af2e8db0c756149e30c19614f3cc52cb2220e771b19aad7fef556c73fc14b3068074d3ada879dd448d65d9df67
6
+ metadata.gz: ddce1beb9a306f2b3f5c95a836eff8aba4aa12a723f91102f6cde20cd353990dc028b6d06b3a5515f0738195dffa7fa1449a997080f0954b4deae3fe354203bf
7
+ data.tar.gz: 10012f4d5b4a0f1a51e16a35ab2a1c0f98dd80903cfff4cac3709c68bc13b5187f866e8f2015da018c85cdb639d764cce4f141c36aaa4f11ae39fc6eb616bb6a
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/Rakefile CHANGED
@@ -3,8 +3,15 @@ require "rake"
3
3
  require "rake/testtask"
4
4
 
5
5
  Rake::TestTask.new(:test) do |t|
6
- t.libs << 'lib' << 'test'
7
- t.pattern = 'test/*.rb'
6
+ t.libs.push("lib", "test")
7
+ t.pattern = "test/**/*.rb"
8
8
  end
9
9
 
10
10
  task :default => [:test]
11
+ task :default => [:test]
12
+ task :default => [:test]
13
+ task :default => [:test]
14
+ task :default => [:test]
15
+ task :default => [:test]
16
+ task :default => [:test]
17
+ task :default => [:test]
@@ -3,34 +3,4 @@
3
3
  Please see README
4
4
  =end
5
5
 
6
- require "securerandom"
7
- require "digest/sha2"
8
-
9
- class XID < String
10
-
11
- def initialize(s = nil)
12
- s and (XID.valid?(s) or raise ArgumentError)
13
- super(s || SecureRandom.hex)
14
- end
15
-
16
- def valid?
17
- XID.valid?(self)
18
- end
19
-
20
- def self.valid?(s)
21
- !!(s && s.is_a?(String) && s.size == 32 && s =~ /\A[0-9a-f]{32}\Z/)
22
- end
23
-
24
- def digest
25
- XID.digest(self)
26
- end
27
-
28
- def self.digest(s)
29
- Digest::SHA256.new.update(s).to_s
30
- end
31
-
32
- def self.parse(s)
33
- XID.new(s.downcase.gsub(/[^0-9a-f]/,'')[0...32])
34
- end
35
-
36
- end
6
+ require_relative "sixarm_ruby_xid/xid"
@@ -0,0 +1,101 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin rdoc
3
+ XID class.
4
+ =end
5
+
6
+ require "securerandom"
7
+ require "digest/sha2"
8
+
9
+ class XID < String
10
+
11
+ # Initialize a new XID, optionally with a string.
12
+ #
13
+ # Example:
14
+ #
15
+ # xid = XID.new
16
+ #
17
+ # xid = XID.new("4bb88af57d4ddc224fecad688442423d")
18
+ #
19
+ # Return: [XID] A new XID
20
+ #
21
+ def initialize(s = nil)
22
+ s and (XID.valid?(s) or raise ArgumentError)
23
+ super(s || SecureRandom.hex)
24
+ end
25
+
26
+ # Is this XID valid?
27
+ #
28
+ # Example:
29
+ #
30
+ # xid = XID.new
31
+ # xid.valid? #=> true
32
+ #
33
+ # Return: [true/false]
34
+ #
35
+ def valid?
36
+ XID.valid?(self)
37
+ end
38
+
39
+ # Is a given XID string valid?
40
+ #
41
+ # Example:
42
+ #
43
+ # XID.valid?("4bb88af57d4ddc224fecad688442423d") #=> true
44
+ # XID.valid?("hello") #=> false
45
+ #
46
+ # Return: [true/false]
47
+ #
48
+ def self.valid?(s)
49
+ !!(s && s.is_a?(String) && s.size == 32 && s =~ /\A[0-9a-f]{32}\Z/)
50
+ end
51
+
52
+ # Compute the XID digest of this XID.
53
+ #
54
+ # This is useful for proving knowledge of the XID,
55
+ # without needed to expose the XID.
56
+ #
57
+ # Example:
58
+ #
59
+ # xid = XID.new("4bb88af57d4ddc224fecad688442423d")
60
+ # xid.digest
61
+ # #=> 4d648be0ca9dbb9e3a1b6b30b9d13c79ecbc0818dfca4125cc7961e32d61112c
62
+ #
63
+ def digest
64
+ XID.digest(self)
65
+ end
66
+
67
+ # Compute the XID digest of a given string.
68
+ #
69
+ # This is useful for proving knowledge of the XID,
70
+ # without needed to expose the XID.
71
+ #
72
+ # Example:
73
+ #
74
+ # xid = XID.new("4bb88af57d4ddc224fecad688442423d")
75
+ # xid.digest
76
+ # #=> 4d648be0ca9dbb9e3a1b6b30b9d13c79ecbc0818dfca4125cc7961e32d61112c
77
+ #
78
+ def self.digest(s)
79
+ Digest::SHA256.new.update(s).to_s
80
+ end
81
+
82
+ # Parse a string to an XID.
83
+ #
84
+ # This does three steps:
85
+ #
86
+ # * downcase
87
+ # * delete any non-hex characters
88
+ # * take the first 32 characters
89
+ #
90
+ # Example:
91
+ #
92
+ # xid = XID.parse("***FFAD30A1-BE5E-B511-9ED8-976CAB0281B6***")
93
+ # #=> "ffad30a1be5eb5119ed8976cab0281b6"
94
+ #
95
+ # Return: [XID] A new XID
96
+ #
97
+ def self.parse(s)
98
+ XID.new(s.downcase.gsub(/[^0-9a-f]/,'')[0...32])
99
+ end
100
+
101
+ end
@@ -1,120 +1,11 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require "minitest/autorun"
3
- Minitest::Test ||= MiniTest::Unit::TestCase
3
+ require "coveralls"
4
4
  require "simplecov"
5
+ Coveralls.wear!
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
5
10
  SimpleCov.start
6
11
  require "sixarm_ruby_xid"
7
-
8
- describe XID do
9
-
10
- describe "#new" do
11
-
12
- describe "with initialize defaults" do
13
-
14
- it "is a string with the correct length and characters" do
15
- xid = XID.new
16
- xid.must_match /\A[0-9a-f]{32}\z/
17
- end
18
-
19
- it "is always different" do
20
- seen = Set.new
21
- 99999.times.each{
22
- xid = XID.new
23
- seen.include?(xid).must_equal false
24
- seen.add(xid)
25
- }
26
- end
27
-
28
- end
29
-
30
- describe "with valid initialize string" do
31
-
32
- it "sets" do
33
- s = "1cf2a839c0890bb9be7e9d56b7405a54"
34
- xid = XID.new(s)
35
- xid.must_equal(s)
36
- end
37
-
38
- end
39
-
40
- describe "with invalid initialize string" do
41
-
42
- it "raises" do
43
- proc { XID.new("invalid") }.must_raise ArgumentError
44
- end
45
-
46
- end
47
-
48
- end
49
-
50
- describe ".valid" do
51
-
52
- describe "with valid string" do
53
- it "is true" do
54
- xid = XID.new("c3d010bbfec046f59c7fe843d32dab32")
55
- xid.valid?.must_equal true
56
- end
57
- end
58
-
59
- describe "with invalid string" do
60
- it "never gets called because it fails to create an xid" do
61
- proc { XID.new("abc") }.must_raise ArgumentError
62
- end
63
- end
64
-
65
- end
66
-
67
- describe "#valid" do
68
-
69
- describe "with valid string" do
70
- it "is true" do
71
- XID.valid?("c3d010bbfec046f59c7fe843d32dab32").must_be_same_as true
72
- end
73
- end
74
-
75
- describe "with invalid string" do
76
- it "is false" do
77
- XID.valid?("abc").must_be_same_as false
78
- end
79
- end
80
-
81
- end
82
-
83
- describe "#digest" do
84
-
85
- it "digests" do
86
- xid = XID.new
87
- xid.digest.must_match /\A[0-9a-f]{64}\z/
88
- end
89
-
90
- end
91
-
92
- describe ".digest" do
93
-
94
- it "digests" do
95
- XID.digest("foo").must_match /\A[0-9a-f]{64}\z/
96
- end
97
-
98
- end
99
-
100
- describe ".parse" do
101
-
102
- it "converts to lower case" do
103
- XID.parse("C3D010BBFEC046F59C7FE843D32DAB32").must_equal "c3d010bbfec046f59c7fe843d32dab32"
104
- end
105
-
106
- it "deletes non-hex characters" do
107
- XID.parse("!!c3d010bb-fec0-46f59c7f-e843d32dab32!!").must_equal "c3d010bbfec046f59c7fe843d32dab32"
108
- end
109
-
110
- it "chops at 32 characters" do
111
- XID.parse("c3d010bbfec046f59c7fe843d32dab32aaaaaaaaa").must_equal "c3d010bbfec046f59c7fe843d32dab32"
112
- end
113
-
114
- it "raises if the string is invalid" do
115
- proc { XID.parse("abc") }.must_raise ArgumentError
116
- end
117
-
118
- end
119
-
120
- end
@@ -0,0 +1,116 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "sixarm_ruby_xid_test"
3
+
4
+ describe XID do
5
+
6
+ describe "#new" do
7
+
8
+ describe "with initialize defaults" do
9
+
10
+ it "is a string with the correct length and characters" do
11
+ xid = XID.new
12
+ xid.must_match /\A[0-9a-f]{32}\z/
13
+ end
14
+
15
+ it "is always different" do
16
+ seen = Set.new
17
+ 99999.times.each{
18
+ xid = XID.new
19
+ seen.include?(xid).must_equal false
20
+ seen.add(xid)
21
+ }
22
+ end
23
+
24
+ end
25
+
26
+ describe "with valid initialize string" do
27
+
28
+ it "sets" do
29
+ s = "1cf2a839c0890bb9be7e9d56b7405a54"
30
+ xid = XID.new(s)
31
+ xid.must_equal(s)
32
+ end
33
+
34
+ end
35
+
36
+ describe "with invalid initialize string" do
37
+
38
+ it "raises" do
39
+ proc { XID.new("invalid") }.must_raise ArgumentError
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ describe ".valid" do
47
+
48
+ describe "with valid string" do
49
+ it "is true" do
50
+ xid = XID.new("c3d010bbfec046f59c7fe843d32dab32")
51
+ xid.valid?.must_equal true
52
+ end
53
+ end
54
+
55
+ describe "with invalid string" do
56
+ it "never gets called because it fails to create an xid" do
57
+ proc { XID.new("abc") }.must_raise ArgumentError
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ describe "#valid" do
64
+
65
+ describe "with valid string" do
66
+ it "is true" do
67
+ XID.valid?("c3d010bbfec046f59c7fe843d32dab32").must_be_same_as true
68
+ end
69
+ end
70
+
71
+ describe "with invalid string" do
72
+ it "is false" do
73
+ XID.valid?("abc").must_be_same_as false
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ describe "#digest" do
80
+
81
+ it "digests" do
82
+ xid = XID.new
83
+ xid.digest.must_match /\A[0-9a-f]{64}\z/
84
+ end
85
+
86
+ end
87
+
88
+ describe ".digest" do
89
+
90
+ it "digests" do
91
+ XID.digest("foo").must_match /\A[0-9a-f]{64}\z/
92
+ end
93
+
94
+ end
95
+
96
+ describe ".parse" do
97
+
98
+ it "converts to lower case" do
99
+ XID.parse("C3D010BBFEC046F59C7FE843D32DAB32").must_equal "c3d010bbfec046f59c7fe843d32dab32"
100
+ end
101
+
102
+ it "deletes non-hex characters" do
103
+ XID.parse("!!c3d010bb-fec0-46f59c7f-e843d32dab32!!").must_equal "c3d010bbfec046f59c7fe843d32dab32"
104
+ end
105
+
106
+ it "chops at 32 characters" do
107
+ XID.parse("c3d010bbfec046f59c7fe843d32dab32aaaaaaaaa").must_equal "c3d010bbfec046f59c7fe843d32dab32"
108
+ end
109
+
110
+ it "raises if the string is invalid" do
111
+ proc { XID.parse("abc") }.must_raise ArgumentError
112
+ end
113
+
114
+ end
115
+
116
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sixarm_ruby_xid
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.1
4
+ version: 3.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - SixArm
@@ -44,24 +44,100 @@ cert_chain:
44
44
  2AC9FOGkybW6DJEFSFFMlNk0IILsa/gNp8ufGuTVLWF9FUUdMNK+TMbghnifT8/1
45
45
  n+ES/gQPOnvmVkLDGw==
46
46
  -----END CERTIFICATE-----
47
- date: 2015-07-08 00:00:00.000000000 Z
48
- dependencies: []
49
- description: XID generates a new string suitable for security, authentication, tracking,
50
- etc.
47
+ date: 2015-07-19 00:00:00.000000000 Z
48
+ dependencies:
49
+ - !ruby/object:Gem::Dependency
50
+ name: minitest
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 5.7.0
56
+ - - "<"
57
+ - !ruby/object:Gem::Version
58
+ version: '6'
59
+ type: :development
60
+ prerelease: false
61
+ version_requirements: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 5.7.0
66
+ - - "<"
67
+ - !ruby/object:Gem::Version
68
+ version: '6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">"
74
+ - !ruby/object:Gem::Version
75
+ version: 10.4.2
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '11'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">"
84
+ - !ruby/object:Gem::Version
85
+ version: 10.4.2
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '11'
89
+ - !ruby/object:Gem::Dependency
90
+ name: simplecov
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 0.10.0
96
+ - - "<"
97
+ - !ruby/object:Gem::Version
98
+ version: '2'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: 0.10.0
106
+ - - "<"
107
+ - !ruby/object:Gem::Version
108
+ version: '2'
109
+ - !ruby/object:Gem::Dependency
110
+ name: coveralls
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: 0.8.2
116
+ - - "<"
117
+ - !ruby/object:Gem::Version
118
+ version: '2'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: 0.8.2
126
+ - - "<"
127
+ - !ruby/object:Gem::Version
128
+ version: '2'
129
+ description: XID generates a new random id, suitable for foreign keys, security authentication,
130
+ unique tracking, etc.
51
131
  email: sixarm@sixarm.com
52
132
  executables: []
53
133
  extensions: []
54
134
  extra_rdoc_files: []
55
135
  files:
56
- - ".gemtest"
57
- - CHANGES.md
58
- - CONTRIBUTING.md
59
- - LICENSE.md
60
- - README.md
61
136
  - Rakefile
62
- - VERSION
63
137
  - lib/sixarm_ruby_xid.rb
138
+ - lib/sixarm_ruby_xid/xid.rb
64
139
  - test/sixarm_ruby_xid_test.rb
140
+ - test/sixarm_ruby_xid_test/xid_test.rb
65
141
  homepage: http://sixarm.com/
66
142
  licenses:
67
143
  - BSD
@@ -89,7 +165,8 @@ rubyforge_project:
89
165
  rubygems_version: 2.4.8
90
166
  signing_key:
91
167
  specification_version: 4
92
- summary: SixArm.com » Ruby » XID excellent identifier
168
+ summary: 'SixArm.com » Ruby » XID: Xeno Identifier'
93
169
  test_files:
94
170
  - test/sixarm_ruby_xid_test.rb
171
+ - test/sixarm_ruby_xid_test/xid_test.rb
95
172
  has_rdoc: true
metadata.gz.sig CHANGED
Binary file
data/.gemtest DELETED
File without changes
data/CHANGES.md DELETED
@@ -1,13 +0,0 @@
1
- # Changes
2
-
3
- * 2015-07-07 3.4.1 Update gemspec to use file manifest
4
- * 2015-04-01 3.4.0 Add XID.parse and XID.valid?
5
- * 2015-02-12 3.3.0 Add XID.digest(s)
6
- * 2015-02-12 3.2.0 Add XID.new(s) to initialize with a given string.
7
- * 2015-02-12 3.1.0 Add #digest.
8
- * 2015-02-11 3.0.0 Upgrade to XID.
9
- * 2013-08-20 2.1.0 Add #next to enable using this as an enumeration.
10
- * 2013-08-18 2.0.0 Upgrade for Ruby 2.0.0; add .length and .choices methods.
11
- * 2012-03-21 1.4.0 Upgrade for Ruby 1.9.3, minitest/spec, and improved docs.
12
- * 2011-04-22 1.3.0 Update to 32 characters
13
- * 2011-04-21 1.2.2 End support for Ruby 1.8.6
data/CONTRIBUTING.md DELETED
@@ -1,28 +0,0 @@
1
- # Contributing
2
-
3
- Thank you for contributing!
4
-
5
- If you would like to contribute a donation, an easy way is to use PayPal to sixarm@sixarm.com.
6
-
7
- If you would like to contribute help, the next section is for you.
8
-
9
-
10
- ## Contributing to the source
11
-
12
- We love pull requests for improvments to the source code and documentation.
13
-
14
- There are three easy steps:
15
-
16
- 1. Fork the repo.
17
-
18
- * Before you do any work please run our existing tests to make sure the code runs cleanly.
19
-
20
- 2. Work as you like.
21
-
22
- * Please create tests. This helps us know that all your code runs cleanly.
23
-
24
- 3. Push to your fork and submit a pull request.
25
-
26
- * We'll take a look as soon as we can; this is typically within a business day.
27
-
28
- Thank you again!
data/LICENSE.md DELETED
@@ -1,28 +0,0 @@
1
- # License
2
-
3
- You may choose any of these open source licenses:
4
-
5
- * Apache License
6
- * BSD License
7
- * CreativeCommons License, Non-commercial Share Alike
8
- * GNU Affero General Public License (AGPL)
9
- * GNU General Public License Version (GPL)
10
- * GNU Lesser General Public License (LGPL)
11
- * MIT License
12
- * Perl Artistic License
13
- * Ruby License
14
-
15
- The software is provided "as is", without warranty of any kind,
16
- express or implied, including but not limited to the warranties of
17
- merchantability, fitness for a particular purpose and noninfringement.
18
-
19
- In no event shall the authors or copyright holders be liable for any
20
- claim, damages or other liability, whether in an action of contract,
21
- tort or otherwise, arising from, out of or in connection with the
22
- software or the use or other dealings in the software.
23
-
24
- This license is for the included software that is created by SixArm.
25
- Some of the included software may have its own licenses, copyrights,
26
- authors, etc. and these may take precedence over the SixArm license.
27
-
28
- Copyright (c) Joel Parker Henderson
data/README.md DELETED
@@ -1,124 +0,0 @@
1
- # SixArm.com » Ruby » <br> XID excellent identifier
2
-
3
- [![Code Climate](https://codeclimate.com/github/SixArm/sixarm_ruby_xid.png)](https://codeclimate.com/github/SixArm/sixarm_ruby_xid)
4
- [![Build Status](https://travis-ci.org/SixArm/sixarm_ruby_xid.png)](https://travis-ci.org/SixArm/sixarm_ruby_xid)
5
-
6
- * Doc: <http://sixarm.com/sixarm_ruby_xid/doc>
7
- * Gem: <http://rubygems.org/gems/sixarm_ruby_xid>
8
- * Repo: <http://github.com/sixarm/sixarm_ruby_xid>
9
- * Email: Joel Parker Henderson, <joel@sixarm.com>
10
-
11
-
12
- ## Introduction
13
-
14
- XID is an excellent identifier. The XID much like a UUID (Universally Unique Identifier) or GUID (Globally Unique Identifer).
15
-
16
- Example:
17
-
18
- XID.new
19
- #=> "90f44e35a062479289ff75ab2abc0ed3"
20
-
21
- What makes the XID excellent: a streamlined specfication, stronger security, speedier algorithms, and simple string comparisons.
22
-
23
- XID specification:
24
-
25
- * 128 bit.
26
- * Completely random and generated with a secure random generator.
27
- * The string representation is entirely hexidecimal: digits 0-9 and lowercase a-f.
28
-
29
- For docs go to <http://sixarm.com/sixarm_ruby_xid/doc>
30
-
31
- Want to help? We're happy to get pull requests.
32
-
33
-
34
- ## Install quickstart
35
-
36
- Install:
37
-
38
- gem install sixarm_ruby_xid
39
-
40
- Bundler:
41
-
42
- gem "sixarm_ruby_xid", ">=3.4.0", "<4"
43
-
44
- Require:
45
-
46
- require "sixarm_ruby_xid"
47
-
48
-
49
- ## Install with security (optional)
50
-
51
- To enable high security for all our gems:
52
-
53
- wget http://sixarm.com/sixarm.pem
54
- gem cert --add sixarm.pem
55
- gem sources --add http://sixarm.com
56
-
57
- To install with high security:
58
-
59
- gem install sixarm_ruby_xid --trust-policy HighSecurity
60
-
61
-
62
- ## Details
63
-
64
- Methods:
65
-
66
- * `XID.new`: create an XID and initialize to a random string.
67
- * `XID.new(s)`: create an XID and initialize to a given string.
68
- * `XID.valid?`: is this XIDa valid, i.e. the correct format?
69
- * `XID#valid?(s)`: is a string a valid XID, i.e. the correct format?
70
- * `XID#digest`: return a SHA256 digest as a 64-character string.
71
- * `XID.digest(s)`: return a SHA256 digest as a 64-character string.
72
- * `XID.parse(s)`: parse any string with enough data to a new XID.
73
-
74
- Notes:
75
-
76
- * XID uses Ruby's SecureRandom methods for strong security.
77
- * An XID is a Ruby string, so you can do any string methods on it.
78
-
79
-
80
- ## UUID comparison
81
-
82
- The XID is much like a UUID:
83
-
84
- * The XID and UUID are both 128 bit.
85
- * The XID has one form. The UUID has multiple forms, known as variants and versions.
86
- * The XID is completely random. The UUID may have non-random pieces, such as a MAC sequence, and a fixed bit for the variant and version.
87
- * The XID specification requires the use of a secure random generator. The UUID has no guarantee, and some forms use predicatable sequences.
88
- * The XID uses digits 0-9 and lowecase a-f. The UUID canoncical form uses dashes to separate sequencies, and may use uppercase or lowercase.
89
-
90
- To format an XID in the style of a UUID canonical representation:
91
-
92
- xid = "90f44e35a062479289ff75ab2abc0ed3"
93
- xid.sub(/(.{8})(.{4})(.{4})(.{16})/,"#$1-#$2-#$3-#$4")
94
- #=> "90f44e35-a062-4792-89ff75ab2abc0ed3"
95
-
96
- Note: the result string is formatted like a UUID, but is not guaranteed to be valid UUID. This is because the XID is random, whereas the UUID specification requires a specific bit that indicates the UUID is random.
97
-
98
- To format a UUID in the style of an XID:
99
-
100
- uuid = "14fFE137-2DB2-4A37-A2A4-A04DB1C756CA"
101
- uuid.gsub(/-/,"").downcase
102
- #=> ""14f7e1372db24a37a2a4a04db1c756ca"
103
-
104
- Note: the result string is formatted like a XID, but is not a valid XID. This is because there's no guarantee that the UUID was randomly generated using a secure random generator, and also because the UUID-4 specification requires a random UUID to set the third section's first digit to 4.
105
-
106
-
107
- ## Unix tooling
108
-
109
- To generate an XID on a typical Unix system, one way is the hexdump command:
110
-
111
- $ hexdump -n 16 -v -e '16/1 "%02x" "\n"' /dev/random
112
- b29dd48b7040f788fd926ebf1f4eddd0
113
-
114
- To digest an XID by using SHA256:
115
-
116
- $ echo -n "b29dd48b7040f788fd926ebf1f4eddd0" | shasum -a 256
117
- afdfb0400e479285040e541ee87d9227d5731a7232ecfa5a07074ee0ad171c64
118
-
119
-
120
- ## Database tooling
121
-
122
- To store an XID in a database, one way is using a string field that is 32 characters long.
123
-
124
- Some databases have specialize fields for 128 bit values, such as PostgreSQL and its UUID extensions. PostgreSQL states that a UUID field will accept a string that is lowercase and that omits dashes. PostgreSQL does not do any validity-checking on the UUID value. Thus it is viable to store an XID in a UUID field. Our team has a goal to create a PostgreSQL extension for the XID data type.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 3.4.1