ob64 0.2.0 → 0.3.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/.gitignore +1 -0
- data/CHANGELOG.md +10 -1
- data/README.md +1 -1
- data/benchmark.rb +3 -3
- data/ext/ob64/ob64_ext.c +5 -3
- data/lib/ob64/core_ext.rb +2 -0
- data/lib/ob64/version.rb +1 -1
- data/lib/ob64.rb +7 -1
- metadata +3 -4
- data/.byebug_history +0 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 390a8a475295c4e7fbc739d13fcb099f18e8ab20fcfadedda2a4da0b81646786
|
4
|
+
data.tar.gz: 87e7327f2501a6bb34d3e852c5dce1f88ef3b69386d78a6bbd728b56231decb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f97d6a73685d48f8e90974ec7d6ca14a6827b53955d73c4d536bcade8798e7cec507c96e3b9f608d0170c703cf9041106c93ce4655ac8caf7b72599befe75b6c
|
7
|
+
data.tar.gz: 8cba6ce844a012749a8ad2a60d19be7f22428cc6512051c8e7415ef84be4c2566eec3d43e593513024e80701d81eccd1e0bc0a68283a4161197d878bb8a7c01a
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.
|
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
|
[](http://rubygems.org/gems/ob64)
|
4
4
|
[](https://github.com/jcmfernandes/ob64/actions?query=workflow:Test)
|
5
|
-
[](http://www.rubydoc.info/gems/ob64/0.
|
5
|
+
[](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 =
|
8
|
-
$run_decode_benchmark =
|
9
|
-
$run_urlsafe_encode_benchmark =
|
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
data/lib/ob64/version.rb
CHANGED
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
|
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.
|
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-
|
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.
|
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
|