ronin-support 0.1.0 → 0.2.0.rc1

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 (60) hide show
  1. data/ChangeLog.md +24 -0
  2. data/Gemfile +9 -1
  3. data/README.md +6 -3
  4. data/gemspec.yml +3 -1
  5. data/lib/ronin/extensions.rb +2 -1
  6. data/lib/ronin/extensions/file.rb +4 -0
  7. data/lib/ronin/extensions/ip_addr.rb +8 -0
  8. data/lib/ronin/extensions/kernel.rb +2 -0
  9. data/lib/ronin/extensions/string.rb +50 -11
  10. data/lib/ronin/formatting/extensions/binary.rb +2 -0
  11. data/lib/ronin/formatting/extensions/binary/file.rb +12 -1
  12. data/lib/ronin/formatting/extensions/binary/integer.rb +6 -0
  13. data/lib/ronin/formatting/extensions/binary/string.rb +20 -0
  14. data/lib/ronin/formatting/extensions/digest/file.rb +14 -0
  15. data/lib/ronin/formatting/extensions/digest/string.rb +8 -0
  16. data/lib/ronin/formatting/extensions/html.rb +21 -0
  17. data/lib/ronin/formatting/extensions/html/integer.rb +126 -0
  18. data/lib/ronin/formatting/extensions/html/string.rb +184 -0
  19. data/lib/ronin/formatting/extensions/http/integer.rb +7 -1
  20. data/lib/ronin/formatting/extensions/http/string.rb +10 -0
  21. data/lib/ronin/formatting/extensions/text.rb +2 -0
  22. data/lib/ronin/formatting/extensions/text/array.rb +10 -0
  23. data/lib/ronin/formatting/extensions/text/string.rb +44 -12
  24. data/lib/ronin/formatting/html.rb +20 -0
  25. data/lib/ronin/mixin.rb +89 -0
  26. data/lib/ronin/network/extensions/esmtp/net.rb +6 -0
  27. data/lib/ronin/network/extensions/http/net.rb +124 -51
  28. data/lib/ronin/network/extensions/imap/net.rb +4 -0
  29. data/lib/ronin/network/extensions/pop3/net.rb +4 -0
  30. data/lib/ronin/network/extensions/smtp/net.rb +73 -2
  31. data/lib/ronin/network/extensions/ssl/net.rb +4 -0
  32. data/lib/ronin/network/extensions/tcp/net.rb +16 -0
  33. data/lib/ronin/network/extensions/telnet/net.rb +4 -0
  34. data/lib/ronin/network/extensions/udp/net.rb +12 -0
  35. data/lib/ronin/network/http/http.rb +50 -29
  36. data/lib/ronin/network/http/proxy.rb +26 -0
  37. data/lib/ronin/network/imap.rb +4 -0
  38. data/lib/ronin/network/network.rb +2 -0
  39. data/lib/ronin/network/pop3.rb +4 -0
  40. data/lib/ronin/network/smtp/email.rb +43 -14
  41. data/lib/ronin/network/smtp/smtp.rb +6 -0
  42. data/lib/ronin/network/ssl.rb +2 -0
  43. data/lib/ronin/network/telnet.rb +16 -0
  44. data/lib/ronin/path.rb +6 -0
  45. data/lib/ronin/support/inflector.rb +3 -1
  46. data/lib/ronin/support/version.rb +1 -1
  47. data/lib/ronin/templates/erb.rb +4 -0
  48. data/lib/ronin/templates/template.rb +10 -0
  49. data/spec/extensions/string_spec.rb +4 -4
  50. data/spec/formatting/html/integer_spec.rb +66 -0
  51. data/spec/formatting/html/string_spec.rb +103 -0
  52. data/spec/formatting/http/string_spec.rb +1 -1
  53. data/spec/formatting/text/string_spec.rb +18 -66
  54. data/spec/mixin_spec.rb +53 -0
  55. data/spec/network/http/http_spec.rb +0 -7
  56. data/spec/network/http/proxy_spec.rb +2 -2
  57. data/spec/network/smtp/email_spec.rb +100 -0
  58. data/spec/path_spec.rb +13 -13
  59. data/spec/templates/helpers/data.rb +1 -1
  60. metadata +52 -33
