blackbox 1.0.0

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.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +374 -0
  6. data/README.md +34 -0
  7. data/Rakefile +31 -0
  8. data/blackbox.gemspec +25 -0
  9. data/coverage/.last_run.json +5 -0
  10. data/coverage/.resultset.json +323 -0
  11. data/coverage/assets/0.7.1/application.css +1110 -0
  12. data/coverage/assets/0.7.1/application.js +626 -0
  13. data/coverage/assets/0.7.1/fancybox/blank.gif +0 -0
  14. data/coverage/assets/0.7.1/fancybox/fancy_close.png +0 -0
  15. data/coverage/assets/0.7.1/fancybox/fancy_loading.png +0 -0
  16. data/coverage/assets/0.7.1/fancybox/fancy_nav_left.png +0 -0
  17. data/coverage/assets/0.7.1/fancybox/fancy_nav_right.png +0 -0
  18. data/coverage/assets/0.7.1/fancybox/fancy_shadow_e.png +0 -0
  19. data/coverage/assets/0.7.1/fancybox/fancy_shadow_n.png +0 -0
  20. data/coverage/assets/0.7.1/fancybox/fancy_shadow_ne.png +0 -0
  21. data/coverage/assets/0.7.1/fancybox/fancy_shadow_nw.png +0 -0
  22. data/coverage/assets/0.7.1/fancybox/fancy_shadow_s.png +0 -0
  23. data/coverage/assets/0.7.1/fancybox/fancy_shadow_se.png +0 -0
  24. data/coverage/assets/0.7.1/fancybox/fancy_shadow_sw.png +0 -0
  25. data/coverage/assets/0.7.1/fancybox/fancy_shadow_w.png +0 -0
  26. data/coverage/assets/0.7.1/fancybox/fancy_title_left.png +0 -0
  27. data/coverage/assets/0.7.1/fancybox/fancy_title_main.png +0 -0
  28. data/coverage/assets/0.7.1/fancybox/fancy_title_over.png +0 -0
  29. data/coverage/assets/0.7.1/fancybox/fancy_title_right.png +0 -0
  30. data/coverage/assets/0.7.1/fancybox/fancybox-x.png +0 -0
  31. data/coverage/assets/0.7.1/fancybox/fancybox-y.png +0 -0
  32. data/coverage/assets/0.7.1/fancybox/fancybox.png +0 -0
  33. data/coverage/assets/0.7.1/favicon_green.png +0 -0
  34. data/coverage/assets/0.7.1/favicon_red.png +0 -0
  35. data/coverage/assets/0.7.1/favicon_yellow.png +0 -0
  36. data/coverage/assets/0.7.1/loading.gif +0 -0
  37. data/coverage/assets/0.7.1/magnify.png +0 -0
  38. data/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  39. data/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  40. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  41. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  42. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  43. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  44. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  45. data/coverage/assets/0.7.1/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  46. data/coverage/assets/0.7.1/smoothness/images/ui-icons_222222_256x240.png +0 -0
  47. data/coverage/assets/0.7.1/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  48. data/coverage/assets/0.7.1/smoothness/images/ui-icons_454545_256x240.png +0 -0
  49. data/coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png +0 -0
  50. data/coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  51. data/coverage/index.html +2080 -0
  52. data/doc/BB.html +129 -0
  53. data/doc/BB/Crypto.html +1145 -0
  54. data/doc/BB/Hash.html +441 -0
  55. data/doc/BB/String.html +240 -0
  56. data/doc/_index.html +155 -0
  57. data/doc/class_list.html +53 -0
  58. data/doc/css/common.css +1 -0
  59. data/doc/css/full_list.css +57 -0
  60. data/doc/css/style.css +338 -0
  61. data/doc/file.README.html +104 -0
  62. data/doc/file_list.html +55 -0
  63. data/doc/frames.html +28 -0
  64. data/doc/index.html +104 -0
  65. data/doc/js/app.js +214 -0
  66. data/doc/js/full_list.js +173 -0
  67. data/doc/js/jquery.js +4 -0
  68. data/doc/method_list.html +124 -0
  69. data/doc/top-level-namespace.html +112 -0
  70. data/lib/blackbox.rb +4 -0
  71. data/lib/blackbox/crypto.rb +99 -0
  72. data/lib/blackbox/hash.rb +49 -0
  73. data/lib/blackbox/string.rb +17 -0
  74. data/lib/blackbox/version.rb +3 -0
  75. data/spec/blackbox_spec.rb +9 -0
  76. data/spec/crypto_spec.rb +70 -0
  77. data/spec/hash_spec.rb +51 -0
  78. data/spec/spec_helper.rb +4 -0
  79. data/spec/string_spec.rb +13 -0
  80. metadata +184 -0
