ob64 0.2.0 → 0.3.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: 4697c65d1300ef0e6ec98cd12884ea07b3ab33a2a2b398a2a19ccb02d43d46d6
4
- data.tar.gz: ce016702f7b2c43c183c43ab87974d74fe8efc56ba1e983e465f66e69f9edba2
3
+ metadata.gz: 390a8a475295c4e7fbc739d13fcb099f18e8ab20fcfadedda2a4da0b81646786
4
+ data.tar.gz: 87e7327f2501a6bb34d3e852c5dce1f88ef3b69386d78a6bbd728b56231decb0
5
5
  SHA512:
6
- metadata.gz: ca030510d227fac302d0dcf723bb78ff43f0e093b164293512d2fe5989fd05c43fb05c10ea5e2bbca5b3f31a8692b144979e80c956da54e03344ce5785c787a8
7
- data.tar.gz: d9cf2b043bf838add8daec7ef0882ab204b23d35ce1b019a5aa614621fba5c7e83234579ba8b1d3372fd7e9f477a3a2c9af8c7b96a63f78d865a2f1a09e7fbf5
6
+ metadata.gz: f97d6a73685d48f8e90974ec7d6ca14a6827b53955d73c4d536bcade8798e7cec507c96e3b9f608d0170c703cf9041106c93ce4655ac8caf7b72599befe75b6c
7
+ data.tar.gz: 8cba6ce844a012749a8ad2a60d19be7f22428cc6512051c8e7415ef84be4c2566eec3d43e593513024e80701d81eccd1e0bc0a68283a4161197d878bb8a7c01a
data/.gitignore CHANGED
@@ -12,6 +12,7 @@
12
12
  *.a
13
13
  mkmf.log
14
14
  Gemfile.lock
15
+ .byebug_history
15
16
 
16
17
  # rspec failure tracking
17
18
  .rspec_status
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2021-09-21
3
+ ## [0.3.0] - 2021-09-28
4
+
5
+ - Raise error when attempting to get the base64-decoded length of an invalid (in
6
+ length) base64-encoded payload.
7
+
8
+ ## [0.2.0] - 2021-09-26
9
+
10
+ - Add yard documention
11
+
12
+ ## [0.1.0] - 2021-09-25
4
13
 
5
14
  - Initial release
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/ob64.svg)](http://rubygems.org/gems/ob64)
4
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)
5
+ [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/ob64/0.2.0)
6
6
 
7
7
  A *fast* Base64 encoder and decoder as a Ruby gem.
8
8
 
data/benchmark.rb CHANGED
@@ -4,9 +4,9 @@ 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
7
+ $run_encode_benchmark = true
8
+ $run_decode_benchmark = true
9
+ $run_urlsafe_encode_benchmark = true
10
10
  $run_urlsafe_decode_benchmark = true
11
11
 
12
12
  def to_size(bytes)
data/ext/ob64/ob64_ext.c CHANGED
@@ -69,13 +69,15 @@ size_t __encoded_length_of(VALUE bin, bool withPadding)
69
69
 
70
70
  size_t __decoded_length_of(VALUE string)
71
71
  {
72
+ char *string_ptr = StringValuePtr(string);
72
73
  size_t string_len = RSTRING_LEN(string);
73
- if (string_len < 2) return 0;
74
-
75
74
  size_t padding = 0;
76
- char* string_ptr = StringValuePtr(string);
77
75
  if (string_ptr[string_len - 1] == '=') padding++;
78
76
  if (string_ptr[string_len - 2] == '=') padding++;
79
77
 
78
+ if ((string_len - padding) % 4 == 1) {
79
+ rb_raise(rb_eArgError, "invalid base64");
80
+ }
81
+
80
82
  return (3 * (string_len - padding)) / 4;
81
83
  }
data/lib/ob64/core_ext.rb CHANGED
@@ -24,4 +24,6 @@ module Ob64
24
24
 
25
25
  ::Base64.prepend(CoreExt)
26
26
  ::Base64.singleton_class.prepend(CoreExt)
27
+
28
+ private_constant :CoreExt
27
29
  end
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.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/ob64.rb CHANGED
@@ -5,6 +5,9 @@ require_relative "ob64_ext"
5
5
 
