base32-url 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +5 -5
- data/lib/base32/url.rb +6 -6
- data/lib/base32/version.rb +1 -1
- data/test/test_base32_url.rb +6 -6
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1905c3d866b4e3ce2f810b3a5c918c8ac20bdb2ae6e91a8ae8b6c2e366540274
|
4
|
+
data.tar.gz: effb748c3d55a28017ab77ff8b8f01803621fb617d247505d6c5c824b892921a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10c13658735a6d31812e4e9c60b33f125dbf466fc8d37367e6aa3469b1da22bcffbecddfbec325b379131a7337fb79c924b19788365ae109050f254dd2dd0e9e
|
7
|
+
data.tar.gz: 5333b4899d6ed9a0bdcf0ac008973daf36955ef5a6fa9877f86395504d86d05e4e392da42c887d6671d6905cb44f857cf5b5f0e5e184ff80a38c7541c792d399
|
data/README.md
CHANGED
@@ -29,8 +29,8 @@ $ gem install base32-url
|
|
29
29
|
|
30
30
|
require 'base32/url'
|
31
31
|
|
32
|
-
Base32::
|
33
|
-
Base32::
|
34
|
-
Base32::
|
35
|
-
Base32::
|
36
|
-
Base32::
|
32
|
+
Base32::URL.encode(1234) # => "16j"
|
33
|
+
Base32::URL.encode(100**10, :split=>5, :length=>15) # => "02pqh-ty5nh-h0000"
|
34
|
+
Base32::URL.decode("2pqh-ty5nh-hoooo") # => 10**100
|
35
|
+
Base32::URL.encode(1234, checksum: true) # => "16jd"
|
36
|
+
Base32::URL.decode("16jd", checksum: true) # => 1234
|
data/lib/base32/url.rb
CHANGED
@@ -48,15 +48,15 @@ class Base32::URL
|
|
48
48
|
h[c] = i; h
|
49
49
|
end.merge({'i' => 1, 'l' => 1, 'o' => 0})
|
50
50
|
|
51
|
-
CHECKSUM_CHARS = %w(
|
51
|
+
CHECKSUM_CHARS = %w(i l o u)
|
52
52
|
|
53
|
-
CHECKSUM_MAP = { "
|
53
|
+
CHECKSUM_MAP = { "i" => 32, "l" => 33, "o" => 34, "u" => 35 }
|
54
54
|
|
55
55
|
# encodes an integer into a string
|
56
56
|
#
|
57
57
|
# when +checksum+ is given, a checksum is added at the end of the the string,
|
58
|
-
# calculated as modulo
|
59
|
-
# used for symbol values 32-
|
58
|
+
# calculated as modulo 36 of +number+. Four additional checksum symbols are
|
59
|
+
# used for symbol values 32-35
|
60
60
|
#
|
61
61
|
# when +split+ is given a hyphen is inserted every <n> characters to improve
|
62
62
|
# readability
|
@@ -75,7 +75,7 @@ class Base32::URL
|
|
75
75
|
ENCODE_CHARS[bits.reverse.to_i(2)]
|
76
76
|
end.reverse.join
|
77
77
|
|
78
|
-
str += (ENCODE_CHARS + CHECKSUM_CHARS)[number %
|
78
|
+
str += (ENCODE_CHARS + CHECKSUM_CHARS)[number % 36] if opts[:checksum]
|
79
79
|
|
80
80
|
str = str.rjust(opts[:length], '0') if opts[:length]
|
81
81
|
|
@@ -113,7 +113,7 @@ class Base32::URL
|
|
113
113
|
DECODE_MAP[char] or return nil
|
114
114
|
}.inject(0) { |result,val| (result << 5) + val }
|
115
115
|
|
116
|
-
return nil if opts[:checksum] && (number %
|
116
|
+
return nil if opts[:checksum] && (number % 36 != checksum_number)
|
117
117
|
|
118
118
|
number
|
119
119
|
end
|
data/lib/base32/version.rb
CHANGED
data/test/test_base32_url.rb
CHANGED
@@ -73,21 +73,21 @@ class TestBase32Url < Test::Unit::TestCase
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def test_encoding_checksum
|
76
|
-
assert_equal "
|
76
|
+
assert_equal "16ja",
|
77
77
|
Base32::URL.encode(1234, :checksum => true)
|
78
|
-
assert_equal "
|
78
|
+
assert_equal "016ja",
|
79
79
|
Base32::URL.encode(1234, :length => 5, :checksum => true)
|
80
|
-
assert_equal "0-16-
|
80
|
+
assert_equal "0-16-ja",
|
81
81
|
Base32::URL.encode(1234, :length => 5, :split => 2, :checksum => true)
|
82
82
|
end
|
83
83
|
|
84
84
|
def test_decoding_checksum
|
85
85
|
assert_equal 1234,
|
86
|
-
Base32::URL.decode("
|
86
|
+
Base32::URL.decode("16ja", :checksum => true)
|
87
87
|
assert_equal 1234,
|
88
|
-
Base32::URL.decode("
|
88
|
+
Base32::URL.decode("016ja", :length => 5, :checksum => true)
|
89
89
|
assert_equal 1234,
|
90
|
-
Base32::URL.decode("0-16-
|
90
|
+
Base32::URL.decode("0-16-ja", :length => 5, :split => 2, :checksum => true)
|
91
91
|
end
|
92
92
|
|
93
93
|
def test_decoding_invalid_checksum
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base32-url
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Fenner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -91,9 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
93
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
94
|
+
rubygems_version: 2.7.4
|
95
95
|
signing_key:
|
96
96
|
specification_version: 4
|
97
97
|
summary: Ruby client library for conversion of DOI Metadata
|
98
|
-
test_files:
|
99
|
-
- test/test_base32_url.rb
|
98
|
+
test_files: []
|