base32 0.1.1 → 0.1.2
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.
- data/README +1 -1
- data/Rakefile +11 -4
- data/config/environment.rb +1 -1
- data/ext/decoder.c +2 -2
- data/ext/decoder.h +1 -1
- data/ext/encoder.c +1 -1
- data/ext/encoder.h +1 -1
- data/ext/ext.c +23 -1
- data/ext/extconf.rb +1 -1
- data/test/base32_test.rb +7 -3
- metadata +42 -33
data/README
CHANGED
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007 Samuel Tesla
|
1
|
+
# Copyright (c) 2007-2009 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.2"
|
45
45
|
end
|
46
46
|
|
47
47
|
Rake::GemPackageTask.new(gemspec) do |pkg|
|
@@ -49,7 +49,7 @@ Rake::GemPackageTask.new(gemspec) do |pkg|
|
|
49
49
|
end
|
50
50
|
|
51
51
|
namespace :test do
|
52
|
-
Rake::TestTask.new :all => [:
|
52
|
+
Rake::TestTask.new :all => [:test_extension] do |t|
|
53
53
|
t.libs << 'test'
|
54
54
|
t.libs << 'ext'
|
55
55
|
t.pattern = 'test/**/*_test.rb'
|
@@ -59,12 +59,19 @@ namespace :test do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
task :extension => "ext/base32.bundle"
|
62
|
+
task :test_extension do
|
63
|
+
sh 'rake TEST=1 ext/base32.bundle'
|
64
|
+
end
|
62
65
|
|
63
66
|
extension_source = FileList["ext/**/*.c", "ext/**/*.h"]
|
64
67
|
|
65
68
|
file "ext/base32.bundle" => ["ext/Makefile", *extension_source] do
|
66
69
|
cd "ext" do
|
67
|
-
|
70
|
+
if ENV['TEST']
|
71
|
+
sh "make cflags=\"-D TEST\""
|
72
|
+
else
|
73
|
+
sh "make"
|
74
|
+
end
|
68
75
|
end
|
69
76
|
end
|
70
77
|
|
data/config/environment.rb
CHANGED
data/ext/decoder.c
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* Copyright (c) 2007 Samuel Tesla
|
1
|
+
/* Copyright (c) 2007-2009 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
|
@@ -53,7 +53,7 @@ base32_decode_buffer_size (const size_t encodedTextLength)
|
|
53
53
|
{
|
54
54
|
if (encodedTextLength == 0 || encodedTextLength % 8 != 0)
|
55
55
|
return 0;
|
56
|
-
return encodedTextLength *
|
56
|
+
return encodedTextLength * 5 / 8;
|
57
57
|
}
|
58
58
|
|
59
59
|
size_t
|
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 Samuel Tesla
|
1
|
+
/* Copyright (c) 2007-2009 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
|
@@ -39,6 +39,9 @@ b32_decode (VALUE self, VALUE value)
|
|
39
39
|
return value;
|
40
40
|
|
41
41
|
VALUE result = rb_str_new (0, base32_decode_buffer_size (RSTRING (value)->len));
|
42
|
+
#ifdef TEST
|
43
|
+
memset(RSTRING (result)->ptr, 0xff, RSTRING (result)->len);
|
44
|
+
#endif
|
42
45
|
size_t length = base32_decode ((uint8_t *) RSTRING (result)->ptr, RSTRING (result)->len,
|
43
46
|
(uint8_t *) RSTRING (value)->ptr, RSTRING (value)->len);
|
44
47
|
if (length == 0)
|
@@ -60,17 +63,36 @@ b32_encode (VALUE self, VALUE value)
|
|
60
63
|
value = StringValue(value);
|
61
64
|
|
62
65
|
VALUE result = rb_str_new (0, base32_encoder_buffer_size (RSTRING (value)->len));
|
66
|
+
#ifdef TEST
|
67
|
+
memset(RSTRING (result)->ptr, 0xff, RSTRING (result)->len);
|
68
|
+
#endif
|
63
69
|
base32_encode ((uint8_t *) RSTRING (result)->ptr, RSTRING (result)->len,
|
64
70
|
(uint8_t *) RSTRING (value)->ptr, RSTRING (value)->len);
|
65
71
|
|
66
72
|
return result;
|
67
73
|
}
|
68
74
|
|
75
|
+
#ifdef TEST
|
76
|
+
static VALUE
|
77
|
+
b32_test_strlen (VALUE self, VALUE value)
|
78
|
+
{
|
79
|
+
return UINT2NUM (strlen (RSTRING (value)->ptr));
|
80
|
+
}
|
81
|
+
#endif
|
82
|
+
|
83
|
+
|
69
84
|
VALUE mBase32;
|
85
|
+
#ifdef TEST
|
86
|
+
VALUE mBase32Test;
|
87
|
+
#endif
|
70
88
|
|
71
89
|
void Init_base32 ()
|
72
90
|
{
|
73
91
|
mBase32 = rb_define_module ("Base32");
|
74
92
|
rb_define_module_function(mBase32, "decode", b32_decode, 1);
|
75
93
|
rb_define_module_function(mBase32, "encode", b32_encode, 1);
|
94
|
+
#ifdef TEST
|
95
|
+
mBase32Test = rb_define_module ("Base32Test");
|
96
|
+
rb_define_module_function(mBase32Test, "strlen", b32_test_strlen, 1);
|
97
|
+
#endif
|
76
98
|
}
|
data/ext/extconf.rb
CHANGED
data/test/base32_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007 Samuel Tesla
|
1
|
+
# Copyright (c) 2007-2009 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
|
@@ -23,11 +23,15 @@ require 'base32'
|
|
23
23
|
|
24
24
|
class TestBase32 < Test::Unit::TestCase
|
25
25
|
def assert_decoding(encoded, plain)
|
26
|
-
|
26
|
+
decoded = Base32.decode(encoded)
|
27
|
+
assert_equal(plain, decoded)
|
28
|
+
assert_equal(decoded.size, Base32Test.strlen(decoded))
|
27
29
|
end
|
28
30
|
|
29
31
|
def assert_encoding(encoded, plain)
|
30
|
-
|
32
|
+
actual = Base32.encode(plain)
|
33
|
+
assert_equal(encoded, actual)
|
34
|
+
assert_equal(actual.size, Base32Test.strlen(actual))
|
31
35
|
end
|
32
36
|
|
33
37
|
def assert_encode_and_decode(encoded, plain)
|
metadata
CHANGED
@@ -1,34 +1,26 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: base32
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-06-29 00:00:00 -05:00
|
8
|
-
summary: Ruby extension for base32 encoding and decoding
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
- ext
|
12
|
-
email: samuel@thoughtlocker.net
|
13
|
-
homepage: http://base32.rubyforge.org
|
14
|
-
rubyforge_project:
|
15
|
-
description:
|
16
|
-
autorequire:
|
17
|
-
default_executable:
|
18
|
-
bindir: bin
|
19
|
-
has_rdoc: true
|
20
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
-
requirements:
|
22
|
-
- - ">"
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 0.0.0
|
25
|
-
version:
|
4
|
+
version: 0.1.2
|
26
5
|
platform: ruby
|
27
|
-
signing_key:
|
28
|
-
cert_chain:
|
29
|
-
post_install_message:
|
30
6
|
authors:
|
31
7
|
- Samuel Tesla
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-06 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: samuel@thoughtlocker.net
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions:
|
21
|
+
- ext/extconf.rb
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
32
24
|
files:
|
33
25
|
- Rakefile
|
34
26
|
- config/environment.rb
|
@@ -40,17 +32,34 @@ files:
|
|
40
32
|
- ext/encoder.h
|
41
33
|
- ext/extconf.rb
|
42
34
|
- README
|
43
|
-
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://base32.rubyforge.org
|
37
|
+
licenses: []
|
44
38
|
|
39
|
+
post_install_message:
|
45
40
|
rdoc_options: []
|
46
41
|
|
47
|
-
|
48
|
-
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
-
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
- ext
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
53
57
|
requirements:
|
54
58
|
- none
|
55
|
-
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.3.5
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Ruby extension for base32 encoding and decoding
|
64
|
+
test_files: []
|
56
65
|
|