Protocol-OTR

 view release on metacpan or  search on metacpan

lib/Protocol/OTR/Channel.pm  view on Meta::CPAN

}
$Protocol::OTR::Channel::VERSION = '0.05';
use strict;
use warnings;
use Scalar::Util ();
use Protocol::OTR ();

sub _new {
    my ($class, $cnt, $args) = @_;

    $args->{selected_instag} = Protocol::OTR::INSTAG_BEST();
    $args->{known_sessions} = {};
    $args->{gone_secure} = 0;

    my $self = bless $args, $class;
    $self->{cnt} = $cnt;

    return $self;
}

sub account {
    return $_[0]->{cnt}->{act};
}

sub contact {
    return $_[0]->{cnt};
}

sub _ev {
    my ($self, $cb_name) = (shift, shift);

    {
        Scalar::Util::weaken(my $this = $self);
        $this->{$cb_name}->($this, @_);
    }
}


1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Protocol::OTR::Channel - Off-the-Record communication Channel

=head1 VERSION

version 0.05

=head1 SYNOPSIS

    use Protocol::OTR qw( :constants );

    my $otr = Protocol::OTR->new(
        {
            privkeys_file => "otr.private_key",
            contacts_file => "otr.fingerprints",
            instance_tags_file => "otr.instance_tags",
        }
    );

    # find or create account
    my $alice = $otr->account('alice@domain', 'prpl-jabber');

    # find or create contact known by $alice
    my $bob = $alice->contact('bob@domain');

    # create secure channel to Bob
    my $channel = $bob->channel(
        {
            policy => ...,
            max_message_size => ...,
            on_write => sub { ... },
            on_read => sub { ... },
            on_gone_secure => sub { ... },
            on_gone_insecure => sub { ... },
            on_still_secure => sub { ... },
            on_unverified_fingerprint => sub { ... },
            on_symkey => sub { ... },
            on_timer => sub { ... },
            on_smp => sub { ... },
            on_error => sub { ... },
            on_event => sub { ... },
            on_smp_event => sub { ... },
            on_before_encrypt => sub { ... },
            on_after_decrypt => sub { ... },
            on_is_contact_logged_in => sub { ... },
        }
    );

=head1 DESCRIPTION

L<Protocol::OTR::Channel> represents the OTR communication channel.

=head1 METHODS

=head2 account

    my $account = $channel->account();

Returns channel's L<Protocol::OTR::Account> object.

=head2 contact

    my $contact = $channel->contact();

Returns channel's L<Protocol::OTR::Contact> object.

=head2 init

    $channel->init();

Send OTR default query message to initialize secure session.

    '<b>'. $channel->account->name .'</b> has requested an '
   .'<a href="http://otr.cypherpunks.ca/">Off-the-Record '



( run in 1.262 second using v1.01-cache-2.11-cpan-39bf76dae61 )