Class Net::SSH::Transport::OSSL::CipherFactory
In: lib/net/ssh/transport/ossl/cipher-factory.rb
Parent: Object

Implements a factory of OpenSSL cipher algorithms.

Methods

get   get_lengths   new  

Attributes

identity_cipher  [W]  The accessor for setting the identity cipher implementation to use.

Public Class methods

Create a new CipherFactory instance that uses the given Hash-like to convert SSH2 cipher algorithm names to OpenSSL cipher algorithm names.

[Source]

    # File lib/net/ssh/transport/ossl/cipher-factory.rb, line 35
35:           def initialize( cipher_map )
36:             @cipher_map = cipher_map
37:           end

Public Instance 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/ossl/cipher-factory.rb, line 44
44:           def get( name,
45:                    iv=nil, key=nil,
46:                    shared=nil, hash=nil,
47:                    digester=nil,
48:                    encrypt=false )
49:           # begin
50:             ossl_name = @cipher_map.fetch( name ) do
51:               raise CipherNotFound, name
52:             end
53: 
54:             return @identity_cipher if ossl_name == "none"
55: 
56:             cipher = OpenSSL::Cipher::Cipher.new( ossl_name )
57:             cipher.send( encrypt ? :encrypt : :decrypt )
58: 
59:             cipher.padding = 0
60:             cipher.iv = make_key( cipher.iv_len, iv, shared, hash, digester )
61:             cipher.key = make_key( cipher.key_len, key, shared, hash, digester )
62: 
63:             return cipher
64:           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/ossl/cipher-factory.rb, line 70
70:           def get_lengths( name )
71:             ossl_name = @cipher_map[ name ]
72:             return [ 0, 0 ] if ossl_name.nil? || ossl_name == "none"
73: 
74:             cipher = OpenSSL::Cipher::Cipher.new( ossl_name )
75:             return [ cipher.key_len, cipher.block_size ]
76:           end

[Validate]