Net::NSS::SSL::LWPCompat - Wrapper for Net::NSS::SSL to make it LWP compatible


Crypt-NSS documentation Contained in the Crypt-NSS distribution.

Index


Code Index:

NAME

Top

Net::NSS::SSL::LWPCompat - Wrapper for Net::NSS::SSL to make it LWP compatible

SYNOPSIS

Top

  # Using NSS for SSL connections from LWP
  use LWP;
  use Crypt::NSS config_dir => "$ENV{HOME}/.netscape";
  use Net::HTTPS;

  local @Net::HTTPS::ISA = qw(Net::NSS::SSL::LWPCompat Net::HTTP::Methods);

  my $content = get("https://secure.mycompany.com");

INTERFACE

Top

CLASS METHODS

new ( $addr : string, %args )
new ( %args )

See new in Net::NSS::SSL

INSTANCE METHODS

get_cipher

get_cipher in Net::NSS::SSL

get_peer_certificate

get_peer_certificate in Net::NSS::SSL

peerhost

peerhost in Net::NSS::SSL

peerport

peerport in Net::NSS::SSL

sysread

sysread in Net::NSS::SSL

syswrite

syswrite in Net::NSS::SSL

can_read

Checks if there is data available to be read.

configure

Configures the socket, does nothing as this is done in the constructor.

blocking

Compat method that does nothing.


Crypt-NSS documentation Contained in the Crypt-NSS distribution.

package Net::NSS::SSL::LWPCompat;

use strict;
use warnings;

use Symbol;
use Net::NSS::SSL;

# Set up Net::HTTPS
$Net::HTTPS::SSL_SOCKET_CLASS = __PACKAGE__;

my %Socket;
sub new {
    my $pkg = shift;
    my %cnf = @_;
    my $socket = Net::NSS::SSL->new(%cnf);
    my $self = Symbol::gensym();
    bless $self, $pkg;
    $Socket{$self} = $socket;
    $self->configure(\%cnf);
    return $self;
}

sub configure {
    my $self = shift;
    return $self;
} 

# Noop since we set blocking in other way
sub blocking { 1 }; 

sub DESTROY {
    my $self = shift;
    delete $Socket{$self};
}

sub syswrite {
    my $self = shift;
    $Socket{$self}->syswrite(@_);
}

sub sysread {
    my $self = shift;
    $Socket{$self}->sysread($_[0], $_[1]);
}

sub can_read {
    my $self = shift;
    return $Socket{$self}->available > 0;
}

for my $meth (qw(peerhost peerport get_peer_certificate get_cipher)) {
    no strict 'refs';
    *$meth = sub {
        my $self = shift;
        $Socket{$self}->$meth();
    };
}

1;
__END__