Class Net::SSH::Transport::CipherFactory
In: lib/net/ssh/transport/cipher_factory.rb
lib/net/ssh/transport/cipher_factory.rb
Parent: Object

Implements a factory of OpenSSL cipher algorithms.

Methods

Constants

SSH_TO_OSSL = { "3des-cbc" => "des-ede3-cbc", "blowfish-cbc" => "bf-cbc", "aes256-cbc" => "aes-256-cbc", "aes192-cbc" => "aes-192-cbc", "aes128-cbc" => "aes-128-cbc", "idea-cbc" => "idea-cbc", "cast128-cbc" => "cast-cbc", "rijndael-cbc@lysator.liu.se" => "aes-256-cbc", "none" => "none"   Maps the SSH name of a cipher to it‘s corresponding OpenSSL name
SSH_TO_OSSL = { "3des-cbc" => "des-ede3-cbc", "blowfish-cbc" => "bf-cbc", "aes256-cbc" => "aes-256-cbc", "aes192-cbc" => "aes-192-cbc", "aes128-cbc" => "aes-128-cbc", "idea-cbc" => "idea-cbc", "cast128-cbc" => "cast-cbc", "rijndael-cbc@lysator.liu.se" => "aes-256-cbc", "none" => "none"   Maps the SSH name of a cipher to it‘s corresponding OpenSSL name

Public Class methods

Retrieves a new instance of the named algorithm. The new instance will be initialized using an iv and key generated from the given iv, key, shared, hash and digester values. Additionally, the cipher will be put into encryption or decryption mode, based on the value of the encrypt parameter.

[Source]

    # File lib/net/ssh/transport/cipher_factory.rb, line 34
34:     def self.get(name, options={})
35:       ossl_name = SSH_TO_OSSL[name] or raise NotImplementedError, "unimplemented cipher `#{name}'"
36:       return IdentityCipher if ossl_name == "none"
37: 
38:       cipher = OpenSSL::Cipher::Cipher.new(ossl_name)
39:       cipher.send(options[:encrypt] ? :encrypt : :decrypt)
40: 
41:       cipher.padding = 0
42:       cipher.iv      = make_key(cipher.iv_len, options[:iv], options)
43:       cipher.key     = make_key(cipher.key_len, options[:key], options)
44: 
45:       return cipher
46:     end

Retrieves a new instance of the named algorithm. The new instance will be initialized using an iv and key generated from the given iv, key, shared, hash and digester values. Additionally, the cipher will be put into encryption or decryption mode, based on the value of the encrypt parameter.

[Source]

    # File lib/net/ssh/transport/cipher_factory.rb, line 34
34:     def self.get(name, options={})
35:       ossl_name = SSH_TO_OSSL[name] or raise NotImplementedError, "unimplemented cipher `#{name}'"
36:       return IdentityCipher if ossl_name == "none"
37: 
38:       cipher = OpenSSL::Cipher::Cipher.new(ossl_name)
39:       cipher.send(options[:encrypt] ? :encrypt : :decrypt)
40: 
41:       cipher.padding = 0
42:       cipher.iv      = make_key(cipher.iv_len, options[:iv], options)
43:       cipher.key     = make_key(cipher.key_len, options[:key], options)
44: 
45:       return cipher
46:     end

Returns a two-element array containing the [ key-length, block-size ] for the named cipher algorithm. If the cipher algorithm is unknown, or is "none", 0 is returned for both elements of the tuple.

[Source]

    # File lib/net/ssh/transport/cipher_factory.rb, line 52
52:     def self.get_lengths(name)
53:       ossl_name = SSH_TO_OSSL[name]
54:       return [0, 0] if ossl_name.nil? || ossl_name == "none"
55: 
56:       cipher = OpenSSL::Cipher::Cipher.new(ossl_name)
57:       return [cipher.key_len, cipher.block_size]
58:     end

Returns a two-element array containing the [ key-length, block-size ] for the named cipher algorithm. If the cipher algorithm is unknown, or is "none", 0 is returned for both elements of the tuple.

[Source]

    # File lib/net/ssh/transport/cipher_factory.rb, line 52
52:     def self.get_lengths(name)
53:       ossl_name = SSH_TO_OSSL[name]
54:       return [0, 0] if ossl_name.nil? || ossl_name == "none"
55: 
56:       cipher = OpenSSL::Cipher::Cipher.new(ossl_name)
57:       return [cipher.key_len, cipher.block_size]
58:     end

Returns true if the underlying OpenSSL library supports the given cipher, and false otherwise.

[Source]

    # File lib/net/ssh/transport/cipher_factory.rb, line 23
23:     def self.supported?(name)
24:       ossl_name = SSH_TO_OSSL[name] or raise NotImplementedError, "unimplemented cipher `#{name}'"
25:       return true if ossl_name == "none"
26:       return OpenSSL::Cipher.ciphers.include?(ossl_name)
27:     end

Returns true if the underlying OpenSSL library supports the given cipher, and false otherwise.

[Source]

    # File lib/net/ssh/transport/cipher_factory.rb, line 23
23:     def self.supported?(name)
24:       ossl_name = SSH_TO_OSSL[name] or raise NotImplementedError, "unimplemented cipher `#{name}'"
25:       return true if ossl_name == "none"
26:       return OpenSSL::Cipher.ciphers.include?(ossl_name)
27:     end

[Validate]