z85 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/z85/z85.c +2 -2
- data/lib/z85/version.rb +1 -1
- data/lib/z85.rb +11 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b42cdc4d3ab6d389b80a598d1139e194142ee57a0f35fd2562aaecbeeb24173e
|
4
|
+
data.tar.gz: e41d59835773468dd3a806e05378e1c83186bdfcc54a0a7caef92edcffef8093
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
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,
|
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
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
|
-
|
7
|
-
string += "\0" *
|
8
|
-
encode(string) +
|
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
|
-
|
13
|
-
|
14
|
-
|
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
|