crockford32 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6e7d5926825497887afa8a356c29d3d858c8fd77c8885b926899b69e110b5d2
4
- data.tar.gz: 1d012996acd856eed31ec4aa096c6f1c2ee193b2df081138670201546811363d
3
+ metadata.gz: b2f3c133e3c624b9664a506fc2d8a9b4637d7316ce4e22d288f1c7a989ae2dc9
4
+ data.tar.gz: 99218eed8df26f78d663e6126e6a0f2579e7d7abbed00934bb17af668881561c
5
5
  SHA512:
6
- metadata.gz: 4027fea38aa6aeb2f627e203d09345afd53a0e7120a25aec1d52ac5b1a1d0e626a8c37a02677a8eb47d5bed0b45db3264f2c4e33a6d7175bddd9b0e09e0efafa
7
- data.tar.gz: 7af4989d8267bef92f06347af2bdd8cfaa668bf15c4e142111549939bcd4b8b4fa97c845d7cc29e23d48a8c386734600858689d02877e84c9bef3e3712277ac6
6
+ metadata.gz: cfae960c489f647dd841ee981c2a414c2b92283be33519d125b65382f3e8f7bc818cad6a2dde442fbb2c7f6caf913b50d7d78567ea1aaba46d956b0f9f707320
7
+ data.tar.gz: 211e81e821b28cab1f6a84a698687a0c11d82a53de529e44708cd51d8f574b1c01c848246a5bf798364cd2ba4c62e54eb1ad9b5f3fd225be80fd3987c87842c8
data/CHANGELOG.md CHANGED
@@ -1,4 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.1.0 - 2022-03-08
4
+ - Add `length:` parameter to `Crockford32.decode` to support padding to a given length after decoding into a string.
5
+
6
+ ## v1.0.2 - 2022-02-22
7
+ - Add type definitions
8
+
9
+ ## v1.0.1 - 2022-02-19
10
+ - Fixed `TypeError` in `private_class_method` call in Ruby < 3.0.0
11
+
3
12
  ## v1.0.0 - 2022-02-19
4
13
  - Initial release
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2022 Stephan Tarulli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,6 +1,21 @@
1
1
  # Crockford32
