jruby-base32 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *~
2
+ manifest.mf
3
+ build.xml
4
+ pkg
5
+ dist
6
+ build
7
+ nbproject
8
+ tmp
9
+ lib/base32.jar
data/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 The Skunkworx
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,16 @@
1
+ = jruby-base32
2
+
3
+ A Jruby Java extension port of the base32 gem
4
+
5
+ == Installing
6
+
7
+ jruby -S gem install jruby-base32
8
+
9
+ == Usage
10
+
11
+ encoded = Base32.encode("thin pancetta!") # => "ORUGS3RAOBQW4Y3FOR2GCII="
12
+ decoded = Base32.decode(encoded) # => "thin pancetta!"
13
+
14
+ == Copyright
15
+
16
+ Copyright 2011 The Skunkworx
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # Copyright (c) 2011 The Skunkworx
2
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
3
+ # this software and associated documentation files (the "Software"), to deal in
4
+ # the Software without restriction, including without limitation the rights to
5
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
6
+ # of the Software, and to permit persons to whom the Software is furnished to do
7
+ # so, subject to the following conditions:
8
+
9
+ # The above copyright notice and this permission notice shall be included in all
10
+ # copies or substantial portions of the Software.
11
+
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18
+ # SOFTWARE.
19
+
20
+ require 'rubygems'
21
+ require 'rake'
22
+ require 'rake/clean'
23
+ require 'rake/gempackagetask'
24
+ require 'rake/extensiontask'
25
+ require 'rake/javaextensiontask'
26
+ require 'spec/rake/spectask'
27
+
28
+ GEMSPEC = eval(File.read(File.expand_path('../jruby-base32.gemspec', __FILE__)))
29
+ GEMSPEC.files += ['lib/base32.jar']
30
+
31
+ CLEAN.include '**/*.jar'
32
+
33
+ Rake::GemPackageTask.new(GEMSPEC) do |pkg|
34
+ end
35
+
36
+ Rake::JavaExtensionTask.new("base32", GEMSPEC) do |ext|
37
+ ext.ext_dir = 'ext/java'
38
+ end
39
+
40
+ Spec::Rake::SpecTask.new('spec') do |t|
41
+ t.spec_files = FileList['spec/*.rb']
42
+ end
43
+
44
+ task :build => [:compile]
45
+ task :default => [:compile]
@@ -0,0 +1,100 @@
1
+ /*
2
+ Copyright (c) 2011 The Skunkworx
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the "Software"), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ */
22
+
23
+ package base32;
24
+
25
+ import java.nio.ByteBuffer;
26
+ import java.nio.MappedByteBuffer;
27
+
28
+ /**
29
+ * Static class to perform base32 encoding
30
+ *
31
+ * @author Chris Umbel
32
+ */
33
+ public class Base32Decoder {
34
+ public static final int[] byteTable = {
35
+ 0xff, 0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
36
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
37
+ 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
38
+ 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
39
+ 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
40
+ 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff,
41
+ 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
42
+ 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
43
+ 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
44
+ 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff
45
+ };
46
+
47
+ public static byte[] decode(String encodedText) {
48
+ int i;
49
+ int shiftIndex = 0;
50
+ int plainDigit;
51
+ int plainPos = 0;
52
+ int encodedByte;
53
+
54
+ StringBuilder encodedBuffer = new StringBuilder(encodedText);
55
+
56
+ if(encodedBuffer.length() > 0) {
57
+ while(encodedBuffer.charAt(encodedBuffer.length() - 1) == '=')
58
+ encodedBuffer.deleteCharAt(encodedBuffer.length() - 1);
59
+ }
60
+
61
+ byte[] buff = new byte[encodedBuffer.length() * 5 / 8];
62
+
63
+ for(i = 0; i < encodedBuffer.length(); i++) {
64
+ /* grab the encoded byte out of the input */
65
+ encodedByte = encodedBuffer.charAt(i) - 0x30;
66
+
67
+ if(encodedByte >= 0 && encodedByte < byteTable.length) {
68
+ /* get the raw plaintext value of the encoded byte */
69
+ plainDigit = byteTable[encodedByte];
70
+
71
+ if (plainDigit != 0xff) {
72
+ if(shiftIndex <= 3) {
73
+ shiftIndex = (shiftIndex + 5) % 8;
74
+
75
+ if(shiftIndex == 0) {
76
+ buff[plainPos] |= plainDigit;
77
+ plainPos++;
78
+ } else
79
+ buff[plainPos] |= plainDigit << (8 - shiftIndex);
80
+ } else {
81
+ shiftIndex = (shiftIndex + 5) % 8;
82
+ buff[plainPos] |= (plainDigit >>> shiftIndex);
83
+ plainPos++;
84
+
85
+ if (plainPos >= buff.length)
86
+ break;
87
+
88
+ buff[plainPos] |= plainDigit << (8 - shiftIndex);
89
+ }
90
+ }
91
+ }
92
+ }
93
+
94
+ return buff;
95
+ }
96
+
97
+ public static String decodeString(String encodedText) {
98
+ return new String(decode(encodedText));
99
+ }
100
+ }
@@ -0,0 +1,89 @@
1
+ /*
2
+ Copyright (c) 2011 The Skunkworx
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the "Software"), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ */
22
+
23
+ package base32;
24
+
25
+ /**
26
+ * Static class to perform base32 encoding
27
+ *
28
+ * @author Chris Umbel
29
+ */
30
+ public class Base32Encoder {
31
+ private static final String charTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
32
+
33
+ public static int getDigit(byte[] buff, int i) {
34
+ return buff[i] >= 0 ? buff[i] : buff[i] + 256;
35
+ }
36
+
37
+ public static String encode(String plainText) {
38
+ return encode(plainText.getBytes());
39
+ }
40
+
41
+ public static int quintetCount(byte[] buff) {
42
+ int quintets = buff.length / 5;
43
+
44
+ return buff.length % 5 == 0 ? quintets: quintets + 1;
45
+ }
46
+
47
+ public static String encode(byte[] buff) {
48
+ int next;
49
+ int current;
50
+ int shiftIndex = 0;
51
+ int digit = 0;
52
+ int i = 0;
53
+ int outputLength = quintetCount(buff) * 8;
54
+
55
+ StringBuilder builder = new StringBuilder(outputLength);
56
+
57
+ while(i < buff.length) {
58
+ current = getDigit(buff, i);
59
+
60
+ if(shiftIndex > 3) {
61
+ if(i + 1 < buff.length)
62
+ next = getDigit(buff, i + 1);
63
+ else
64
+ next = 0;
65
+
66
+ digit = current & (0xff >> shiftIndex);
67
+ shiftIndex = (shiftIndex + 5) % 8;
68
+ digit <<= shiftIndex;
69
+ digit |= next >> (8 - shiftIndex);
70
+ i++;
71
+ } else {
72
+ digit = (current >> (8 - (shiftIndex + 5))) & 0x1f;
73
+ shiftIndex = (shiftIndex + 5) % 8;
74
+
75
+ if(shiftIndex == 0)
76
+ i++;
77
+ }
78
+
79
+ builder.append(charTable.charAt(digit));
80
+ }
81
+
82
+ int padding = builder.capacity() - builder.length();
83
+
84
+ for(i = 0; i < padding; i++)
85
+ builder.append("=");
86
+
87
+ return builder.toString();
88
+ }
89
+ }
@@ -0,0 +1,52 @@
1
+ /*
2
+ Copyright (c) 2011 The Skunkworx
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the "Software"), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ */
22
+ package base32;
23
+
24
+
25
+ import org.jruby.Ruby;
26
+ import org.jruby.RubyModule;
27
+ import org.jruby.RubyString;
28
+ import org.jruby.runtime.Block;
29
+ import org.jruby.runtime.CallbackFactory;
30
+ import org.jruby.runtime.builtin.IRubyObject;
31
+
32
+ /**
33
+ * The actual module containing the methods jruby will use
34
+ *
35
+ * @author Chris Umbel
36
+ */
37
+ public class Base32Module {
38
+ public static IRubyObject encode(IRubyObject recv, IRubyObject plainText, Block unusedBlock) {
39
+ return RubyString.newString(recv.getRuntime(), Base32Encoder.encode(plainText.asJavaString()));
40
+ }
41
+
42
+ public static IRubyObject decode(IRubyObject recv, IRubyObject encodedText, Block unusedBlock) {
43
+ return RubyString.newString(recv.getRuntime(), Base32Decoder.decodeString(encodedText.asJavaString()));
44
+ }
45
+
46
+ public static void init(Ruby runtime) {
47
+ RubyModule base32Module = runtime.defineModule("Base32");
48
+ CallbackFactory callbackFactory = runtime.callbackFactory(Base32Module.class);
49
+ base32Module.defineModuleFunction("encode", callbackFactory.getSingletonMethod("encode", IRubyObject.class));
50
+ base32Module.defineModuleFunction("decode", callbackFactory.getSingletonMethod("decode", IRubyObject.class));
51
+ }
52
+ }
@@ -0,0 +1,39 @@
1
+ /*
2
+ Copyright (c) 2011 The Skunkworx
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the "Software"), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ */
22
+ package base32;
23
+
24
+
25
+ import java.io.IOException;
26
+ import org.jruby.Ruby;
27
+ import org.jruby.runtime.load.BasicLibraryService;
28
+
29
+ /**
30
+ * Primary interface to jruby for base32 encoding/decoding
31
+ *
32
+ * @author Chris Umbel
33
+ */
34
+ public class Base32Service implements BasicLibraryService {
35
+ public boolean basicLoad(Ruby runtime) throws IOException {
36
+ Base32Module.init(runtime);
37
+ return true;
38
+ }
39
+ }
@@ -0,0 +1,38 @@
1
+ # Copyright (c) 2011 The Skunkworx
2
+
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ # this software and associated documentation files (the "Software"), to deal in
5
+ # the Software without restriction, including without limitation the rights to
6
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ # of the Software, and to permit persons to whom the Software is furnished to do
8
+ # so, subject to the following conditions:
9
+
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require File.expand_path('../lib/base32/version', __FILE__)
22
+
23
+ Gem::Specification.new do |s|
24
+ s.name = 'jruby-base32'
25
+ s.version = Base32::VERSION
26
+ s.homepage = 'http://github.com/TheSkunkworx/jruby-base32'
27
+
28
+ s.authors = ['Chris Umbel']
29
+ s.email = ['chris@chrisumbel.com']
30
+
31
+ s.files = `git ls-files`.split("\n")
32
+ s.require_paths = ["lib"]
33
+
34
+ s.add_development_dependency('rspec')
35
+
36
+ s.summary = 'jruby, java extension port of the base32 gem'
37
+ s.description = 'jruby-base32 is a fast port of the base32 gem with the computation done in pure java.'
38
+ end
data/lib/base32.rb ADDED
@@ -0,0 +1,22 @@
1
+ # Copyright (c) 2011 The Skunkworx
2
+
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ # this software and associated documentation files (the "Software"), to deal in
5
+ # the Software without restriction, including without limitation the rights to
6
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ # of the Software, and to permit persons to whom the Software is furnished to do
8
+ # so, subject to the following conditions:
9
+
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'base32.jar'
22
+ require 'base32/base32'
@@ -0,0 +1,3 @@
1
+ module Base32
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,82 @@
1
+ # Copyright (c) 2011 The Skunkworx
2
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
3
+ # this software and associated documentation files (the "Software"), to deal in
4
+ # the Software without restriction, including without limitation the rights to
5
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
6
+ # of the Software, and to permit persons to whom the Software is furnished to do
7
+ # so, subject to the following conditions:
8
+
9
+ # The above copyright notice and this permission notice shall be included in all
10
+ # copies or substantial portions of the Software.
11
+
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18
+ # SOFTWARE.
19
+
20
+ require 'rubygems'
21
+ require File.dirname(__FILE__) + '/../lib/base32'
22
+
23
+ describe Base32 do
24
+ it 'should encode' do
25
+ Base32.encode('thin').should == 'ORUGS3Q='
26
+ Base32.encode('thin!').should == 'ORUGS3RB'
27
+ Base32.encode('pancetta').should == 'OBQW4Y3FOR2GC==='
28
+ Base32.encode('pancetta!').should == 'OBQW4Y3FOR2GCII='
29
+ Base32.encode('thin pancetta!').should == 'ORUGS3RAOBQW4Y3FOR2GCII='
30
+ end
31
+
32
+ it 'should decode' do
33
+ Base32.decode('ORUGS3Q=').should == 'thin'
34
+ Base32.decode('ORUGS3RB').should == 'thin!'
35
+ Base32.decode('OBQW4Y3FOR2GC===').should == 'pancetta'
36
+ Base32.decode('OBQW4Y3FOR2GCII=').should == 'pancetta!'
37
+ Base32.decode('ORUGS3RAOBQW4Y3FOR2GCII=').should == 'thin pancetta!'
38
+ end
39
+
40
+ it 'should encode then decode to same value' do
41
+ plaintext = 'thin pancetta!'
42
+ Base32.decode(Base32.encode(plaintext)).should == plaintext
43
+ end
44
+
45
+ it 'should handle empty strings' do
46
+ Base32.decode(Base32.encode('')).should == ''
47
+ end
48
+
49
+ it 'should always pad to octets' do
50
+ plaintext = ''
51
+
52
+ 256.times do |i|
53
+ plaintext << 'A'
54
+ (Base32.encode(plaintext).length % 8).should == 0
55
+ end
56
+ end
57
+
58
+ it 'should encode the preamble' do
59
+ #grabbed from stesla's tests
60
+
61
+ plaintext =<<-EOT
62
+ We the people of the United States, in order to form a more perfect union,
63
+ establish justice, insure domestic tranquility, provide for the common
64
+ defense, promote the general welfare, and secure the blessings of liberty
65
+ to ourselves and our posterity, do ordain and establish this Constitution
66
+ for the United States of America.
67
+ EOT
68
+
69
+ encoded = %W(
70
+ EAQCAIBAEBLWKIDUNBSSA4DFN5YGYZJAN5TCA5DIMUQFK3TJORSWIICTORQXIZLTFQQGS3RA
71
+ N5ZGIZLSEB2G6IDGN5ZG2IDBEBWW64TFEBYGK4TGMVRXIIDVNZUW63RMBIQCAIBAEAQGK43U
72
+ MFRGY2LTNAQGU5LTORUWGZJMEBUW443VOJSSAZDPNVSXG5DJMMQHI4TBNZYXK2LMNF2HSLBA
73
+ OBZG65TJMRSSAZTPOIQHI2DFEBRW63LNN5XAUIBAEAQCAIDEMVTGK3TTMUWCA4DSN5WW65DF
74
+ EB2GQZJAM5SW4ZLSMFWCA53FNRTGC4TFFQQGC3TEEBZWKY3VOJSSA5DIMUQGE3DFONZWS3TH
75
+ OMQG6ZRANRUWEZLSOR4QUIBAEAQCAIDUN4QG65LSONSWY5TFOMQGC3TEEBXXK4RAOBXXG5DF
76
+ OJUXI6JMEBSG6IDPOJSGC2LOEBQW4ZBAMVZXIYLCNRUXG2BAORUGS4ZAINXW443UNF2HK5DJ
77
+ N5XAUIBAEAQCAIDGN5ZCA5DIMUQFK3TJORSWIICTORQXIZLTEBXWMICBNVSXE2LDMEXAU===).join
78
+
79
+ Base32.encode(plaintext).should == encoded
80
+ end
81
+ end
82
+
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jruby-base32
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Chris Umbel
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-04-09 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ description: jruby-base32 is a fast port of the base32 gem with the computation done in pure java.
33
+ email:
34
+ - chris@chrisumbel.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ files:
42
+ - .gitignore
43
+ - LICENSE.txt
44
+ - README.rdoc
45
+ - Rakefile
46
+ - ext/java/base32/Base32Decoder.java
47
+ - ext/java/base32/Base32Encoder.java
48
+ - ext/java/base32/Base32Module.java
49
+ - ext/java/base32/Base32Service.java
50
+ - jruby-base32.gemspec
51
+ - lib/base32.rb
52
+ - lib/base32/version.rb
53
+ - spec/base32_spec.rb
54
+ - lib/base32.jar
55
+ has_rdoc: true
56
+ homepage: http://github.com/TheSkunkworx/jruby-base32
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.6
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: jruby, java extension port of the base32 gem
85
+ test_files: []
86
+