ob64 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d1111a285be1731afda3a4b3040eb9150109a6022eaea13d007004e5d51dcfe
4
- data.tar.gz: e3a298f4286ac95e6656cd0ba0fdebefa1e7f180eec6f4ca0b3f7def4de64122
3
+ metadata.gz: 4697c65d1300ef0e6ec98cd12884ea07b3ab33a2a2b398a2a19ccb02d43d46d6
4
+ data.tar.gz: ce016702f7b2c43c183c43ab87974d74fe8efc56ba1e983e465f66e69f9edba2
5
5
  SHA512:
6
- metadata.gz: b5992c541b3d46c846bb3e22f8e7e01aed89b8a8760ce3ca401263ebfebbd9130cfba69eacee46e288fdba44ed5319ee1086ff55e9e0b0b6791254def2577632
7
- data.tar.gz: 3e77098bab5a772fdab9cf3cc0d987ee18e7a64748dd3fda9bc970cc29b15e48f2fa6b2f24d1ba9b8bb4e41c24bea9fac4041834214d638a17bf0b7c2776fe5b
6
+ metadata.gz: ca030510d227fac302d0dcf723bb78ff43f0e093b164293512d2fe5989fd05c43fb05c10ea5e2bbca5b3f31a8692b144979e80c956da54e03344ce5785c787a8
7
+ data.tar.gz: d9cf2b043bf838add8daec7ef0882ab204b23d35ce1b019a5aa614621fba5c7e83234579ba8b1d3372fd7e9f477a3a2c9af8c7b96a63f78d865a2f1a09e7fbf5
@@ -10,9 +10,25 @@ jobs:
10
10
  ruby: ['2.5', '2.6', '2.7', '3.0']
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
- - uses: actions/checkout@v2
14
- - uses: ruby/setup-ruby@v1
13
+ - name: repository checkout
14
+ uses: actions/checkout@v2
15
+ with:
16
+ submodules: true
17
+
18
+ - name: load ruby
19
+ uses: ruby/setup-ruby@v1
15
20
  with:
16
21
  ruby-version: ${{ matrix.ruby }}