@@ -0,0 +1,49 @@
1
+ module BB
2
+ # Hash utilities.
3
+ module Hash
4
+ class << self
5
+ # Symbolize all top level keys.
6
+ #
7
+ # @param [Hash] hash Input hash
8
+ # @return [Hash] Output hash (with symbolized keys)
9
+ def symbolize_keys(hash)
10
+ hash.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
11
+ end
12
+
13
+ # Recursively flatten a hash to property-style format.
14
+ # This is a lossy conversion and should only be used for display-purposes.
15
+ #
16
+ # @example
17
+ # input = { :a => { :b => :c } }
18
+ # BB::Hash.flatten_prop_style(input)
19
+ # => {"a.b"=>:c}
20
+ #
21
+ # @example
22
+ # input = { :a => { :b => [:c, :d, :e] } }
23
+ # BB::Hash.flatten_prop_style(input)
24
+ # => {"a.b"=>"c,d,e"}
25
+ #
26
+ # @param [Hash] input Input hash
27
+ # @param [Hash] opts Options
28
+ # @option opts [String] :delimiter
29
+ # Key delimiter (Default: '.')
30
+ # @param [Hash] output (leave this blank)
31
+ # @return [Hash] Output hash (flattened)
32
+ def flatten_prop_style(input={}, opts={}, output={})
33
+ input.each do |key, value|
34
+ key = opts[:prefix].nil? ? "#{key}" : "#{opts[:prefix]}#{opts[:delimiter]||"."}#{key}"
35
+ case value
36
+ when ::Hash
37
+ flatten_prop_style(value, {:prefix => key, :delimiter => "."}, output)
38
+ when Array
39
+ output[key] = value.join(',')
40
+ else
41
+ output[key] = value
42
+ end
43
+ end
44
+ output
45
+ end
46
+ end
47
+ end
48
+ end
49
+
@@ -0,0 +1,17 @@
1
+ module BB
2
+ # String utilities.
3
+ module String
4
+ class << self
5
+ # Strip ANSI escape sequences from String.
6
+ #
7
+ # @param [String] text Input string (dirty)
8
+ # @return [String] Output string (cleaned)
9
+ def strip_ansi(text)
10
+ text.gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '').
11
+ gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '').
12
+ gsub(/(\x03|\x1a)/, '')
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,3 @@
1
+ module BB
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+ require 'blackbox/version'
3
+
4
+ describe BB do
5
+ it 'should have a version number' do
6
+ BB::VERSION.should_not be_nil
7
+ end
8
+ end
9
+
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'blackbox/crypto'
3
+ require 'base64'
4
+
5
+ OPENSSL_CIPHERS = %w[aes-128-cbc aes-128-ecb aes-192-cbc aes-192-ecb aes-256-cbc]+
6
+ %w[aes-256-ecb bf bf-cbc bf-cfb]+
7
+ %w[bf-ecb bf-ofb cast cast-cbc cast5-cbc]+
8
+ %w[cast5-cfb cast5-ecb cast5-ofb des des-cbc]+
9
+ %w[des-cfb des-ecb des-ede des-ede-cbc des-ede-cfb]+
10
+ %w[des-ede-ofb des-ede3 des-ede3-cbc des-ede3-cfb des-ede3-ofb]+
11
+ %w[des-ofb des3 desx rc2 rc2-40-cbc]+
12
+ %w[rc2-64-cbc rc2-cbc rc2-cfb rc2-ecb rc2-ofb]+
13
+ %w[rc4 rc4-40]
14
+
15
+ TEST_KEY='12345678901234567890123456789012'
16
+ TEST_IV ='x234567890123456789012345678901x'
17
+ TEST_TEXT_SHORT='[SHORT_TEST]'*16
18
+ TEST_TEXT_LONG='[LONG_TEST]'*8192
19
+
20
+ describe BB::Crypto do
21
+ OPENSSL_CIPHERS.each do |cipher|
22
+ describe "#{cipher}" do
23
+ [[:encrypt, :decrypt],
24
+ [:encrypt_base64, :decrypt_base64],
25
+ [:encrypt_urlsafe_base64, :decrypt_urlsafe_base64]].each do |e|
26
+ m_enc, m_dec = e
27
+ describe "#{m_enc}, #{m_dec}" do
28
+ it "can decrypt what it encrypted (short string, random iv)" do
29
+ ct = BB::Crypto.send(m_enc, TEST_TEXT_SHORT, TEST_KEY, cipher)
30
+ pt = BB::Crypto.send(m_dec, ct, TEST_KEY, cipher)
31
+ pt.should == TEST_TEXT_SHORT
32
+ end
33
+
34
+ it "can decrypt what it encrypted (long string, random iv)" do
35
+ ct = BB::Crypto.send(m_enc, TEST_TEXT_LONG, TEST_KEY, cipher)
36
+ pt = BB::Crypto.send(m_dec, ct, TEST_KEY, cipher)
37
+ pt.should == TEST_TEXT_LONG
38
+ end
39
+
40
+ it "can decrypt what it encrypted (long string, static iv)" do
41
+ ct = BB::Crypto.send(m_enc, TEST_TEXT_LONG, TEST_KEY, cipher, TEST_IV)
42
+ pt = BB::Crypto.send(m_dec, ct, TEST_KEY, cipher, TEST_IV)
43
+ pt.should == TEST_TEXT_LONG
44
+ end
45
+
46
+ it "returns consistent output with static iv" do
47
+ a = BB::Crypto.send(m_enc, TEST_TEXT_SHORT, TEST_KEY, cipher, TEST_IV)
48
+ b = BB::Crypto.send(m_enc, TEST_TEXT_SHORT, TEST_KEY, cipher, TEST_IV)
49
+ a.should == b
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "encrypt_base64" do
55
+ it "returns base64 string" do
56
+ ct = BB::Crypto.encrypt_base64(TEST_TEXT_LONG, TEST_KEY)
57
+ Base64.decode64(ct)
58
+ end
59
+ end
60
+
61
+ describe "encrypt_urlsafe_base64" do
62
+ it "returns urlsafe base64 string" do
63
+ ct = BB::Crypto.encrypt_urlsafe_base64(TEST_TEXT_LONG, TEST_KEY)
64
+ Base64.urlsafe_decode64(ct)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'blackbox/hash'
3
+
4
+ describe BB::Hash do
5
+ describe '.symbolize_keys' do
6
+ it "turns all keys into symbols" do
7
+ have = { 'foo' => 1, :bar => 2, 'batz' => 3 }
8
+ want = { :foo => 1, :bar => 2, :batz => 3 }
9
+ BB::Hash.symbolize_keys(have).should == want
10
+ end
11
+
12
+ it "raises NoMethodError when #to_sym fails for a key" do
13
+ lambda {
14
+ have = { 'foo' => 1, 2 => 2, :bar => 3 }
15
+ BB::Hash.symbolize_keys(have)
16
+ }.should raise_error NoMethodError
17
+ end
18
+ end
19
+
20
+ describe ".flatten_prop_style" do
21
+ it "returns flattened hash" do
22
+ have = {
23
+ :a=> 1,
24
+ 'b' => 2,
25
+ 3 => 3,
26
+ :array => [1,2,3],
27
+ 'nested' => { 'a' => 1, :b => 2, :c => 3 },
28
+ :double_nested => { :a => { :aa => 1 }, :b => { :bb => 2 }, :c => { :cc => 3 } },
29
+ :nested_with_array => { :a => { :aa => [:a, 'b', 3] }, :b => { :bb => [:a, 'b', 3] }, :c => { :cc => [:a, 'b', 3] } }
30
+ }
31
+
32
+ want = {
33
+ "a"=>1,
34
+ "b"=>2,
35
+ "3"=>3,
36
+ "array"=>"1,2,3",
37
+ "nested.a"=>1,
38
+ "nested.b"=>2,
39
+ "nested.c"=>3,
40
+ "double_nested.a.aa"=>1,
41
+ "double_nested.b.bb"=>2,
42
+ "double_nested.c.cc"=>3,
43
+ "nested_with_array.a.aa"=>"a,b,3",
44
+ "nested_with_array.b.bb"=>"a,b,3",
45
+ "nested_with_array.c.cc"=>"a,b,3"
46
+ }
47
+ BB::Hash::flatten_prop_style(have).should == want
48
+ end
49
+ end
50
+ end
51
+
@@ -0,0 +1,4 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'blackbox/string'
3
+
4
+ describe BB::String do
5
+ describe '.strip_ansi' do
6
+ it "strips a few common escape sequences" do
7
+ have = "\e[31;1mX\e[AY\e[2JZ"
8
+ want = "XYZ"
9
+ BB::String.strip_ansi(have).should == want
10
+ end
11
+ end
12
+ end
13
+
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blackbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Moe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: simplecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redcarpet
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Various little helpers
70
+ email:
71
+ - moe@busyloop.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - blackbox.gemspec
83
+ - coverage/.last_run.json
84
+ - coverage/.resultset.json
85
+ - coverage/assets/0.7.1/application.css
86
+ - coverage/assets/0.7.1/application.js
87
+ - coverage/assets/0.7.1/fancybox/blank.gif
88
+ - coverage/assets/0.7.1/fancybox/fancy_close.png
89
+ - coverage/assets/0.7.1/fancybox/fancy_loading.png
90
+ - coverage/assets/0.7.1/fancybox/fancy_nav_left.png
91
+ - coverage/assets/0.7.1/fancybox/fancy_nav_right.png
92
+ - coverage/assets/0.7.1/fancybox/fancy_shadow_e.png
93
+ - coverage/assets/0.7.1/fancybox/fancy_shadow_n.png
94
+ - coverage/assets/0.7.1/fancybox/fancy_shadow_ne.png
95
+ - coverage/assets/0.7.1/fancybox/fancy_shadow_nw.png
96
+ - coverage/assets/0.7.1/fancybox/fancy_shadow_s.png
97
+ - coverage/assets/0.7.1/fancybox/fancy_shadow_se.png
98
+ - coverage/assets/0.7.1/fancybox/fancy_shadow_sw.png
99
+ - coverage/assets/0.7.1/fancybox/fancy_shadow_w.png
100
+ - coverage/assets/0.7.1/fancybox/fancy_title_left.png
101
+ - coverage/assets/0.7.1/fancybox/fancy_title_main.png
102
+ - coverage/assets/0.7.1/fancybox/fancy_title_over.png
103
+ - coverage/assets/0.7.1/fancybox/fancy_title_right.png
104
+ - coverage/assets/0.7.1/fancybox/fancybox-x.png
105
+ - coverage/assets/0.7.1/fancybox/fancybox-y.png
106
+ - coverage/assets/0.7.1/fancybox/fancybox.png
107
+ - coverage/assets/0.7.1/favicon_green.png
108
+ - coverage/assets/0.7.1/favicon_red.png
109
+ - coverage/assets/0.7.1/favicon_yellow.png
110
+ - coverage/assets/0.7.1/loading.gif
111
+ - coverage/assets/0.7.1/magnify.png
112
+ - coverage/assets/0.7.1/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
113
+ - coverage/assets/0.7.1/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
114
+ - coverage/assets/0.7.1/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
115
+ - coverage/assets/0.7.1/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
116
+ - coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_dadada_1x400.png
117
+ - coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
118
+ - coverage/assets/0.7.1/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
119
+ - coverage/assets/0.7.1/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
120
+ - coverage/assets/0.7.1/smoothness/images/ui-icons_222222_256x240.png
121
+ - coverage/assets/0.7.1/smoothness/images/ui-icons_2e83ff_256x240.png
122
+ - coverage/assets/0.7.1/smoothness/images/ui-icons_454545_256x240.png
123
+ - coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png
124
+ - coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png
125
+ - coverage/index.html
126
+ - doc/BB.html
127
+ - doc/BB/Crypto.html
128
+ - doc/BB/Hash.html
129
+ - doc/BB/String.html
130
+ - doc/_index.html
131
+ - doc/class_list.html
132
+ - doc/css/common.css
133
+ - doc/css/full_list.css
134
+ - doc/css/style.css
135
+ - doc/file.README.html
136
+ - doc/file_list.html
137
+ - doc/frames.html
138
+ - doc/index.html
139
+ - doc/js/app.js
140
+ - doc/js/full_list.js
141
+ - doc/js/jquery.js
142
+ - doc/method_list.html
143
+ - doc/top-level-namespace.html
144
+ - lib/blackbox.rb
145
+ - lib/blackbox/crypto.rb
146
+ - lib/blackbox/hash.rb
147
+ - lib/blackbox/string.rb
148
+ - lib/blackbox/version.rb
149
+ - spec/blackbox_spec.rb
150
+ - spec/crypto_spec.rb
151
+ - spec/hash_spec.rb
152
+ - spec/spec_helper.rb
153
+ - spec/string_spec.rb
154
+ homepage: https://github.com/busyloop/blackbox
155
+ licenses:
156
+ - MPL 2.0
157
+ metadata: {}
158
+ post_install_message:
159
+ rdoc_options: []
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ requirements: []
173
+ rubyforge_project:
174
+ rubygems_version: 2.0.0
175
+ signing_key:
176
+ specification_version: 4
177
+ summary: Various little helpers
178
+ test_files:
179
+ - spec/blackbox_spec.rb
180
+ - spec/crypto_spec.rb
181
+ - spec/hash_spec.rb
182
+ - spec/spec_helper.rb
183
+ - spec/string_spec.rb
184
+ has_rdoc: