<commit_before>package Crypt::OTR;

use 5.010000;
use strict;
use warnings;
use Carp;

use AutoLoader;

our $VERSION = '0.01';

sub AUTOLOAD {
    # This AUTOLOAD is used to 'autoload' constants from the constant()
    # XS function.

    my $constname;
    our $AUTOLOAD;
    ($constname = $AUTOLOAD) =~ s/.*:://;
    croak "&Crypt::OTR::constant not defined" if $constname eq 'constant';
    my ($error, $val) = constant($constname);
    if ($error) { croak $error; }
    {
	no strict 'refs';
	# Fixed between 5.005_53 and 5.005_61
#XXX	if ($] >= 5.00561) {
#XXX	    *$AUTOLOAD = sub () { $val };
#XXX	}
#XXX	else {
	    *$AUTOLOAD = sub { $val };
#XXX	}
    }
    goto &$AUTOLOAD;
}

require XSLoader;
XSLoader::load('Crypt::OTR', $VERSION);

#########################

=head1 NAME

Crypt::OTR - Do Off-The-Record message encryption

=head1 SYNOPSIS

    use Crypt::OTR;
    
    # call near the beginning of your program, should only be one per
    # process
    Crypt::OTR->init;

    # create OTR object, set up callbacks
    my $otr = new Crypt::OTR(
        account_name => "crypt_otr_user",    # name of account associated with this keypair
        protocol_name => "my_protocol_name", # e.g. 'AIM'
        max_message_size => 1024,            # how much to fragment
    );
    $otr->set_callback('inject' => \&otr_inject);
    $otr->set_callback('display' => \&otr_display);
    $otr->set_callback('connect' => \&otr_connect);
    $otr->set_callback('display' => \&otr_display);

    # create a context for user "alice"
    $otr->establish("alice");  # calls otr_inject($account_name, $protocol, $dest_account, $message)

    
    # CALLBACKS 
    #  (if writing a multithreaded application you will
    #   probably want to lock a mutex when sending/receiving)

    # called when OTR is ready to send a message after massaging it.
    # this method should transmit $message over a socket or somesuch
    sub otr_inject {
        my ($self, $account_name, $protocol, $dest_account, $message) = @_;
        $my_app->send_message_to_user($dest_account, $message);
    }

    # called after OTR has massaged an incoming message, possibly decrypting it
    sub otr_display {
        my ($self, $account_name, $protocol, $from_account, $message) = @_;
        $my_app->display_message($from_account, $message);
    }

    # called when a verified conversation is established with $from_account
    sub connect {
        my ($self, $from_account) = @_;
        print "Started verified conversation with $from_account\n";
    }

    # called when an unverified conversation is established with $from_account
    sub connect {
        my ($self, $from_account) = @_;
        print "Started unverified conversation with $from_account\n";
    }

<commit_msg>add more POD docs to Crypt::OTR<commit_after>package Crypt::OTR;

use 5.010000;
use strict;
use warnings;
use Carp;

use AutoLoader;

our $VERSION = '0.01';

sub AUTOLOAD {
    # This AUTOLOAD is used to 'autoload' constants from the constant()
    # XS function.

    my $constname;
    our $AUTOLOAD;
    ($constname = $AUTOLOAD) =~ s/.*:://;
    croak "&Crypt::OTR::constant not defined" if $constname eq 'constant';
    my ($error, $val) = constant($constname);
    if ($error) { croak $error; }
    {
	no strict 'refs';
	# Fixed between 5.005_53 and 5.005_61
#XXX	if ($] >= 5.00561) {
#XXX	    *$AUTOLOAD = sub () { $val };
#XXX	}
#XXX	else {
	    *$AUTOLOAD = sub { $val };
#XXX	}
    }
    goto &$AUTOLOAD;
}

require XSLoader;
XSLoader::load('Crypt::OTR', $VERSION);

#########################

=head1 NAME

Crypt::OTR - Do Off-The-Record message encryption

=head1 SYNOPSIS

    use Crypt::OTR;
    
    # call near the beginning of your program, should only be one per
    # process
    Crypt::OTR->init;

    # create OTR object, set up callbacks
    my $otr = new Crypt::OTR(
        account_name     => "alice",    # name of account associated with this keypair
        protocol_name    => "my_protocol_name", # e.g. 'AIM'
        max_message_size => 1024,            # how much to fragment
    );
    $otr->set_callback('inject' => \&otr_inject);
    $otr->set_callback('display' => \&otr_display);
    $otr->set_callback('connect' => \&otr_connect);
    $otr->set_callback('display' => \&otr_display);

    # create a context for user "bob"
    $otr->establish("bob");  # calls otr_inject($account_name, $protocol, $dest_account, $message)

    # send a message to bob
    my $plaintext = "hello, bob! this is a message from alice";
    if (my $ciphertext = $otr->encrypt("bob", $plaintext)) {
        $my_app->send_message_to_user("bob", $ciphertext);
    } else {
        warn "Your message was not sent - no encrypted conversation is established\n";
    }

    # called from bob's end
    if (my $plaintext = $otr->decrypt("alice", $ciphertext)) {
        print "alice: $plaintext\n";
    } else {
        warn "We received an encrypted message from alice but were unable to decrypt it\n";
    }

    # done with chats
    $otr->disconnect("bob");
    
    # CALLBACKS 
    #  (if writing a multithreaded application you will
    #   probably want to lock a mutex when sending/receiving)

    # called when OTR is ready to send a message after massaging it.
    # this method should transmit $message over a socket or somesuch
    sub otr_inject {
        my ($self, $account_name, $protocol, $dest_account, $message) = @_;
        $my_app->send_message_to_user($dest_account, $message);
    }

    # called after OTR has massaged an incoming message, possibly decrypting it
    sub otr_display {
        my ($self, $account_name, $protocol, $from_account, $message) = @_;
        $my_app->display_message($from_account, $message);
    }

    # called when a verified conversation is established with $from_account
    sub connect {
        my ($self, $from_account) = @_;
        print "Started verified conversation with $from_account\n";
    }

    # called when an unverified conversation is established with $from_account
    sub connect {
        my ($self, $from_account) = @_;
        print "Started unverified conversation with $from_account\n";
    }


{'fraction_non_alphanumeric': 0.1322906484196807, 'fraction_numerical': 0.011078527207559466, 'mean_word_length': 3.0414746543778803, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1439072', 'n_tokens_mistral': 2107, 'n_tokens_neox': 2009, 'n_words': 596}