hrr_rb_ssh 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/demo/server.rb +23 -3
  4. data/hrr_rb_ssh.gemspec +2 -2
  5. data/lib/hrr_rb_ssh/authentication/method/method.rb +34 -0
  6. data/lib/hrr_rb_ssh/authentication/method/none.rb +5 -14
  7. data/lib/hrr_rb_ssh/authentication/method/password.rb +6 -12
  8. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/algorithm.rb +41 -0
  9. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/codable.rb +33 -0
  10. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_dss.rb +105 -0
  11. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm/ssh_rsa.rb +85 -0
  12. data/lib/hrr_rb_ssh/authentication/method/publickey/algorithm.rb +28 -0
  13. data/lib/hrr_rb_ssh/authentication/method/publickey.rb +9 -25
  14. data/lib/hrr_rb_ssh/authentication/method.rb +12 -9
  15. data/lib/hrr_rb_ssh/connection/channel/channel_type/channel_type.rb +30 -0
  16. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/env/context.rb +46 -0
  17. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/env.rb +34 -0
  18. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec/context.rb +44 -0
  19. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec.rb +34 -0
  20. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req/context.rb +54 -0
  21. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req.rb +34 -0
  22. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type.rb +34 -0
  23. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell/context.rb +41 -0
  24. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell.rb +34 -0
  25. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem/context.rb +44 -0
  26. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem.rb +34 -0
  27. data/lib/hrr_rb_ssh/connection/channel/channel_type/session/request_type.rb +33 -0
  28. data/lib/hrr_rb_ssh/connection/channel/channel_type/session.rb +30 -0
  29. data/lib/hrr_rb_ssh/connection/channel/channel_type.rb +25 -0
  30. data/lib/hrr_rb_ssh/connection/channel.rb +2 -12
  31. data/lib/hrr_rb_ssh/transport/compression_algorithm/compression_algorithm.rb +34 -0
  32. data/lib/hrr_rb_ssh/transport/compression_algorithm/functionable.rb +31 -0
  33. data/lib/hrr_rb_ssh/transport/compression_algorithm/none.rb +7 -19
  34. data/lib/hrr_rb_ssh/transport/compression_algorithm/unfunctionable.rb +20 -0
  35. data/lib/hrr_rb_ssh/transport/compression_algorithm/zlib.rb +7 -24
  36. data/lib/hrr_rb_ssh/transport/compression_algorithm.rb +11 -9
  37. data/lib/hrr_rb_ssh/transport/direction.rb +11 -0
  38. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes128_cbc.rb +19 -0
  39. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes128_ctr.rb +19 -0
  40. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes192_cbc.rb +19 -0
  41. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes192_ctr.rb +19 -0
  42. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes256_cbc.rb +19 -0
  43. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes256_ctr.rb +19 -0
  44. data/lib/hrr_rb_ssh/transport/encryption_algorithm/arcfour.rb +19 -0
  45. data/lib/hrr_rb_ssh/transport/encryption_algorithm/blowfish_cbc.rb +19 -0
  46. data/lib/hrr_rb_ssh/transport/encryption_algorithm/cast128_cbc.rb +19 -0
  47. data/lib/hrr_rb_ssh/transport/encryption_algorithm/encryption_algorithm.rb +34 -0
  48. data/lib/hrr_rb_ssh/transport/encryption_algorithm/functionable.rb +61 -0
  49. data/lib/hrr_rb_ssh/transport/encryption_algorithm/none.rb +6 -33
  50. data/lib/hrr_rb_ssh/transport/encryption_algorithm/three_des_cbc.rb +19 -0
  51. data/lib/hrr_rb_ssh/transport/encryption_algorithm/unfunctionable.rb +35 -0
  52. data/lib/hrr_rb_ssh/transport/encryption_algorithm.rb +20 -9
  53. data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman.rb +3 -4
  54. data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group14_sha1.rb +4 -8
  55. data/lib/hrr_rb_ssh/transport/kex_algorithm/diffie_hellman_group1_sha1.rb +4 -8
  56. data/lib/hrr_rb_ssh/transport/kex_algorithm/kex_algorithm.rb +34 -0
  57. data/lib/hrr_rb_ssh/transport/kex_algorithm.rb +10 -9
  58. data/lib/hrr_rb_ssh/transport/mac_algorithm/functionable.rb +32 -0
  59. data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_md5.rb +21 -0
  60. data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_md5_96.rb +21 -0
  61. data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_sha1.rb +5 -29
  62. data/lib/hrr_rb_ssh/transport/mac_algorithm/hmac_sha1_96.rb +21 -0
  63. data/lib/hrr_rb_ssh/transport/mac_algorithm/mac_algorithm.rb +34 -0
  64. data/lib/hrr_rb_ssh/transport/mac_algorithm/none.rb +6 -22
  65. data/lib/hrr_rb_ssh/transport/mac_algorithm/unfunctionable.rb +24 -0
  66. data/lib/hrr_rb_ssh/transport/mac_algorithm.rb +14 -9
  67. data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/server_host_key_algorithm.rb +34 -0
  68. data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_dss.rb +106 -0
  69. data/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ssh_rsa.rb +4 -11
  70. data/lib/hrr_rb_ssh/transport/server_host_key_algorithm.rb +10 -8
  71. data/lib/hrr_rb_ssh/transport.rb +23 -15
  72. data/lib/hrr_rb_ssh/version.rb +1 -1
  73. metadata +51 -17
  74. data/lib/hrr_rb_ssh/authentication/method/publickey/ssh_rsa.rb +0 -116
  75. data/lib/hrr_rb_ssh/connection/channel/session/env/context.rb +0 -43
  76. data/lib/hrr_rb_ssh/connection/channel/session/env.rb +0 -31
  77. data/lib/hrr_rb_ssh/connection/channel/session/exec/context.rb +0 -41
  78. data/lib/hrr_rb_ssh/connection/channel/session/exec.rb +0 -31
  79. data/lib/hrr_rb_ssh/connection/channel/session/pty_req/context.rb +0 -50
  80. data/lib/hrr_rb_ssh/connection/channel/session/pty_req.rb +0 -31
  81. data/lib/hrr_rb_ssh/connection/channel/session/shell/context.rb +0 -37
  82. data/lib/hrr_rb_ssh/connection/channel/session/shell.rb +0 -31
  83. data/lib/hrr_rb_ssh/connection/channel/session/subsystem/context.rb +0 -40
  84. data/lib/hrr_rb_ssh/connection/channel/session/subsystem.rb +0 -31
  85. data/lib/hrr_rb_ssh/connection/channel/session.rb +0 -31
  86. data/lib/hrr_rb_ssh/transport/encryption_algorithm/aes_128_cbc.rb +0 -73
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/logger'
5
+ require 'hrr_rb_ssh/connection/request_handler'
6
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type'
7
+
8
+ module HrrRbSsh
9
+ class Connection
10
+ class Channel
11
+ module ChannelType
12
+ class Session
13
+ module RequestType
14
+ class Env < RequestType
15
+ NAME = 'env'
16
+
17
+ def self.run proc_chain, username, io, variables, message, options
18
+ logger = HrrRbSsh::Logger.new self.class.name
19
+
20
+ context = Context.new proc_chain, username, io, variables, message
21
+ handler = options.fetch('connection_channel_request_env', RequestHandler.new {})
22
+ handler.run context
23
+
24
+ proc_chain.connect context.chain_proc
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/env/context'
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/logger'
5
+
6
+ module HrrRbSsh
7
+ class Connection
8
+ class Channel
9
+ module ChannelType
10
+ class Session
11
+ module RequestType
12
+ class Exec
13
+ class Context
14
+ attr_reader \
15
+ :logger,
16
+ :username,
17
+ :io,
18
+ :variables,
19
+ :vars,
20
+ :command
21
+
22
+ def initialize proc_chain, username, io, variables, message
23
+ @logger = HrrRbSsh::Logger.new self.class.name
24
+
25
+ @proc_chain = proc_chain
26
+ @username = username
27
+ @io = io
28
+ @variables = variables
29
+ @vars = variables
30
+
31
+ @command = message['command']
32
+ end
33
+
34
+ def chain_proc &block
35
+ @proc = block || @proc
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/logger'
5
+ require 'hrr_rb_ssh/connection/request_handler'
6
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type'
7
+
8
+ module HrrRbSsh
9
+ class Connection
10
+ class Channel
11
+ module ChannelType
12
+ class Session
13
+ module RequestType
14
+ class Exec < RequestType
15
+ NAME = 'exec'
16
+
17
+ def self.run proc_chain, username, io, variables, message, options
18
+ logger = HrrRbSsh::Logger.new self.class.name
19
+
20
+ context = Context.new proc_chain, username, io, variables, message
21
+ handler = options.fetch('connection_channel_request_exec', RequestHandler.new {})
22
+ handler.run context
23
+
24
+ proc_chain.connect context.chain_proc
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec/context'
@@ -0,0 +1,54 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/logger'
5
+
6
+ module HrrRbSsh
7
+ class Connection
8
+ class Channel
9
+ module ChannelType
10
+ class Session
11
+ module RequestType
12
+ class PtyReq
13
+ class Context
14
+ attr_reader \
15
+ :logger,
16
+ :username,
17
+ :io,
18
+ :variables,
19
+ :vars,
20
+ :term_environment_variable_value,
21
+ :terminal_width_characters,
22
+ :terminal_height_rows,
23
+ :terminal_width_pixels,
24
+ :terminal_height_pixels,
25
+ :encoded_terminal_modes
26
+
27
+ def initialize proc_chain, username, io, variables, message
28
+ @logger = HrrRbSsh::Logger.new self.class.name
29
+
30
+ @proc_chain = proc_chain
31
+ @username = username
32
+ @io = io
33
+ @variables = variables
34
+ @vars = variables
35
+
36
+ @term_environment_variable_value = message['TERM environment variable value']
37
+ @terminal_width_characters = message['terminal width, characters']
38
+ @terminal_height_rows = message['terminal height, rows']
39
+ @terminal_width_pixels = message['terminal width, pixels']
40
+ @terminal_height_pixels = message['terminal height, pixels']
41
+ @encoded_terminal_modes = message['encoded terminal modes']
42
+ end
43
+
44
+ def chain_proc &block
45
+ @proc = block || @proc
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/logger'
5
+ require 'hrr_rb_ssh/connection/request_handler'
6
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type'
7
+
8
+ module HrrRbSsh
9
+ class Connection
10
+ class Channel
11
+ module ChannelType
12
+ class Session
13
+ module RequestType
14
+ class PtyReq < RequestType
15
+ NAME = 'pty-req'
16
+
17
+ def self.run proc_chain, username, io, variables, message, options
18
+ logger = HrrRbSsh::Logger.new self.class.name
19
+
20
+ context = Context.new proc_chain, username, io, variables, message
21
+ handler = options.fetch('connection_channel_request_pty_req', RequestHandler.new {})
22
+ handler.run context
23
+
24
+ proc_chain.connect context.chain_proc
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req/context'
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ module HrrRbSsh
5
+ class Connection
6
+ class Channel
7
+ module ChannelType
8
+ class Session
9
+ module RequestType
10
+ class RequestType
11
+ @@list = Array.new
12
+
13
+ def self.inherited klass
14
+ @@list.push klass
15
+ end
16
+
17
+ def self.list
18
+ @@list
19
+ end
20
+
21
+ def self.name_list
22
+ @@list.map{ |klass| klass::NAME }
23
+ end
24
+
25
+ def self.[] key
26
+ @@list.find{ |klass| key == klass::NAME }
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/logger'
5
+
6
+ module HrrRbSsh
7
+ class Connection
8
+ class Channel
9
+ module ChannelType
10
+ class Session
11
+ module RequestType
12
+ class Shell
13
+ class Context
14
+ attr_reader \
15
+ :logger,
16
+ :username,
17
+ :io,
18
+ :variables,
19
+ :vars
20
+
21
+ def initialize proc_chain, username, io, variables, message
22
+ @logger = HrrRbSsh::Logger.new self.class.name
23
+
24
+ @proc_chain = proc_chain
25
+ @username = username
26
+ @io = io
27
+ @variables = variables
28
+ @vars = variables
29
+ end
30
+
31
+ def chain_proc &block
32
+ @proc = block || @proc
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/logger'
5
+ require 'hrr_rb_ssh/connection/request_handler'
6
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type'
7
+
8
+ module HrrRbSsh
9
+ class Connection
10
+ class Channel
11
+ module ChannelType
12
+ class Session
13
+ module RequestType
14
+ class Shell < RequestType
15
+ NAME = 'shell'
16
+
17
+ def self.run proc_chain, username, io, variables, message, options
18
+ logger = HrrRbSsh::Logger.new self.class.name
19
+
20
+ context = Context.new proc_chain, username, io, variables, message
21
+ handler = options.fetch('connection_channel_request_shell', RequestHandler.new {})
22
+ handler.run context
23
+
24
+ proc_chain.connect context.chain_proc
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell/context'
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/logger'
5
+
6
+ module HrrRbSsh
7
+ class Connection
8
+ class Channel
9
+ module ChannelType
10
+ class Session
11
+ module RequestType
12
+ class Subsystem
13
+ class Context
14
+ attr_reader \
15
+ :logger,
16
+ :username,
17
+ :io,
18
+ :variables,
19
+ :vars,
20
+ :subsystem_name
21
+
22
+ def initialize proc_chain, username, io, variables, message
23
+ @logger = HrrRbSsh::Logger.new self.class.name
24
+
25
+ @proc_chain = proc_chain
26
+ @username = username
27
+ @io = io
28
+ @variables = variables
29
+ @vars = variables
30
+
31
+ @subsystem_name = message['subsystem name']
32
+ end
33
+
34
+ def chain_proc &block
35
+ @proc = block || @proc
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/logger'
5
+ require 'hrr_rb_ssh/connection/request_handler'
6
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type'
7
+
8
+ module HrrRbSsh
9
+ class Connection
10
+ class Channel
11
+ module ChannelType
12
+ class Session
13
+ module RequestType
14
+ class Subsystem < RequestType
15
+ NAME = 'subsystem'
16
+
17
+ def self.run proc_chain, username, io, variables, message, options
18
+ logger = HrrRbSsh::Logger.new self.class.name
19
+
20
+ context = Context.new proc_chain, username, io, variables, message
21
+ handler = options.fetch('connection_channel_request_subsystem', RequestHandler.new {})
22
+ handler.run context
23
+
24
+ proc_chain.connect context.chain_proc
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem/context'
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ module HrrRbSsh
5
+ class Connection
6
+ class Channel
7
+ module ChannelType
8
+ class Session
9
+ module RequestType
10
+ def self.list
11
+ RequestType.list
12
+ end
13
+
14
+ def self.name_list
15
+ RequestType.name_list
16
+ end
17
+
18
+ def self.[] key
19
+ RequestType[key]
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/request_type'
29
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/pty_req'
30
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/env'
31
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/shell'
32
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/exec'
33
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type/subsystem'
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/connection/channel/channel_type/channel_type'
5
+
6
+ module HrrRbSsh
7
+ class Connection
8
+ class Channel
9
+ module ChannelType
10
+ class Session < ChannelType
11
+ NAME = 'session'
12
+
13
+ def self.list
14
+ RequestType.list
15
+ end
16
+
17
+ def self.name_list
18
+ RequestType.name_list
19
+ end
20
+
21
+ def self.[] key
22
+ RequestType[key]
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ require 'hrr_rb_ssh/connection/channel/channel_type/session/request_type'
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ module HrrRbSsh
5
+ class Connection
6
+ class Channel
7
+ module ChannelType
8
+ def self.list
9
+ ChannelType.list
10
+ end
11
+
12
+ def self.name_list
13
+ ChannelType.name_list
14
+ end
15
+
16
+ def self.[] key
17
+ ChannelType[key]
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ require 'hrr_rb_ssh/connection/channel/channel_type/channel_type'
25
+ require 'hrr_rb_ssh/connection/channel/channel_type/session'
@@ -4,21 +4,11 @@
4
4
  require 'socket'