@@ -31,6 +31,8 @@ class String
31
31
  # "hello".md5
32
32
  # # => "5d41402abc4b2a76b9719d911017c592"
33
33
  #
34
+ # @api public
35
+ #
34
36
  def md5
35
37
  Digest::MD5.hexdigest(self)
36
38
  end
@@ -43,6 +45,8 @@ class String
43
45
  # "hello".sha1
44
46
  # # => "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d"
45
47
  #
48
+ # @api public
49
+ #
46
50
  def sha1
47
51
  Digest::SHA1.hexdigest(self)
48
52
  end
@@ -57,6 +61,8 @@ class String
57
61
  # "hello".sha2
58
62
  # # => "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
59
63
  #
64
+ # @api public
65
+ #
60
66
  def sha256
61
67
  Digest::SHA256.hexdigest(self)
62
68
  end
@@ -71,6 +77,8 @@ class String
71
77
  # "hello".sha512
72
78
  # # => "9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043"
73
79
  #
80
+ # @api public
81
+ #
74
82
  def sha512
75
83
  Digest::SHA512.hexdigest(self)
76
84
  end
@@ -0,0 +1,21 @@
1
+ #
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin Support.
5
+ #
6
+ # Ronin Support is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin Support is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/formatting/extensions/html/integer'
21
+ require 'ronin/formatting/extensions/html/string'
@@ -0,0 +1,126 @@
1
+ #
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin Support.
5
+ #
6
+ # Ronin Support is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin Support is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'cgi'
21
+
22
+ class Integer
23
+
24
+ # Special JavaScript bytes and their escaped Strings.
25
+ JS_ESCAPE_BYTES = {
26
+ 0x00 => '%u0000',
27
+ 0x01 => '%u0001',
28
+ 0x02 => '%u0002',
29
+ 0x03 => '%u0003',
30
+ 0x04 => '%u0004',
31
+ 0x05 => '%u0005',
32
+ 0x06 => '%u0006',
33
+ 0x07 => '%u0007',
34
+ 0x08 => '\b',
35
+ 0x09 => '\t',
36
+ 0x0a => '\n',
37
+ 0x0b => '%u000b',
38
+ 0x0c => '\f',
39
+ 0x0d => '\r',
40
+ 0x0e => '%u000e',
41
+ 0x0f => '%u000f',
42
+ 0x10 => '%u0010',
43
+ 0x11 => '%u0011',
44
+ 0x12 => '%u0012',
45
+ 0x13 => '%u0013',
46
+ 0x14 => '%u0014',
47
+ 0x15 => '%u0015',
48
+ 0x16 => '%u0016',
49
+ 0x17 => '%u0017',
50
+ 0x18 => '%u0018',
51
+ 0x19 => '%u0019',
52
+ 0x1a => '%u001a',
53
+ 0x1b => '%u001b',
54
+ 0x1c => '%u001c',
55
+ 0x1d => '%u001d',
56
+ 0x1e => '%u001e',
57
+ 0x1f => '%u001f',
58
+ 0x22 => '\"',
59
+ 0x5c => '\\\\',
60
+ }
61
+
62
+ #
63
+ # Escapes the Integer as an HTML String.
64
+ #
65
+ # @return [String]
66
+ # The escaped HTML String.
67
+ #
68
+ # @since 0.2.0
69
+ #
70
+ # @api public
71
+ #
72
+ def html_escape
73
+ CGI.escapeHTML(self.chr)
74
+ end
75
+
76
+ #
77
+ # Formats the Integer as a HTML String.
78
+ #
79
+ # @return [String]
80
+ # The HTML String.
81
+ #
82
+ # @since 0.2.0
83
+ #
84
+ # @api public
85
+ #
86
+ def format_html
87
+ "&#%d;" % self
88
+ end
89
+
90
+ #
91
+ # Escapes the Integer as a JavaScript String.
92
+ #
93
+ # @return [String]
94
+ # The escaped JavaScript String.
95
+ #
96
+ # @since 0.2.0
97
+ #
98
+ # @api public
99
+ #
100
+ def js_escape
101
+ if self > 0xff
102
+ format_js
103
+ else
104
+ JS_ESCAPE_BYTES.fetch(self,self.chr)
105
+ end
106
+ end
107
+
108
+ #
109
+ # Formats the Integer as a JavaScript escaped String.
110
+ #
111
+ # @return [String]
112
+ # The escaped JavaScript String.
113
+ #
114
+ # @since 0.2.0
115
+ #
116
+ # @api public
117
+ #
118
+ def format_js
119
+ if self > 0xff
120
+ "%%u%.2X%.2X" % [(self & 0xff00) >> 8, (self & 0xff)]
121
+ else
122
+ "%%%.2X" % self
123
+ end
124
+ end
125
+
126
+ end
@@ -0,0 +1,184 @@
1
+ #
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin Support.
5
+ #
6
+ # Ronin Support is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin Support is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/formatting/extensions/html/integer'
21
+ require 'ronin/formatting/extensions/text/string'
22
+
23
+ require 'cgi'
24
+
25
+ class String
26
+
27
+ # JavaScript characters that must be back-slashed.
28
+ JS_BACKSLASHED_CHARS = {
29
+ "\\b" => "\b",
30
+ "\\t" => "\t",
31
+ "\\n" => "\n",
32
+ "\\f" => "\f",
33
+ "\\r" => "\r",
34
+ "\\\"" => "\"",
35
+ "\\\\" => "\\"
36
+ }
37
+
38
+ #
39
+ # HTML escapes the String.
40
+ #
41
+ # @return [String]
42
+ # The HTML escaped String.
43
+ #
44
+ # @see http://rubydoc.info/stdlib/cgi/1.9.2/CGI.escapeHTML
45
+ #
46
+ # @since 0.2.0
47
+ #
48
+ # @api public
49
+ #
50
+ def html_escape
51
+ CGI.escapeHTML(self)
52
+ end
53
+
54
+ #
55
+ # Unescapes the HTML encoded String.
56
+ #
57
+ # @return [String]
58
+ # The unescaped String.
59
+ #
60
+ # @see http://rubydoc.info/stdlib/cgi/1.9.2/CGI.unescapeHTML
61
+ #
62
+ # @since 0.2.0
63
+ #
64
+ # @api public
65
+ #
66
+ def html_unescape
67
+ CGI.unescapeHTML(self)
68
+ end
69
+
70
+ #
71
+ # Formats the chars in the String for HTML.
72
+ #
73
+ # @param [Hash] options
74
+ # Additional options for {#format_chars}.
75
+ #
76
+ # @return [String]
77
+ # The formatted HTML String.
78
+ #
79
+ # @see Integer#format_html
80
+ #
81
+ # @since 0.2.0
82
+ #
83
+ # @api public
84
+ #
85
+ def format_html(options={})
86
+ if RUBY_VERSION < '1.9.'
87
+ # String#ord was not backported to Rub 1.8.7
88
+ format_chars(options) { |c| c[0].format_html }
89
+ else
90
+ format_chars(options) { |c| c.ord.format_html }
91
+ end
92
+ end
93
+
94
+ #
95
+ # Escapes a String for JavaScript.
96
+ #
97
+ # @param [Hash] options
98
+ # Additional options for {#format_chars}.
99
+ #
100
+ # @return [String]
101
+ # The JavaScript escaped String.
102
+ #
103
+ # @example
104
+ # "hello".js_escape
105
+ # # => "%u0068%u0065%u006C%u006C%u006F"
106
+ #
107
+ # @see Integer#js_escape
108
+ #
109
+ # @since 0.2.0
110
+ #
111
+ # @api public
112
+ #
113
+ def js_escape(options={})
114
+ if RUBY_VERSION < '1.9.'
115
+ # String#ord was not backported to Rub 1.8.7
116
+ format_chars(options) { |c| c[0].js_escape }
117
+ else
118
+ format_chars(options) { |c| c.ord.js_escape }
119
+ end
120
+ end
121
+
122
+ #
123
+ # Unescapes a JavaScript escaped String.
124
+ #
125
+ # @return [String]
126
+ # The unescaped JavaScript String.
127
+ #
128
+ # @example
129
+ # "%u0068%u0065%u006C%u006C%u006F world".js_unescape
130
+ # # => "hello world"
131
+ #
132
+ # @since 0.2.0
133
+ #
134
+ # @api public
135
+ #
136
+ def js_unescape
137
+ unescaped = ''
138
+
139
+ scan(/([\\%]u[0-9a-fA-F]{4}|[\\%][0-9a-fA-F]{2}|\\[btnfr"\\]|.)/).each do |match|
140
+ c = match[0]
141
+
142
+ if c.length == 6
143
+ unescaped << c[2,4].to_i(16)
144
+ elsif c.length == 3
145
+ unescaped << c[1,2].to_i(16)
146
+ elsif c.length == 2
147
+ unescaped << JS_BACKSLASHED_CHARS[c]
148
+ else
149
+ unescaped << c
150
+ end
151
+ end
152
+
153
+ return unescaped
154
+ end
155
+
156
+ #
157
+ # Escapes a String for JavaScript.
158
+ #
159
+ # @param [Hash] options
160
+ # Additional options for {#format_chars}.
161
+ #
162
+ # @return [String]
163
+ # The JavaScript escaped String.
164
+ #
165
+ # @example
166
+ # "hello".js_escape
167
+ # # => "%u0068%u0065%u006C%u006C%u006F"
168
+ #
169
+ # @see Integer#js_escape
170
+ #
171
+ # @since 0.2.0
172
+ #
173
+ # @api public
174
+ #
175
+ def format_js(options={})
176
+ if RUBY_VERSION < '1.9.'
177
+ # String#ord was not backported to Rub 1.8.7
178
+ format_chars(options) { |c| c[0].format_js }
179
+ else
180
+ format_chars(options) { |c| c.ord.format_js }
181
+ end
182
+ end
183
+
184
+ end
@@ -28,6 +28,8 @@ class Integer
28
28
  # @return [String]
29
29
  # The URI encoded byte.
30
30
  #
31
+ # @api public
32
+ #
31
33
  def uri_encode
32
34
  URI.encode(self.chr)
33
35
  end
@@ -38,6 +40,8 @@ class Integer
38
40
  # @return [String]
39
41
  # The URI escaped byte.
40
42
  #
43
+ # @api public
44
+ #
41
45
  def uri_escape
42
46
  CGI.escape(self.chr)
43
47
  end
@@ -48,8 +52,10 @@ class Integer
48
52
  # @return [String]
49
53
  # The formatted byte.
50
54
  #
55
+ # @api public
56
+ #
51
57
  def format_http
52
- "%%%x" % self
58
+ "%%%X" % self
53
59
  end
54
60
 
55
61
  end
@@ -35,6 +35,8 @@ class String
35
35
  # "art is graffiti".uri_encode
36
36
  # # => "art%20is%20graffiti"
37
37
  #
38
+ # @api public
39
+ #
38
40
  def uri_encode
39
41
  URI.encode(self)
40
42
  end
@@ -49,6 +51,8 @@ class String
49
51
  # "genre%3f".uri_decode
50
52
  # # => "genre?"
51
53
  #
54
+ # @api public
55
+ #
52
56
  def uri_decode
53
57
  URI.decode(self)
54
58
  end
@@ -63,6 +67,8 @@ class String
63
67
  # "x > y".uri_escape
64
68
  # # => "x+%3E+y"
65
69
  #
70
+ # @api public
71
+ #
66
72
  def uri_escape
67
73
  CGI.escape(self)
68
74
  end
@@ -77,6 +83,8 @@ class String
77
83
  # "sweet+%26+sour".uri_unescape
78
84
  # # => "sweet & sour"
79
85
  #
86
+ # @api public
87
+ #
80
88
  def uri_unescape
81
89
  CGI.unescape(self)
82
90
  end
@@ -93,6 +101,8 @@ class String
93
101
  #
94
102
  # @see String#format_bytes
95
103
  #
104
+ # @api public
105
+ #
96
106
  def format_http(options={})
97
107
  format_bytes(options) { |b| b.format_http }
98
108
  end
@@ -19,3 +19,5 @@
19
19
 
20
20
  require 'ronin/formatting/extensions/text/string'
21
21
  require 'ronin/formatting/extensions/text/array'
22
+
23
+ require 'chars/extensions'