sixarm_ruby_xid 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +64 -19
- data/lib/sixarm_ruby_xid.rb +5 -0
- data/test/sixarm_ruby_xid_test.rb +12 -3
- data.tar.gz.sig +0 -0
- metadata +5 -5
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a6cd306d753aa53345165bc0fe03abdb5f32038
|
4
|
+
data.tar.gz: 2ddb1e1f1c2d577434669f2d2b1f5c77b36b018e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d2072630d29de5205328f7e571a7f5dce56a47b85b001da782f8faaeaf75bca1bfe5366dbfe878b2dab033447f02c0326d0221f1aba8d2275231900b4825122
|
7
|
+
data.tar.gz: 04e1403dc19e8065b7dd6c237619cbed0ef7714f4db1aaaeed900a8b3cd7b72601aef4870bb4c4fb356038c35838738de34aca3fdff3994704e87a30fcef7064
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# SixArm.com » Ruby » <br>
|
1
|
+
# SixArm.com » Ruby » <br> XID excellent identifier
|
2
2
|
|
3
3
|
[![Code Climate](https://codeclimate.com/github/SixArm/xid.png)](https://codeclimate.com/github/SixArm/xid)
|
4
4
|
[![Build Status](https://travis-ci.org/SixArm/xid.png)](https://travis-ci.org/SixArm/xid)
|
@@ -11,28 +11,20 @@
|
|
11
11
|
|
12
12
|
## Introduction
|
13
13
|
|
14
|
-
XID is
|
15
|
-
|
16
|
-
XID specification:
|
17
|
-
|
18
|
-
* 128 bit.
|
19
|
-
* Completely random.
|
20
|
-
* Generated with a secure random generator.
|
21
|
-
* The string representation is entirely hexidecimal: digits 0-9 and lowercase a-f.
|
22
|
-
|
23
|
-
Comparison with UUID:
|
24
|
-
|
25
|
-
* The XID and UUID are both 128 bit.
|
26
|
-
* The XID has one form. The UUID has multiple forms, called variants and versions.
|
27
|
-
* 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.
|
28
|
-
* The XID specification requires the use of a secure random generator. The UUID has no guarantee.
|
29
|
-
* The XID uses digits 0-9 and lowecase a-f. The UUID canoncical form uses dashes to separate sequencies, and can use uppercase or lowercase.
|
14
|
+
XID is an excellent identifier. The XID much like a UUID (Universally Unique Identifier) or GUID (Globally Unique Identifer).
|
30
15
|
|
31
16
|
Example:
|
32
17
|
|
33
18
|
XID.new
|
34
19
|
#=> "90f44e35a062479289ff75ab2abc0ed3"
|
35
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.
|
36
28
|
|
37
29
|
For docs go to <http://sixarm.com/sixarm_ruby_xid/doc>
|
38
30
|
|
@@ -69,9 +61,62 @@ To install with high security:
|
|
69
61
|
|
70
62
|
## Details
|
71
63
|
|
72
|
-
|
64
|
+
Methods:
|
65
|
+
|
66
|
+
* `XID.new`: generate a new XID string
|
67
|
+
* `XID#digest`: return a SHA256 digest as a 64-character string
|
68
|
+
|
69
|
+
Notes:
|
70
|
+
|
71
|
+
* XID uses Ruby's SecureRandom methods for strong security.
|
72
|
+
* An XID is a Ruby string, so you can do any string methods on it.
|
73
|
+
|
74
|
+
|
75
|
+
## UUID comparison
|
76
|
+
|
77
|
+
The XID is much like a UUID:
|
78
|
+
|
79
|
+
* The XID and UUID are both 128 bit.
|
80
|
+
* The XID has one form. The UUID has multiple forms, known as variants and versions.
|
81
|
+
* 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.
|
82
|
+
* The XID specification requires the use of a secure random generator. The UUID has no guarantee, and some forms use predicatable sequences.
|
83
|
+
* 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.
|
84
|
+
|
85
|
+
To format an XID in the style of a UUID canonical representation:
|
86
|
+
|
87
|
+
xid = "90f44e35a062479289ff75ab2abc0ed3"
|
88
|
+
xid.sub(/(.{8})(.{4})(.{4})(.{16})/,"#$1-#$2-#$3-#$4")
|
89
|
+
#=> "90f44e35-a062-4792-89ff75ab2abc0ed3"
|
90
|
+
|
91
|
+
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.
|
92
|
+
|
93
|
+
To format a UUID in the style of an XID:
|
94
|
+
|
95
|
+
uuid = "14fFE137-2DB2-4A37-A2A4-A04DB1C756CA"
|
96
|
+
uuid.gsub(/-/,"").downcase
|
97
|
+
#=> ""14f7e1372db24a37a2a4a04db1c756ca"
|
98
|
+
|
99
|
+
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.
|
100
|
+
|
101
|
+
|
102
|
+
## Unix tooling
|
103
|
+
|
104
|
+
To generate an XID on a typical Unix system, one way is the hexdump command:
|
105
|
+
|
106
|
+
$ hexdump -n 16 -v -e '16/1 "%02x" "\n"' /dev/random
|
107
|
+
b29dd48b7040f788fd926ebf1f4eddd0
|
108
|
+
|
109
|
+
To digest an XID by using SHA256:
|
110
|
+
|
111
|
+
$ echo -n "b29dd48b7040f788fd926ebf1f4eddd0" | shasum -a 256
|
112
|
+
afdfb0400e479285040e541ee87d9227d5731a7232ecfa5a07074ee0ad171c64
|
113
|
+
|
114
|
+
|
115
|
+
## Database tooling
|
116
|
+
|
117
|
+
To store an XID in a database, one way is using a string field that is 32 characters long.
|
73
118
|
|
74
|
-
|
119
|
+
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.
|
75
120
|
|
76
121
|
|
77
122
|
## Changes
|
data/lib/sixarm_ruby_xid.rb
CHANGED
@@ -4,6 +4,7 @@ Please see README
|
|
4
4
|
=end
|
5
5
|
|
6
6
|
require 'securerandom'
|
7
|
+
require 'digest/sha2'
|
7
8
|
|
8
9
|
class XID < String
|
9
10
|
|
@@ -11,4 +12,8 @@ class XID < String
|
|
11
12
|
super(SecureRandom.hex(16))
|
12
13
|
end
|
13
14
|
|
15
|
+
def digest
|
16
|
+
Digest::SHA256.new.update(self).to_s
|
17
|
+
end
|
18
|
+
|
14
19
|
end
|
@@ -3,7 +3,7 @@ require 'minitest/autorun'
|
|
3
3
|
Minitest::Test ||= MiniTest::Unit::TestCase
|
4
4
|
require 'simplecov'
|
5
5
|
SimpleCov.start
|
6
|
-
require '
|
6
|
+
require 'sixarm_ruby_xid'
|
7
7
|
|
8
8
|
describe XID do
|
9
9
|
|
@@ -11,12 +11,12 @@ describe XID do
|
|
11
11
|
|
12
12
|
it "is a string with the correct length and characters" do
|
13
13
|
xid = XID.new
|
14
|
-
xid.must_match /\A[0-9a-
|
14
|
+
xid.must_match /\A[0-9a-f]{32}\z/
|
15
15
|
end
|
16
16
|
|
17
17
|
it "is always different" do
|
18
18
|
seen = Set.new
|
19
|
-
|
19
|
+
99999.times.each{
|
20
20
|
xid = XID.new
|
21
21
|
seen.include?(xid).must_equal false
|
22
22
|
seen.add(xid)
|
@@ -25,4 +25,13 @@ describe XID do
|
|
25
25
|
|
26
26
|
end
|
27
27
|
|
28
|
+
describe "#digest" do
|
29
|
+
|
30
|
+
it "digests" do
|
31
|
+
xid = XID.new
|
32
|
+
xid.digest.must_match /\A[0-9a-f]{64}\z/
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
28
37
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
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
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SixArm
|
@@ -30,10 +30,10 @@ cert_chain:
|
|
30
30
|
sWRVEyjnjnNuAeLP9zv43IDXjS22L2efhap7IOinYjcecpfXJgQaU+6BFAY4sdkQ
|
31
31
|
S1STYSfs3qySBxxAeEyZTw==
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2015-02-
|
33
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
34
34
|
dependencies: []
|
35
|
-
description: XID
|
36
|
-
|
35
|
+
description: XID generates a new string suitable for security, authentication, tracking,
|
36
|
+
etc.
|
37
37
|
email: sixarm@sixarm.com
|
38
38
|
executables: []
|
39
39
|
extensions: []
|
@@ -73,7 +73,7 @@ rubyforge_project:
|
|
73
73
|
rubygems_version: 2.4.5
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
|
-
summary: SixArm.com » Ruby » XID
|
76
|
+
summary: SixArm.com » Ruby » XID excellent identifier
|
77
77
|
test_files:
|
78
78
|
- test/sixarm_ruby_xid_test.rb
|
79
79
|
has_rdoc: true
|
metadata.gz.sig
CHANGED
Binary file
|