5
5
  require 'hrr_rb_ssh/logger'
6
6
  require 'hrr_rb_ssh/connection/channel/proc_chain'
7
- require 'hrr_rb_ssh/connection/channel/session'
7
+ require 'hrr_rb_ssh/connection/channel/channel_type'
8
8
 
9
9
  module HrrRbSsh
10
10
  class Connection
11
11
  class Channel
12
- @@type_list ||= Hash.new
13
-
14
- def self.[] key
15
- @@type_list[key]
16
- end
17
-
18
- def self.type_list
19
- @@type_list.keys
20
- end
21
-
22
12
  INITIAL_WINDOW_SIZE = 100000
23
13
  MAXIMUM_PACKET_SIZE = 100000
24
14
 
@@ -219,7 +209,7 @@ module HrrRbSsh
219
209
 
220
210
  def request message, variables
221
211
  request_type = message['request type']
222
- @@type_list[@channel_type][request_type].run @proc_chain, @connection.username, @request_handler_io, variables, message, @connection.options
212
+ ChannelType[@channel_type][request_type].run @proc_chain, @connection.username, @request_handler_io, variables, message, @connection.options
223
213
  end
224
214
 
225
215
  def send_channel_success
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/logger'
5
+
6
+ module HrrRbSsh
7
+ class Transport
8
+ class CompressionAlgorithm
9
+ class CompressionAlgorithm
10
+ @@list = Array.new
11
+
12
+ def self.inherited klass
13
+ @@list.push klass
14
+ end
15
+
16
+ def self.list
17
+ @@list
18
+ end
19
+
20
+ def self.name_list
21
+ @@list.map{ |klass| klass::NAME }
22
+ end
23
+
24
+ def self.[] key
25
+ @@list.find{ |klass| key == klass::NAME }
26
+ end
27
+
28
+ def initialize direction
29
+ @logger = HrrRbSsh::Logger.new self.class.name
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'zlib'
5
+
6
+ module HrrRbSsh
7
+ class Transport
8
+ class CompressionAlgorithm
9
+ module Functionable
10
+ def initialize direction
11
+ super
12
+
13
+ case direction
14
+ when HrrRbSsh::Transport::Direction::OUTGOING
15
+ @deflator = ::Zlib::Deflate.new
16
+ when HrrRbSsh::Transport::Direction::INCOMING
17
+ @inflator = ::Zlib::Inflate.new
18
+ end
19
+ end
20
+
21
+ def deflate data
22
+ @deflator.deflate(data, ::Zlib::SYNC_FLUSH)
23
+ end
24
+
25
+ def inflate data
26
+ @inflator.inflate(data)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,32 +1,20 @@
1
1
  # coding: utf-8
