base32 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/Rakefile +2 -2
- data/config/environment.rb +1 -1
- data/ext/decoder.c +1 -1
- data/ext/decoder.h +1 -1
- data/ext/encoder.c +1 -1
- data/ext/encoder.h +1 -1
- data/ext/ext.c +22 -13
- data/ext/extconf.rb +1 -1
- data/test/base32_test.rb +1 -1
- metadata +17 -5
data/README
CHANGED
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-
|
1
|
+
# Copyright (c) 2007-2011 Samuel Tesla
|
2
2
|
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -41,7 +41,7 @@ gemspec = Gem::Specification.new do |s|
|
|
41
41
|
s.require_paths << 'ext'
|
42
42
|
s.requirements << 'none'
|
43
43
|
s.summary = "Ruby extension for base32 encoding and decoding"
|
44
|
-
s.version = "0.1.
|
44
|
+
s.version = "0.1.3"
|
45
45
|
end
|
46
46
|
|
47
47
|
Rake::GemPackageTask.new(gemspec) do |pkg|
|
data/config/environment.rb
CHANGED
data/ext/decoder.c
CHANGED
data/ext/decoder.h
CHANGED
data/ext/encoder.c
CHANGED
data/ext/encoder.h
CHANGED
data/ext/ext.c
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* Copyright (c) 2007-
|
1
|
+
/* Copyright (c) 2007-2011 Samuel Tesla
|
2
2
|
*
|
3
3
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
* of this software and associated documentation files (the "Software"), to deal
|
@@ -35,19 +35,28 @@ static VALUE
|
|
35
35
|
b32_decode (VALUE self, VALUE value)
|
36
36
|
{
|
37
37
|
value = StringValue (value);
|
38
|
-
if (
|
38
|
+
if (RSTRING_LEN (value) == 0)
|
39
39
|
return value;
|
40
40
|
|
41
|
-
|
41
|
+
size_t buflen = base32_decode_buffer_size (RSTRING_LEN (value));
|
42
|
+
char *buffer = (char *) malloc (buflen);
|
42
43
|
#ifdef TEST
|
43
|
-
memset(
|
44
|
+
memset(buffer, 0xff, buflen);
|
45
|
+
#else
|
46
|
+
memset(buffer, 0x00, buflen);
|
44
47
|
#endif
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
+
|
49
|
+
size_t length = base32_decode ((uint8_t *) buffer, buflen,
|
50
|
+
(uint8_t *) RSTRING_PTR (value), RSTRING_LEN (value));
|
51
|
+
|
52
|
+
if (length == 0) {
|
53
|
+
free(buffer);
|
48
54
|
rb_raise(rb_eRuntimeError, "Value provided not base32 encoded");
|
55
|
+
}
|
49
56
|
|
50
|
-
|
57
|
+
VALUE result = rb_str_new (0, length);
|
58
|
+
memcpy(RSTRING_PTR (result), buffer, length);
|
59
|
+
free(buffer);
|
51
60
|
return result;
|
52
61
|
}
|
53
62
|
|
@@ -62,12 +71,12 @@ b32_encode (VALUE self, VALUE value)
|
|
62
71
|
{
|
63
72
|
value = StringValue(value);
|
64
73
|
|
65
|
-
VALUE result = rb_str_new (0, base32_encoder_buffer_size (
|
74
|
+
VALUE result = rb_str_new (0, base32_encoder_buffer_size (RSTRING_LEN (value)));
|
66
75
|
#ifdef TEST
|
67
|
-
memset(
|
76
|
+
memset(RSTRING_PTR (result), 0xff, RSTRING_LEN (result));
|
68
77
|
#endif
|
69
|
-
base32_encode ((uint8_t *)
|
70
|
-
(uint8_t *)
|
78
|
+
base32_encode ((uint8_t *) RSTRING_PTR (result), RSTRING_LEN (result),
|
79
|
+
(uint8_t *) RSTRING_PTR (value), RSTRING_LEN (value));
|
71
80
|
|
72
81
|
return result;
|
73
82
|
}
|
@@ -76,7 +85,7 @@ b32_encode (VALUE self, VALUE value)
|
|
76
85
|
static VALUE
|
77
86
|
b32_test_strlen (VALUE self, VALUE value)
|
78
87
|
{
|
79
|
-
return UINT2NUM (strlen (
|
88
|
+
return UINT2NUM (strlen (RSTRING_PTR (value)));
|
80
89
|
}
|
81
90
|
#endif
|
82
91
|
|
data/ext/extconf.rb
CHANGED
data/test/base32_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base32
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Samuel Tesla
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2011-03-31 00:00:00 -07:00
|
13
19
|
default_executable:
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -43,21 +49,27 @@ require_paths:
|
|
43
49
|
- lib
|
44
50
|
- ext
|
45
51
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
46
53
|
requirements:
|
47
54
|
- - ">="
|
48
55
|
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
49
59
|
version: "0"
|
50
|
-
version:
|
51
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
52
62
|
requirements:
|
53
63
|
- - ">="
|
54
64
|
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
55
68
|
version: "0"
|
56
|
-
version:
|
57
69
|
requirements:
|
58
70
|
- none
|
59
71
|
rubyforge_project:
|
60
|
-
rubygems_version: 1.
|
72
|
+
rubygems_version: 1.5.0
|
61
73
|
signing_key:
|
62
74
|
specification_version: 3
|
63
75
|
summary: Ruby extension for base32 encoding and decoding
|