crockford32 1.0.2 → 1.1.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/CHANGELOG.md +3 -0
- data/README.md +20 -3
- data/lib/crockford32/version.rb +1 -1
- data/lib/crockford32.rb +13 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2f3c133e3c624b9664a506fc2d8a9b4637d7316ce4e22d288f1c7a989ae2dc9
|
4
|
+
data.tar.gz: 99218eed8df26f78d663e6126e6a0f2579e7d7abbed00934bb17af668881561c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfae960c489f647dd841ee981c2a414c2b92283be33519d125b65382f3e8f7bc818cad6a2dde442fbb2c7f6caf913b50d7d78567ea1aaba46d956b0f9f707320
|
7
|
+
data.tar.gz: 211e81e821b28cab1f6a84a698687a0c11d82a53de529e44708cd51d8f574b1c01c848246a5bf798364cd2ba4c62e54eb1ad9b5f3fd225be80fd3987c87842c8
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,20 @@ A fast little-endian implementation of [Douglas Crockford's Base32 specification
|
|
3
3
|
|
4
4
|
[](https://badge.fury.io/rb/crockford32)
|
5
5
|
|
6
|
+
## What's in the box?
|
7
|
+
✅ Simple usage documentation written to get started fast. [Check it out!](#usage)
|
8
|
+
|
9
|
+
⚡ A pretty fast implementation of Crockford32 in pure ruby. [Check it out!](#benchmarks)
|
10
|
+
|
11
|
+
📚 YARD generated API documentation for the library. [Check it out!](https://tinychameleon.github.io/crockford32/)
|
12
|
+
|
13
|
+
🤖 RBS types for your type checking wants. [Check it out!](./sig/crockford32.rbs)
|
14
|
+
|
15
|
+
💎 Tests against many Ruby versions. [Check it out!](#ruby-versions)
|
16
|
+
|
17
|
+
🔒 MFA protection on all gem owners. [Check it out!](https://rubygems.org/gems/crockford32)
|
18
|
+
|
19
|
+
|
6
20
|
## Installation
|
7
21
|
Add this line to your application's Gemfile:
|
8
22
|
|
@@ -28,6 +42,7 @@ This gem is tested against the following Ruby versions:
|
|
28
42
|
- 3.0.0
|
29
43
|
- 3.0.3
|
30
44
|
- 3.1.0
|
45
|
+
- 3.1.1
|
31
46
|
|
32
47
|
|
33
48
|
## Usage
|
@@ -105,19 +120,21 @@ This library _always_ uses little-endian.
|
|
105
120
|
For more detailed information about the library [see the API documentation](https://tinychameleon.github.io/crockford32/).
|
106
121
|
|
107
122
|
|
108
|
-
##
|
123
|
+
## Contributing
|
124
|
+
|
125
|
+
### Development
|
109
126
|
To get started development on this gem run the `bin/setup` command. This will install dependencies and run the tests and linting tasks to ensure everything is working.
|
110
127
|
|
111
128
|
For an interactive console with the gem loaded run `bin/console`.
|
112
129
|
|
113
130
|
|
114
|
-
|
131
|
+
### Testing
|
115
132
|
Use the `bundle exec rake test` command to run unit tests. To install the gem onto your local machine for general integration testing use `bundle exec rake install`.
|
116
133
|
|
117
134
|
To test the gem against each supported version of Ruby use `bin/test_versions`. This will create a Docker image for each version and run the tests and linting steps.
|
118
135
|
|
119
136
|
|
120
|
-
|
137
|
+
### Releasing
|
121
138
|
Do the following to release a new version of this gem:
|
122
139
|
|
123
140
|
- Update the version number in [lib/crockford32/version.rb](./lib/crockford32/version.rb)
|
data/lib/crockford32/version.rb
CHANGED
data/lib/crockford32.rb
CHANGED
@@ -54,6 +54,7 @@ module Crockford32
|
|
54
54
|
# @param value [String] the Base32 value to decode.
|
55
55
|
# @param into [Symbol] the destination type to decode into. Can be +:integer+ or +:string+.
|
56
56
|
# @param check [Boolean] whether to validate the check symbol.
|
57
|
+
# @param length [Integer, nil] the length of the resulting string when right padded.
|
57
58
|
#
|
58
59
|
# @return [Integer, String] the decoded value.
|
59
60
|
#
|
@@ -61,7 +62,7 @@ module Crockford32
|
|
61
62
|
# @raise [InvalidCharacterError] when the value being decoded has a character outside the
|
62
63
|
# Base32 symbol set or a misplaced check symbol.
|
63
64
|
# @raise [UnsupportedDecodingTypeError] when the requested +into:+ type is not supported.
|
64
|
-
def self.decode(value, into: :integer, check: false)
|
65
|
+
def self.decode(value, into: :integer, check: false, length: nil)
|
65
66
|
checksum = check ? value[-1] : nil
|
66
67
|
value = check ? value[0...-1] : value
|
67
68
|
|
@@ -73,7 +74,7 @@ module Crockford32
|
|
73
74
|
raise ChecksumError.new(value, actual, required) if actual != required
|
74
75
|
end
|
75
76
|
|
76
|
-
convert result, into
|
77
|
+
convert result, into, length
|
77
78
|
end
|
78
79
|
|
79
80
|
# Encode a value as Base32.
|
@@ -118,13 +119,14 @@ module Crockford32
|
|
118
119
|
#
|
119
120
|
# @param result [Integer] the decoded value.
|
120
121
|
# @param type [Symbol] the destination type for the value. Can be +:integer+ or +:string+.
|
122
|
+
# @param length [Integer, nil] the length to pad the string to.
|
121
123
|
# @return [Integer, String] the decoded value converted to the destination type.
|
122
|
-
def self.convert(result, type)
|
124
|
+
def self.convert(result, type, length)
|
123
125
|
case type
|
124
126
|
when :integer
|
125
127
|
result
|
126
128
|
when :string
|
127
|
-
into_string result
|
129
|
+
into_string result, length
|
128
130
|
else
|
129
131
|
raise UnsupportedDecodingTypeError.new(type)
|
130
132
|
end
|
@@ -135,8 +137,9 @@ module Crockford32
|
|
135
137
|
# Each 8-bit sequence is packed into a String in little-endian order.
|
136
138
|
#
|
137
139
|
# @param result [Integer] the decoded value.
|
140
|
+
# @param length [Integer, nil] the length of the decoded value with right padding.
|
138
141
|
# @return [String] the decoded value as a String.
|
139
|
-
def self.into_string(result)
|
142
|
+
def self.into_string(result, length)
|
140
143
|
q, r = result.bit_length.divmod(0x08)
|
141
144
|
q += 1 if r > 0
|
142
145
|
bytes = Array.new(q)
|
@@ -144,7 +147,11 @@ module Crockford32
|
|
144
147
|
bytes[i] = result & 0xff
|
145
148
|
result >>= 0x08
|
146
149
|
end
|
147
|
-
|
150
|
+
|
151
|
+
bstr = bytes.pack("C*")
|
152
|
+
return bstr if length.nil?
|
153
|
+
|
154
|
+
bstr.ljust(length, "\x00")
|
148
155
|
end
|
149
156
|
|
150
157
|
# Convert a raw value into an Integer for encoding.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crockford32
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephan Tarulli
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A fast little-endian implementation of Crockford's Base32 specification.
|
14
14
|
email:
|