NAME

Net::SSH::Perl::Cipher - Base cipher class, plus utility methods

SYNOPSIS

use Net::SSH::Perl::Cipher;

# Get list of supported cipher IDs.
my $supported = Net::SSH::Perl::Cipher::supported();

# Translate a cipher name into an ID.
my $id = Net::SSH::Perl::Cipher::id($name);

# Translate a cipher ID into a name.
my $name = Net::SSH::Perl::Cipher::name($id);

DESCRIPTION

Net::SSH::Perl::Cipher provides a base class for each of the encryption cipher classes. In addition, it defines a set of utility methods that can be called either as functions or object methods.

UTILITY METHODS

supported( [ $ciph_id [, $server_supports ] ])

Without arguments, returns a reference to an array of ciphers supported by Net::SSH::Perl. These are ciphers that have working Net::SSH::Perl::Cipher:: implementations, essentially.

With one argument $ciph_id, returns a true value if that cipher is supported by Net::SSH::Perl, and false otherwise.

With two arguments, $ciph_id and $server_supports, returns true if the cipher represented by $ciph_id is supported both by Net::SSH::Perl and by the sshd server. The list of ciphers supported by the server should be in $server_supports, a bit mask sent from the server during the session identification phase.

Can be called either as a non-exported function, i.e.

my $i_support = Net::SSH::Perl::Cipher::supported();

or as an object method of a Net::SSH::Perl::Cipher object, or an object of a subclass:

if ($ciph->supported($server_supports)) {
    print "Server supports cipher $ciph";
}

id( [ $cipher_name ] )

Translates a cipher name into a cipher ID.

If given $cipher_name translates that name into the corresponding ID. If called as an object method, translates the object's cipher class name into the ID.

name( [ $cipher_id ] )

Translates a cipher ID into a cipher name.

If given $cipher_id translates that ID into the corresponding name. If called as an object method, returns the (stripped) object's cipher class name; for example, if the object were of type Net::SSH::Perl::Cipher::IDEA, name would return IDEA.

CIPHER USAGE

Net::SSH::Perl::Cipher->new($cipher_name, $key)

Instantiates a new cipher object of the type $cipher_name with the key $key; returns the cipher object, which will be blessed into the actual cipher subclass.

If $cipher_name is the special type 'None' (no encryption cipher), the object will actually be blessed directly into the base class, and text to be encrypted and decrypted will be passed through without change.

$cipher->encrypt($text)

Encrypts $text and returns the encrypted string.

$cipher->decrypt($text)

Decrypts $text and returns the decrypted string.

CIPHER DEVELOPMENT

Classes implementing an encryption cipher must implement the following three methods:

  • $class->new($key)

    Given a key $key, should construct a new cipher object and bless it into $class, presumably.

  • $cipher->encrypt($text)

    Given plain text $text, should encrypt the text and return the encrypted string.

  • $cipher->decrypt($text)

    Given encrypted text $text, should decrypt the text and return the decrypted string.

AUTHOR

Benjamin Trott, ben@rhumba.pair.com

COPYRIGHT

(C) 2001 Benjamin Trott. All rights reserved.