base32 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/base32.rb +2 -2
- data/lib/version.rb +1 -1
- data/test/base32_test.rb +8 -0
- metadata +2 -2
data/lib/base32.rb
CHANGED
@@ -44,12 +44,12 @@ module Base32
|
|
44
44
|
chunks(str, 8).collect(&:decode).flatten.join
|
45
45
|
end
|
46
46
|
|
47
|
-
def self.random_base32(length=16)
|
47
|
+
def self.random_base32(length=16, padding=true)
|
48
48
|
random = ''
|
49
49
|
OpenSSL::Random.random_bytes(length).each_byte do |b|
|
50
50
|
random << self.table[b % 32]
|
51
51
|
end
|
52
|
-
random.ljust((length / 8.0).ceil * 8, '=')
|
52
|
+
padding ? random.ljust((length / 8.0).ceil * 8, '=') : random
|
53
53
|
end
|
54
54
|
|
55
55
|
def self.table=(table)
|
data/lib/version.rb
CHANGED
data/test/base32_test.rb
CHANGED
@@ -84,6 +84,14 @@ class TestBase32 < Minitest::Test
|
|
84
84
|
assert_match(/^[A-Z2-7]{29}={3}$/, Base32.random_base32(29))
|
85
85
|
end
|
86
86
|
|
87
|
+
def test_random_base32_padding
|
88
|
+
assert_equal(32, Base32.random_base32(32, false).length)
|
89
|
+
assert_equal(40, Base32.random_base32(40, false).length)
|
90
|
+
assert_equal(29, Base32.random_base32(29, false).length)
|
91
|
+
assert_match(/^[A-Z2-7]{1}$/, Base32.random_base32(1, false))
|
92
|
+
assert_match(/^[A-Z2-7]{29}$/, Base32.random_base32(29, false))
|
93
|
+
end
|
94
|
+
|
87
95
|
def test_assign_new_table
|
88
96
|
new_table = 'abcdefghijklmnopqrstuvwxyz234567'
|
89
97
|
Base32.table = new_table
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base32
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-02-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|