ob64 0.4.0 → 0.6.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.
@@ -0,0 +1,18 @@
1
+ #ifndef PACK_UUENCODE_H
2
+ #define PACK_UUENCODE_H
3
+
4
+ #include <stddef.h>
5
+
6
+ size_t pack_uuencode_encode(const char *src, size_t srclen, char *out);
7
+ /* Encodes like native pack("u") with line_len (a multiple of 3, 3..63) bytes per line; returns the length */
8
+ size_t pack_uuencode_lines(const char *src, size_t srclen, char *out, size_t line_len);
9
+ size_t pack_uuencode_decode(const char *src, size_t srclen, char *out);
10
+ /* Upper bound of the decoded length of srclen chars: srclen * 3 / 4 without overflow */
11
+ size_t pack_uudecode_cap(size_t srclen);
12
+ /*
13
+ * Decodes like native unpack("u") and returns the decoded length. out needs
14
+ * pack_uudecode_cap(srclen) + 3 bytes; NULL computes the length only.
15
+ */
16
+ size_t pack_uudecode_lines(const char *src, size_t srclen, char *out);
17
+
18
+ #endif /* PACK_UUENCODE_H */
data/lib/ob64/core_ext.rb CHANGED
@@ -1,29 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "ob64"
4
- require "base64"
5
4
 
6
- module Ob64
7
- module CoreExt
8
- def strict_encode64(bin)
9
- Ob64.strictier_encode(bin)
10
- end
11
-
12
- def strict_decode64(str)
13
- Ob64.strictier_decode(str)
14
- end
15
-
16
- def urlsafe_encode64(bin, padding: true)
17
- Ob64.urlsafe_encode(bin, padding: padding)
18
- end
19
-
20
- def urlsafe_decode64(str)
21
- Ob64.urlsafe_decode(str)
22
- end
23
- end
24
-
25
- ::Base64.prepend(CoreExt)
26
- ::Base64.singleton_class.prepend(CoreExt)
27
-
28
- private_constant :CoreExt
29
- end
5
+ ::Array.prepend(Ob64::Ext::Pack)
6
+ ::String.prepend(Ob64::Ext::Unpack)
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.4.0"
4
+ VERSION = "0.6.0"
5
5
  end
data/lib/ob64.rb CHANGED
@@ -3,94 +3,173 @@
3
3
  require_relative "ob64/version"
4
4
  require_relative "ob64_ext"
5
5
 
6
- # Methods for base64-encoding and -decoding strings.
6
+ # Fast base64 and uuencode encoding and decoding: see {Base64} and {UU}.
7
7
  module Ob64
8
- # The glue between Ruby and libbase64. See +../ext/libbase64/ob64/ob64_ext.c+.
9
- module LibBase64; end
8
+ # The glue between Ruby and the C codecs. See +../ext/ob64/ob64_ext.c+.
9
+ module Ext; end
10
10
 
11
- include LibBase64
12
- extend LibBase64
11
+ include Ext
12
+ extend Ext
13
13
 
14
14
  module_function
15
15
 
16
- # Returns the Base64-encoded version of +bin+.
17
- # This method complies with RFC 4648.
18
- # No line feeds are added.
16
+ # Returns the codec used by {Base64}, {UU} and, with +ob64/core_ext+,
17
+ # +pack+ and +unpack+ with +m+ and +u+. Defaults to {best_codec}.
19
18
  #
20
- # @param bin [String]
21
- # @return [String]
22
- def encode(bin)
23
- __encode(bin)
19
+ # @return [Symbol] one of {codecs}
20
+ def codec
21
+ __codec
24
22
  end
25
23
 
26
- # Returns the Base64-decoded version of +string+.
27
- # This method complies with RFC 4648.
28
- # ArgumentError is raised if +string+ is incorrectly padded or contains
29
- # non-alphabet characters. Note that CR or LF are also rejected.
24
+ # Forces a codec for the whole process: every thread and Ractor.
30
25
  #
