z85 0.1 → 0.2

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: f0bd341e9c8a0230ff57e97dc939fd3195a849775bdfc1b702e65b06c1eec30e
4
- data.tar.gz: 9cafa70181d291c96f397f19af8dd333aecbb1acdce30d7aa3f188e0ed45d88f
3
+ metadata.gz: b42cdc4d3ab6d389b80a598d1139e194142ee57a0f35fd2562aaecbeeb24173e
4
+ data.tar.gz: e41d59835773468dd3a806e05378e1c83186bdfcc54a0a7caef92edcffef8093
5
5
  SHA512:
6
- metadata.gz: 799cad30de56e47b2ea6cbf481bc3b55a2319c43f2a33568c1e9af15ef4778ca5cb8145d13e1e4bcdf0dceb3cbc21a30bd0538c97a910a03ef51bc490a53cbc2
7
- data.tar.gz: 9b1a86f71561024b2432d0fa23c306dd0e454ae34eb837741244e90456231e799ac7887eba95d70951fd4fdf55fb3dc2aa3b4d2f79c1ad8d317a9ab80c44a3c0
6
+ metadata.gz: 0caf9cdb5e0800abc98795fe6ff7787bcc7e6d55fc9616789a955c8417b38852a28868f52794d869746a7e1ca11ca75c9d0815a4e9ad581b17d3b6f929ac5f9d
7
+ data.tar.gz: d2e768aa2e8ecfbb8732b13dab5fc123bbfd2d970a782c437337b730168af7c5684893d8845d4b4d5caefcb706899369fd01e37ecefed274fcf040860bb07180
data/ext/z85/z85.c CHANGED
@@ -66,7 +66,7 @@ static VALUE z85_encode(VALUE _mod, VALUE string)
66
66
  long size = RSTRING_LEN(string);
67
67
 
68
68
  if (size % 4)
69
- rb_raise(rb_eRuntimeError, "Invalid string, should have 0 mod 4 bytes");
69
+ rb_raise(rb_eRuntimeError, "Invalid string, number of bytes must be a multiple of 4");
70
70
 
71
71
  size_t encoded_size = size * 5 / 4;
72
72
  char *encoded = malloc(encoded_size + 1);
@@ -96,7 +96,7 @@ static VALUE z85_decode(VALUE _mod, VALUE string)
96
96
  long size = RSTRING_LEN(string);
97
97
 
98
98
  if (size % 5)
99
- rb_raise(rb_eRuntimeError, "Invalid string, should have 0 mod 5 bytes");
99
+ rb_raise(rb_eRuntimeError, "Invalid string, number of bytes must be a multiple of 5");
100
100
 
101
101
  size_t decoded_size = size * 4 / 5;
102
102
  byte* decoded = malloc(decoded_size);
data/lib/z85/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Z85
2
- VERSION = "0.1"
2
+ VERSION = "0.2"
3
3
  end
data/lib/z85.rb CHANGED
@@ -1,17 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "z85/z85"
2
4
  require "z85/version"
3
5
 
4
6
  module Z85
5
7
  def self.encode_with_padding(string)
6
- rem = string.bytesize % 4
7
- string += "\0" * (4 - rem) unless rem == 0
8
- encode(string) + rem.to_s
8
+ padding_length = 4 - (string.bytesize % 4)
9
+ string += "\0" * padding_length unless padding_length == 4
10
+ encode(string) + padding_length.to_s
9
11
  end
10
12
 
11
13
  def self.decode_with_padding(encoded)
12
- rem = encoded[-1].to_i
13
- decoded = decode(encoded.chop!)
14
- (4 - rem).times { decoded.chop! } unless rem == 0
14
+ padding_length = encoded[-1].to_i
15
+ encoded.chop!
16
+
17
+ decoded = decode(encoded)
18
+ padding_length.times { decoded.chop! } unless padding_length == 4
19
+
15
20
  decoded
16
21
  end
17
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: z85
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xavier Noria