6
6
  # Methods for base64-encoding and -decoding strings.
7
7
  module Ob64
8
+ # The glue between Ruby and libbase64. See +../ext/libbase64/ob64/ob64_ext.c+.
9
+ module LibBase64; end
10
+
8
11
  include LibBase64
9
12
  extend LibBase64
10
13
 
@@ -74,7 +77,7 @@ module Ob64
74
77
  # Returns the length of the Base64-encoded version of +bin+.
75
78
  #
76
79
  # @param bin [String]
77
- # @param paddding [Boolean] - if the Base64-encoded version of +bin+ will be padded
80
+ # @param padding [Boolean] - if the Base64-encoded version of +bin+ will be padded
78
81
  # @return [Integer]
79
82
  def encoded_length_of(bin, padding: true)
80
83
  __encoded_length_of(bin, padding)
@@ -82,8 +85,11 @@ module Ob64
82
85
 
83
86
  # Returns the length of the Base64-decoded version of +string+.
84
87
  #
88
+ # ArgumentError is raised if +string+ has an invalid length.
89
+ #
85
90
  # @param string [String]
86
91
  # @return [Integer]
92
+ # @raise [ArgumentError] if +string+ has an invalid length
87
93
  def decoded_length_of(string)
88
94
  __decoded_length_of(string)
89
95
  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.2.0
4
+ version: 0.3.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-26 00:00:00.000000000 Z
11
+ date: 2021-09-28 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:
@@ -18,7 +18,6 @@ extensions:
18
18
  - ext/ob64/extconf.rb
19
19
  extra_rdoc_files: []
20
20
  files:
21
- - ".byebug_history"
22
21
  - ".envrc"
23
22
  - ".github/workflows/main.yml"
24
23
  - ".gitignore"
@@ -68,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
67
  - !ruby/object:Gem::Version
69
68
  version: '0'
70
69
  requirements: []
71
- rubygems_version: 3.1.4
70
+ rubygems_version: 3.2.15
72
71
  signing_key:
73
72
  specification_version: 4
74
73
  summary: A fast Base64 encoder and decoder.
data/.byebug_history DELETED
@@ -1,72 +0,0 @@
1
- continue
2
- aa == String.new(bb, encoding: 'ASCII-8BIT')
3
- String.new(bb, encoding: 'ASCII').encoding
4
- bb.encoding
5
- aa.encoding
6
- aa == String.new(bb, encoding: 'ASCII')
7
- aa == String.new(bb, encoding: 'ASCII)
8
- aa == String.new(bb)
9
- continue
10
- aa = String.new(bb)
11
- bb.dup.force_encoding(Encoding::ASCII_8BIT) == aa
12
- bb.dup.force_encoding(Encoding::ASCII_8BIT).encoding
13
- bb.dup.force_encoding Encoding::ASCII_8BIT
14
- bb.force_encoding Encoding::ASCII_8BIT
15
- bb.encode Encoding::ASCII_8BIT
16
- aa.encode Encoding::UTF_8
17
- aa.encode Encoding::UTF-8
18
- bb.encode Encoding::ASCII_8BIT
19
- Encoding.constants
20
- Encoding
21
- bb.encoding
22
- aa.encoding
23
- bb.class
24
- aa.class
25
- aa.casecmp? 'ad'
26
- aa.casecmp? bb
27
- bb.bytes
28
- aa.bytes
29
- bb.bytesize
30
- aa.bytesize
31
- bb.size
32
- aa.size
33
- aa.match? bb
34
- aa.match?
35
- aa == bb
36
- aa
37
- a
38
- bb
39
- continue
40
- b
41
- a
42
- exit
43
- eixt
44
- continue
45
- disable-byebug
46
- continue
47
- missing_padding
48
- n
49
- continue
50
- n
51
- missing_padding
52
- string
53
- n
54
- string
55
- continue
56
- string
57
- continue
58
- string
59
- continue
60
- exit
61
- missing_padding
62
- n
63
- string
64
- continue
65
- __decode(string)
66
- string
67
- n
68
- string
69
- missing_padding
70
- next
71
- string
72
- continue