2
2
  A fast little-endian implementation of [Douglas Crockford's Base32 specification](https://www.crockford.com/base32.html).
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/crockford32.svg)](https://badge.fury.io/rb/crockford32)
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
+
4
19
 
5
20
  ## Installation
6
21
  Add this line to your application's Gemfile:
@@ -17,6 +32,18 @@ Or install it yourself as:
17
32
 
18
33
  $ gem install crockford32
19
34
 
35
+ ### Ruby Versions
36
+ This gem is tested against the following Ruby versions:
37
+
38
+ - 2.6.0
39
+ - 2.6.9
40
+ - 2.7.0
41
+ - 2.7.5
42
+ - 3.0.0
43
+ - 3.0.3
44
+ - 3.1.0
45
+ - 3.1.1
46
+
20
47
 
21
48
  ## Usage
22
49
  Encode data with the `encode` method:
@@ -93,17 +120,21 @@ This library _always_ uses little-endian.
93
120
  For more detailed information about the library [see the API documentation](https://tinychameleon.github.io/crockford32/).
94
121
 
95
122
 
96
- ## Development
123
+ ## Contributing
124
+
125
+ ### Development
97
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.
98
127
 
99
128
  For an interactive console with the gem loaded run `bin/console`.
100
129
 
101
130
 
102
- ## Testing
131
+ ### Testing
103
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`.
104
133
 
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.
135
+
105
136
 
106
- ## Releases
137
+ ### Releasing
107
138
  Do the following to release a new version of this gem:
108
139
 
109
140
  - Update the version number in [lib/crockford32/version.rb](./lib/crockford32/version.rb)
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Crockford32
4
4
  # The library version.
5
- VERSION = "1.0.0"
5
+ VERSION = "1.1.0"
6
6
  end
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
- bytes.pack("C*")
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.
@@ -226,8 +233,8 @@ module Crockford32
226
233
  result.freeze
227
234
  end
228
235
 
229
- private_class_method [:le_decode_number, :convert, :into_string, :raw_value_to_number,
230
- :string_to_integer, :string_to_integer_unrolled, :le_encode_number]
236
+ private_class_method :le_decode_number, :convert, :into_string, :raw_value_to_number,
237
+ :string_to_integer, :string_to_integer_unrolled, :le_encode_number
231
238
 
232
239
  # @!endgroup
233
240
  end
@@ -0,0 +1,9 @@
1
+ module Crockford32
2
+ VERSION: String
3
+
4
+ type encodable = Integer | String
5
+ type decode_into = :integer | :string
6
+
7
+ def self.decode: (String, ?into: decode_into, ?check: bool) -> encodable
8
+ def self.encode: (encodable, ?length: Integer, ?check: bool) -> String
9
+ end
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.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-02-20 00:00:00.000000000 Z
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:
@@ -17,20 +17,16 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - ".standard.yml"
21
20
  - CHANGELOG.md
22
- - Gemfile
23
- - Gemfile.lock
21
+ - LICENSE
24
22
  - README.md
25
- - Rakefile
26
- - bin/console
27
- - bin/setup
28
- - crockford32.gemspec
29
23
  - lib/crockford32.rb
30
24
  - lib/crockford32/errors.rb
31
25
  - lib/crockford32/version.rb
26
+ - sig/crockford32.rbs
32
27
  homepage: https://github.com/tinychameleon/crockford32
33
- licenses: []
28
+ licenses:
29
+ - MIT
34
30
  metadata:
35
31
  homepage_uri: https://github.com/tinychameleon/crockford32
36
32
  source_code_uri: https://github.com/tinychameleon/crockford32
data/.standard.yml DELETED
@@ -1,2 +0,0 @@
1
- # For available configuration options, see:
2
- # https://github.com/testdouble/standard
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gemspec
6
-
7
- gem "rake", "~> 13.0"
8
- gem "minitest", "~> 5.0"
9
- gem "benchmark-ips", "~> 2.10"
10
- gem "debug", "~> 1.4"
11
- gem "standard", "~> 1.3"
12
- gem "yard", "~> 0.9.27"
data/Gemfile.lock DELETED
@@ -1,63 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- crockford32 (1.0.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- ast (2.4.2)
10
- benchmark-ips (2.10.0)
11
- debug (1.4.0)
12
- irb (>= 1.3.6)
13
- reline (>= 0.2.7)
14
- io-console (0.5.11)
15
- irb (1.4.1)
16
- reline (>= 0.3.0)
17
- minitest (5.15.0)
18
- parallel (1.21.0)
19
- parser (3.1.0.0)
20
- ast (~> 2.4.1)
21
- rainbow (3.1.1)
22
- rake (13.0.6)
23
- regexp_parser (2.2.1)
24
- reline (0.3.1)
25
- io-console (~> 0.5)
26
- rexml (3.2.5)
27
- rubocop (1.25.1)
28
- parallel (~> 1.10)
29
- parser (>= 3.1.0.0)
30
- rainbow (>= 2.2.2, < 4.0)
31
- regexp_parser (>= 1.8, < 3.0)
32
- rexml
33
- rubocop-ast (>= 1.15.1, < 2.0)
34
- ruby-progressbar (~> 1.7)
35
- unicode-display_width (>= 1.4.0, < 3.0)
36
- rubocop-ast (1.15.2)
37
- parser (>= 3.0.1.1)
38
- rubocop-performance (1.13.2)
39
- rubocop (>= 1.7.0, < 2.0)
40
- rubocop-ast (>= 0.4.0)
41
- ruby-progressbar (1.11.0)
42
- standard (1.7.2)
43
- rubocop (= 1.25.1)
44
- rubocop-performance (= 1.13.2)
45
- unicode-display_width (2.1.0)
46
- webrick (1.7.0)
47
- yard (0.9.27)
48
- webrick (~> 1.7.0)
49
-
50
- PLATFORMS
51
- x86_64-darwin-19
52
-
53
- DEPENDENCIES
54
- benchmark-ips (~> 2.10)
55
- crockford32!
56
- debug (~> 1.4)
57
- minitest (~> 5.0)
58
- rake (~> 13.0)
59
- standard (~> 1.3)
60
- yard (~> 0.9.27)
61
-
62
- BUNDLED WITH
63
- 2.3.3
data/Rakefile DELETED
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
- require "standard/rake"
6
- require "yard"
7
-
8
- Rake::TestTask.new(:test) do |t|
9
- t.libs << "test"
10
- t.libs << "lib"
11
- t.test_files = FileList["test/**/test_*.rb"]
12
- end
13
-
14
- YARD::Rake::YardocTask.new do |t|
15
- t.files = ["lib/**/*.rb", "-", "CHANGELOG.md"]
16
- t.options = ["--private", "-o", "./docs"]
17
- end
18
-
19
- task default: %i[test standard]
20
-
21
- desc "Benchmark the current implementation"
22
- task benchmark: [] do |t|
23
- sh "date; ruby test/benchmarks/current.rb"
24
- end
data/bin/console DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "crockford32"
6
-
7
- require "irb"
8
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
-
4
- bundle install
5
- bundle exec rake test standard
data/crockford32.gemspec DELETED
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/crockford32/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "crockford32"
7
- spec.version = Crockford32::VERSION
8
- spec.authors = ["Stephan Tarulli"]
9
- spec.email = ["srt@tinychameleon.com"]
10
-
11
- spec.summary = "A fast little-endian implementation of Crockford's Base32 specification."
12
- spec.description = "A fast little-endian implementation of Crockford's Base32 specification."
13
- spec.homepage = "https://github.com/tinychameleon/crockford32"
14
- spec.required_ruby_version = ">= 2.6.0"
15
-
16
- spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = spec.homepage
18
- spec.metadata["changelog_uri"] = File.join(spec.homepage, "blob/main/CHANGELOG.md")
19
- spec.metadata["bug_tracker_uri"] = File.join(spec.homepage, "issues")
20
- spec.metadata["documentation_uri"] = "https://tinychameleon.github.io/crockford32/"
21
-
22
- # Specify which files should be added to the gem when it is released.
23
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
- `git ls-files -z`.split("\x0").reject do |f|
26
- (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
- end
28
- end
29
- spec.bindir = "exe"
30
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
32
-
33
- # Uncomment to register a new dependency of your gem
34
- # spec.add_dependency "example-gem", "~> 1.0"
35
-
36
- # For more information and examples about making a new gem, check out our
37
- # guide at: https://bundler.io/guides/creating_gem.html
38
- end