17
- bundler-cache: false
18
- - run: bundle exec rake spec
22
+
23
+ - name: RubyGems, Bundler Update
24
+ run: gem update --system --no-document --conservative
25
+
26
+ - name: bundle install
27
+ run: bundle install --path .bundle/gems --without development
28
+
29
+ - name: compile
30
+ run: bundle exec rake compile
31
+
32
+ - name: test
33
+ run: bundle exec rake spec
34
+ timeout-minutes: 10
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 Joao Fernandes
3
+ Copyright (c) 2021 João Fernandes
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Ob64 gem
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/ob64.svg)](http://rubygems.org/gems/ob64)
4
+ [![Build Status](https://github.com/jcmfernandes/ob64/workflows/Test/badge.svg?branch=master&event=push)](https://github.com/jcmfernandes/ob64/actions?query=workflow:Test)
5
+ [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/ob64/0.1.0)
6
+
3
7
  A *fast* Base64 encoder and decoder as a Ruby gem.
4
8
 
5
9
  How fast? Try it yourself, execute:
@@ -39,7 +43,6 @@ require "ob64"
39
43
 
40
44
  bin1 = "This is data!"
41
45
  string = Ob64.encode(bin1)
42
-
43
46
  # string = "VGhpcyBpcyBkYXRhIQ=="
44
47
 
45
48
  bin2 = Ob64.decode(string)
@@ -82,7 +85,36 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jcmfer
82
85
 
83
86
  ## License
84
87
 
85
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
88
+ Released under the MIT License. See [{file:LICENSE}](LICENSE).
89
+
90
+ Copyright (c) 2021, João Fernandes
91
+
92
+ Permission is hereby granted, free of charge, to any person obtaining a copy
93
+ of this software and associated documentation files (the "Software"), to deal
94
+ in the Software without restriction, including without limitation the rights
95
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
96
+ copies of the Software, and to permit persons to whom the Software is
97
+ furnished to do so, subject to the following conditions:
98
+
99
+ The above copyright notice and this permission notice shall be included in
100
+ all copies or substantial portions of the Software.
101
+
102
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
103
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
104
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
105
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
106
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
107
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
108
+ THE SOFTWARE.
109
+
110
+ ### libbase64
111
+
112
+ Released under the BSD 2-clause License. See [LICENSE](https://github.com/jcmfernandes/base64-cmake/blob/feature/cmake/LICENSE).
113
+
114
+ Copyright (c) 2005-2007, Nick Galbreath
115
+ Copyright (c) 2013-2019, Alfred Klomp
116
+ Copyright (c) 2015-2017, Wojciech Mula
117
+ Copyright (c) 2016-2017, Matthieu Darbois
86
118
 
87
119
  ## Code of Conduct
88
120
 
data/benchmark.rb CHANGED
@@ -4,6 +4,11 @@ require "securerandom"
4
4
  require "ob64"
5
5
  require "base64"
6
6
 
7
+ $run_encode_benchmark = false
8
+ $run_decode_benchmark = false
9
+ $run_urlsafe_encode_benchmark = false
10
+ $run_urlsafe_decode_benchmark = true
11
+
7
12
  def to_size(bytes)
8
13
  bytes >= 2**20 ? "#{bytes / 2**20} MB" : "#{bytes / 2**10} kB"
9
14
  end
@@ -59,7 +64,7 @@ encode_benchmark do
59
64
 
60
65
  x.compare!
61
66
  end
62
- end
67
+ end if $run_encode_benchmark
63
68
 
64
69
  decode_benchmark do
65
70
  Benchmark.ips do |x|
@@ -71,9 +76,43 @@ decode_benchmark do
71
76
  end
72
77
 
73
78
  x.report("ob64 .decode") do
74
- Ob64.encode($encoded)
79
+ Ob64.decode($encoded)
75
80
  end
76
81
 
77
82
  x.compare!
78
83
  end
79
- end
84
+ end if $run_decode_benchmark
85
+
86
+ encode_benchmark do
87
+ Benchmark.ips do |x|
88
+ x.time = 5
89
+ x.warmup = 2
90
+
91
+ x.report("base64 .urlsafe_encode64") do
92
+ Base64.urlsafe_encode64($unencoded)
93
+ end
94
+
95
+ x.report("ob64 .urlsafe_encode") do
96
+ Ob64.urlsafe_encode($unencoded)
97
+ end
98
+
99
+ x.compare!
100
+ end
101
+ end if $run_urlsafe_encode_benchmark
102
+
103
+ decode_benchmark do
104
+ Benchmark.ips do |x|
105
+ x.time = 5
106
+ x.warmup = 2
107
+
108
+ x.report("base64 .urlsafe_decode64") do
109
+ Base64.urlsafe_decode64($encoded)
110
+ end
111
+
112
+ x.report("ob64 .urlsafe_decode") do
113
+ Ob64.urlsafe_decode($encoded)
114
+ end
115
+
116
+ x.compare!
117
+ end
118
+ end if $run_urlsafe_decode_benchmark
data/lib/ob64/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ob64
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/ob64.rb CHANGED
@@ -3,20 +3,45 @@
3
3
  require_relative "ob64/version"
4
4
  require_relative "ob64_ext"
5
5
 
6
+ # Methods for base64-encoding and -decoding strings.
6
7
  module Ob64
7
8
  include LibBase64
8
9
  extend LibBase64
9
10
 
10
11
  module_function
11
12
 
13
+ # Returns the Base64-encoded version of +bin+.
14
+ # This method complies with RFC 4648.
15
+ # No line feeds are added.
16
+ #
17
+ # @param bin [String]
18
+ # @return [String]
12
19
  def encode(bin)
13
20
  __encode(bin)
14
21
  end
15
22
 
23
+ # Returns the Base64-decoded version of +string+.
24
+ # This method complies with RFC 4648.
25
+ # ArgumentError is raised if +string+ is incorrectly padded or contains
26
+ # non-alphabet characters. Note that CR or LF are also rejected.
27
+ #
28
+ # @param string [String]
29
+ # @return [String]
30
+ # @raise [ArgumentError] if +string+ cannot be decoded
16
31
  def decode(string)
17
32
  __decode(string)
18
33
  end
19
34
 
35
+ # Returns the Base64-encoded version of +bin+.
36
+ # This method complies with ``Base 64 Encoding with URL and Filename Safe
37
+ # Alphabet'' in RFC 4648.
38
+ # The alphabet uses '-' instead of '+' and '_' instead of '/'.
39
+ # Note that the result can still contain '='.
40
+ # You can remove the padding by setting +padding+ as false.
41
+ #
42
+ # @param bin [String]
43
+ # @param padding [Boolean] - if the output must be padded
44
+ # @return [String]
20
45
  def urlsafe_encode(bin, padding: true)
21
46
  string = __encode(bin)
22
47
  string.chomp!("==") || string.chomp!("=") unless padding
@@ -24,6 +49,18 @@ module Ob64
24
49
  string
25
50
  end
26
51
 
52
+ # Returns the Base64-decoded version of +string+.
53
+ # This method complies with ``Base 64 Encoding with URL and Filename Safe
54
+ # Alphabet'' in RFC 4648.
55
+ # The alphabet uses '-' instead of '+' and '_' instead of '/'.
56
+ #
57
+ # The padding character is optional.
58
+ # This method accepts both correctly-padded and unpadded input.
59
+ # Note that it still rejects incorrectly-padded input.
60
+ #
61
+ # @param string [String]
62
+ # @return [String]
63
+ # @raise [ArgumentError] if +string+ cannot be decoded
27
64
  def urlsafe_decode(string)
28
65
  if !string.end_with?("=") && string.length % 4 != 0
29
66
  string = string.ljust((string.length + 3) & ~3, "=")
@@ -34,10 +71,19 @@ module Ob64
34
71
  __decode(string)
35
72
  end
36
73
 
74
+ # Returns the length of the Base64-encoded version of +bin+.
75
+ #
76
+ # @param bin [String]
77
+ # @param paddding [Boolean] - if the Base64-encoded version of +bin+ will be padded
78
+ # @return [Integer]
37
79
  def encoded_length_of(bin, padding: true)
38
80
  __encoded_length_of(bin, padding)
39
81
  end
40
82
 
83
+ # Returns the length of the Base64-decoded version of +string+.
84
+ #
85
+ # @param string [String]
86
+ # @return [Integer]
41
87
  def decoded_length_of(string)
42
88
  __decoded_length_of(string)
43
89
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ob64
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Fernandes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-25 00:00:00.000000000 Z
11
+ date: 2021-09-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A fast Base64 encoder and decoder that makes use of SIMD extensions.
14
14
  email:
@@ -30,7 +30,7 @@ files:
30
30
  - CODE_OF_CONDUCT.md
31
31
  - Gemfile
32
32
  - Guardfile
33
- - LICENSE.txt
33
+ - LICENSE
34
34
  - README.md
35
35
  - Rakefile
36
36
  - benchmark.rb