2
2
  # vim: et ts=2 sw=2
3
3
 
4
- require 'hrr_rb_ssh/logger'
4
+ require 'hrr_rb_ssh/transport/compression_algorithm/compression_algorithm'
5
+ require 'hrr_rb_ssh/transport/compression_algorithm/unfunctionable'
5
6
 
6
7
  module HrrRbSsh
7
8
  class Transport
8
9
  class CompressionAlgorithm
9
- name_list = [
10
- 'none'
11
- ]
10
+ class None < CompressionAlgorithm
11
+ NAME = 'none'
12
12
 
13
- class None
14
- def initialize
15
- @logger = HrrRbSsh::Logger.new self.class.name
13
+ def initialize direction=nil
14
+ super
16
15
  end
17
16
 
18
- def deflate data
19
- data
20
- end
21
-
22
- def inflate data
23
- data
24
- end
25
- end
26
-
27
- @@list ||= Hash.new
28
- name_list.each do |name|
29
- @@list[name] = None
17
+ include Unfunctionable
30
18
  end
31
19
  end
32
20
  end
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_ssh/logger'
5
+
6
+ module HrrRbSsh
7
+ class Transport
8
+ class CompressionAlgorithm
9
+ module Unfunctionable
10
+ def deflate data
11
+ data
12
+ end
13
+
14
+ def inflate data
15
+ data
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end