31
- # @param string [String]
32
- # @return [String]
33
- # @raise [ArgumentError] if +string+ cannot be decoded
34
- def decode(string)
35
- __decode(string)
26
+ # @param codec [Symbol] one of {codecs}
27
+ # @return [Symbol] +codec+
28
+ # @raise [ArgumentError] if +codec+ is unknown or this CPU cannot run it
29
+ def codec=(codec)
30
+ __set_codec(codec)
36
31
  end
37
32
 
38
- # Returns the Base64-encoded version of +bin+.
39
- # This method complies with ``Base 64 Encoding with URL and Filename Safe
40
- # Alphabet'' in RFC 4648.
41
- # The alphabet uses '-' instead of '+' and '_' instead of '/'.
42
- # Note that the result can still contain '='.
43
- # You can remove the padding by setting +padding+ as false.
33
+ # Returns the codecs this CPU runs, best last. +:scalar+ is plain C.
44
34
  #
45
- # @param bin [String]
46
- # @param padding [Boolean] - if the output must be padded
47
- # @return [String]
48
- def urlsafe_encode(bin, padding: true)
49
- string = __encode(bin)
50
- string.chomp!("==") || string.chomp!("=") unless padding
51
- string.tr!("+/", "-_")
52
- string
35
+ # @return [Array<Symbol>] among +:scalar+, +:avx2+, +:avx512+, +:neon64+
36
+ def codecs
37
+ __codecs
53
38
  end
54
39
 
55
- # Returns the Base64-decoded version of +string+.
56
- # This method complies with ``Base 64 Encoding with URL and Filename Safe
57
- # Alphabet'' in RFC 4648.
58
- # The alphabet uses '-' instead of '+' and '_' instead of '/'.
40
+ # Returns the best codec this CPU runs, the default {codec}.
59
41
  #
60
- # The padding character is optional.
61
- # This method accepts both correctly-padded and unpadded input.
62
- # Note that it still rejects incorrectly-padded input.
63
- #
64
- # @param string [String]
65
- # @return [String]
66
- # @raise [ArgumentError] if +string+ cannot be decoded
67
- def urlsafe_decode(string)
68
- if !string.end_with?("=") && string.length % 4 != 0
69
- string = string.ljust((string.length + 3) & ~3, "=")
70
- string.tr!("-_", "+/")
71
- else
72
- string = string.tr("-_", "+/")
73
- end
74
- __decode(string)
42
+ # @return [Symbol] one of {codecs}
43
+ def best_codec
44
+ codecs.last
75
45
  end
76
46
 
77
- # Returns the length of the Base64-encoded version of +bin+.
78
- #
79
- # @param bin [String]
80
- # @param padding [Boolean] - if the Base64-encoded version of +bin+ will be padded
81
- # @return [Integer]
82
- def encoded_length_of(bin, padding: true)
83
- __encoded_length_of(bin, padding)
47
+ # Methods for base64-encoding and -decoding strings.
48
+ module Base64
49
+ include Ext
50
+ extend Ext
51
+
52
+ module_function
53
+
54
+ # Returns the Base64-encoded version of +bin+.
55
+ # This method complies with RFC 4648.
56
+ # No line feeds are added.
57
+ #
58
+ # @param bin [String]
59
+ # @return [String]
60
+ def encode(bin)
61
+ __encode(bin, false, true)
62
+ end
63
+
64
+ # Returns the Base64-decoded version of +string+.
65
+ # This method complies with RFC 4648.
66
+ # ArgumentError is raised if +string+ is incorrectly padded or contains
67
+ # non-alphabet characters. Note that CR or LF are also rejected.
68
+ #
69
+ # With +loose+, the padding character is optional: both correctly-padded
70
+ # and unpadded input are accepted. Incorrectly-padded input is still
71
+ # rejected.
72
+ #
73
+ # @param string [String]
74
+ # @param loose [Boolean] - if unpadded input is accepted
75
+ # @return [String]
76
+ # @raise [ArgumentError] if +string+ cannot be decoded
77
+ def decode(string, loose: false)
78
+ __decode(string, false, loose)
79
+ end
80
+
81
+ # Returns the Base64-encoded version of +bin+.
82
+ # This method complies with ``Base 64 Encoding with URL and Filename Safe
83
+ # Alphabet'' in RFC 4648.
84
+ # The alphabet uses '-' instead of '+' and '_' instead of '/'.
85
+ # Note that the result can still contain '='.
86
+ # You can remove the padding by setting +padding+ as false.
87
+ #
88
+ # @param bin [String]
89
+ # @param padding [Boolean] - if the output must be padded
90
+ # @return [String]
91
+ def urlsafe_encode(bin, padding: true)
92
+ __encode(bin, true, padding)
93
+ end
94
+
95
+ # Returns the Base64-decoded version of +string+.
96
+ # This method complies with ``Base 64 Encoding with URL and Filename Safe
97
+ # Alphabet'' in RFC 4648.
98
+ # The alphabet uses '-' instead of '+' and '_' instead of '/'.
99
+ #
100
+ # The padding character is optional.
101
+ # This method accepts both correctly-padded and unpadded input.
102
+ # Note that it still rejects incorrectly-padded input.
103
+ #
104
+ # @param string [String]
105
+ # @return [String]
106
+ # @raise [ArgumentError] if +string+ cannot be decoded
107
+ def urlsafe_decode(string)
108
+ __decode(string, true, true)
109
+ end
110
+
111
+ # Returns the length of the Base64-encoded version of +bin+.
112
+ #
113
+ # @param bin [String]
114
+ # @param padding [Boolean] - if the Base64-encoded version of +bin+ will be padded
115
+ # @return [Integer]
116
+ def encoded_length_of(bin, padding: true)
117
+ __encoded_length_of(bin, padding)
118
+ end
119
+
120
+ # Returns the length of the Base64-decoded version of +string+.
121
+ #
122
+ # ArgumentError is raised if +string+ has an invalid length.
123
+ #
124
+ # @param string [String]
125
+ # @return [Integer]
126
+ # @raise [ArgumentError] if +string+ has an invalid length
127
+ def decoded_length_of(string)
128
+ __decoded_length_of(string)
129
+ end
84
130
  end
85
131
 
86
- # Returns the length of the Base64-decoded version of +string+.
87
- #
88
- # ArgumentError is raised if +string+ has an invalid length.
89
- #
90
- # @param string [String]
91
- # @return [Integer]
92
- # @raise [ArgumentError] if +string+ has an invalid length
93
- def decoded_length_of(string)
94
- __decoded_length_of(string)
132
+ # Methods for uuencoding and -decoding strings.
133
+ module UU
134
+ include Ext
135
+ extend Ext
136
+
137
+ module_function
138
+
139
+ # Returns the uuencoded version of +bin+, like <tt>[bin].pack("u")</tt>:
140
+ # lines of up to 45 input bytes, each ending in a newline.
141
+ #
142
+ # @param bin [String]
143
+ # @return [String]
144
+ def encode(bin)
145
+ __uuencode(bin)
146
+ end
147
+
148
+ # Returns the uudecoded version of +string+, like <tt>string.unpack1("u")</tt>.
149
+ # Decoding is lenient, as in Ruby: it stops at the first invalid line and
150
+ # never raises for malformed input.
151
+ #
152
+ # @param string [String]
153
+ # @return [String]
154
+ def decode(string)
155
+ __uudecode(string)
156
+ end
157
+
158
+ # Returns the length of the uuencoded version of +bin+.
159
+ #
160
+ # @param bin [String]
161
+ # @return [Integer]
162
+ def encoded_length_of(bin)
163
+ __uuencoded_length_of(bin)
164
+ end
165
+
166
+ # Returns the length of the uudecoded version of +string+.
167
+ # Like {decode}, never raises for malformed input.
168
+ #
169
+ # @param string [String]
170
+ # @return [Integer]
171
+ def decoded_length_of(string)
172
+ __uudecoded_length_of(string)
173
+ end
95
174
  end
96
175
  end
data/ob64.gemspec CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["joao.fernandes@ist.utl.pt"]
11
11
  spec.homepage = "https://github.com/jcmfernandes/ob64"
12
12
  spec.license = "MIT"
13
- spec.summary = "A fast Base64 encoder and decoder."
14
- spec.description = "A fast Base64 encoder and decoder that makes use of SIMD extensions."
13
+ spec.summary = "A fast Base64 and uuencode encoder and decoder."
14
+ spec.description = "A fast Base64 and uuencode encoder and decoder that makes use of SIMD extensions."
15
15
 
16
16
  # Specify which files should be added to the gem when it is released.
17
17
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -28,5 +28,5 @@ Gem::Specification.new do |spec|
28
28
  "source_code_uri" => spec.homepage + "/tree/v#{spec.version}"
29
29
  }
30
30
 
31
- spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
31
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.3.0")
32
32
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ob64
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Fernandes
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-09-28 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description: A fast Base64 encoder and decoder that makes use of SIMD extensions.
12
+ description: A fast Base64 and uuencode encoder and decoder that makes use of SIMD
13
+ extensions.
14
14
  email:
15
15
  - joao.fernandes@ist.utl.pt
16
16
  executables: []
@@ -18,9 +18,9 @@ extensions:
18
18
  - ext/ob64/extconf.rb
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - ".github/dependabot.yml"
21
22
  - ".github/workflows/main.yml"
22
23
  - ".gitignore"
23
- - ".gitmodules"
24
24
  - ".rspec"
25
25
  - ".standard.yml"
26
26
  - ".yardopts"
@@ -39,9 +39,15 @@ files:
39
39
  - bin/setup
40
40
  - bin/standardrb
41
41
  - ext/ob64/extconf.rb
42
- - ext/ob64/libbase64.h
43
42
  - ext/ob64/ob64.h
44
43
  - ext/ob64/ob64_ext.c
44
+ - ext/ob64/ob64_pack.c
45
+ - ext/ob64/pack_base64.c
46
+ - ext/ob64/pack_base64.h
47
+ - ext/ob64/pack_generic.h
48
+ - ext/ob64/pack_simd.h
49
+ - ext/ob64/pack_uuencode.c
50
+ - ext/ob64/pack_uuencode.h
45
51
  - lib/ob64.rb
46
52
  - lib/ob64/core_ext.rb
47
53
  - lib/ob64/version.rb
@@ -52,9 +58,8 @@ licenses:
52
58
  metadata:
53
59
  homepage_uri: https://github.com/jcmfernandes/ob64
54
60
  changelog_uri: https://github.com/jcmfernandes/ob64/blob/master/CHANGELOG.md
55
- documentation_uri: https://www.rubydoc.info/gems/ob64/0.4.0
56
- source_code_uri: https://github.com/jcmfernandes/ob64/tree/v0.4.0
57
- post_install_message:
61
+ documentation_uri: https://www.rubydoc.info/gems/ob64/0.6.0
62
+ source_code_uri: https://github.com/jcmfernandes/ob64/tree/v0.6.0
58
63
  rdoc_options: []
59
64
  require_paths:
60
65
  - lib
@@ -62,15 +67,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
67
  requirements:
63
68
  - - ">="
64
69
  - !ruby/object:Gem::Version
65
- version: 2.5.0
70
+ version: 3.3.0
66
71
  required_rubygems_version: !ruby/object:Gem::Requirement
67
72
  requirements:
68
73
  - - ">="
69
74
  - !ruby/object:Gem::Version
70
75
  version: '0'
71
76
  requirements: []
72
- rubygems_version: 3.2.15
73
- signing_key:
77
+ rubygems_version: 3.6.9
74
78
  specification_version: 4
75
- summary: A fast Base64 encoder and decoder.
79
+ summary: A fast Base64 and uuencode encoder and decoder.
76
80
  test_files: []
data/.gitmodules DELETED
@@ -1,3 +0,0 @@
1
- [submodule "vendor/libbase64"]
2
- path = vendor/libbase64
3
- url = https://github.com/jcmfernandes/base64-cmake
data/ext/ob64/libbase64.h DELETED
@@ -1 +0,0 @@
1
- #include "../../vendor/libbase64/include/libbase64.h"