| 1 | # ABSTRACT: Off-the-Record secure messaging protocol | ||||||||||
| 2 | package Protocol::OTR; | ||||||||||
| 3 | 8 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 8 | $Protocol::OTR::AUTHORITY = 'cpan:AJGB'; | |||||||||
| 5 | } | ||||||||||
| 6 | 8 | $Protocol::OTR::VERSION = '0.05'; | |||||||||
| 7 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 8 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 8 | ▶ | use Alien::OTR; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 8 | ▶ | use Alien::GCrypt; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 8 | ▶ | use Alien::GPG::Error; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 8 | ▶ | use Carp qw( croak ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 8 | ▶ | use Protocol::OTR::Account (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 8 | ▶ | use Params::Validate qw(validate validate_pos SCALAR); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 8 | require Exporter; | |||||||||
| 18 | |||||||||||
| 19 | 8 | require XSLoader; | |||||||||
| 20 | |||||||||||
| 21 | 8 | our @ISA = qw(Exporter); | |||||||||
| 22 | |||||||||||
| 23 | 8 | our %EXPORT_TAGS = ( | |||||||||
| 24 | 'policies' => [ qw( | ||||||||||
| 25 | POLICY_OPPORTUNISTIC | ||||||||||
| 26 | POLICY_ALWAYS | ||||||||||
| 27 | ) ], | ||||||||||
| 28 | 'error_codes' => [ qw( | ||||||||||
| 29 | ERRCODE_NONE | ||||||||||
| 30 | ERRCODE_ENCRYPTION_ERROR | ||||||||||
| 31 | ERRCODE_MSG_NOT_IN_PRIVATE | ||||||||||
| 32 | ERRCODE_MSG_UNREADABLE | ||||||||||
| 33 | ERRCODE_MSG_MALFORMED | ||||||||||
| 34 | ) ], | ||||||||||
| 35 | 'event_codes' => [ qw( | ||||||||||
| 36 | MSGEVENT_NONE | ||||||||||
| 37 | MSGEVENT_ENCRYPTION_REQUIRED | ||||||||||
| 38 | MSGEVENT_ENCRYPTION_ERROR | ||||||||||
| 39 | MSGEVENT_CONNECTION_ENDED | ||||||||||
| 40 | MSGEVENT_SETUP_ERROR | ||||||||||
| 41 | MSGEVENT_MSG_REFLECTED | ||||||||||
| 42 | MSGEVENT_MSG_RESENT | ||||||||||
| 43 | MSGEVENT_RCVDMSG_NOT_IN_PRIVATE | ||||||||||
| 44 | MSGEVENT_RCVDMSG_UNREADABLE | ||||||||||
| 45 | MSGEVENT_RCVDMSG_MALFORMED | ||||||||||
| 46 | MSGEVENT_LOG_HEARTBEAT_RCVD | ||||||||||
| 47 | MSGEVENT_LOG_HEARTBEAT_SENT | ||||||||||
| 48 | MSGEVENT_RCVDMSG_GENERAL_ERR | ||||||||||
| 49 | MSGEVENT_RCVDMSG_UNENCRYPTED | ||||||||||
| 50 | MSGEVENT_RCVDMSG_UNRECOGNIZED | ||||||||||
| 51 | MSGEVENT_RCVDMSG_FOR_OTHER_INSTANCE | ||||||||||
| 52 | ) ], | ||||||||||
| 53 | 'smp_event_codes' => [ qw( | ||||||||||
| 54 | SMPEVENT_NONE | ||||||||||
| 55 | SMPEVENT_CHEATED | ||||||||||
| 56 | SMPEVENT_IN_PROGRESS | ||||||||||
| 57 | SMPEVENT_SUCCESS | ||||||||||
| 58 | SMPEVENT_FAILURE | ||||||||||
| 59 | SMPEVENT_ABORT | ||||||||||
| 60 | SMPEVENT_ERROR | ||||||||||
| 61 | ) ], | ||||||||||
| 62 | 'instags' => [ qw( | ||||||||||
| 63 | INSTAG_BEST | ||||||||||
| 64 | INSTAG_RECENT | ||||||||||
| 65 | INSTAG_RECENT_RECEIVED | ||||||||||
| 66 | INSTAG_RECENT_SENT | ||||||||||
| 67 | ) ], | ||||||||||
| 68 | ); | ||||||||||
| 69 | $EXPORT_TAGS{'constants'} = [ | ||||||||||
| 70 | 8 | map { @$_ } @EXPORT_TAGS{qw(policies error_codes event_codes smp_event_codes instags)} | |||||||||
| 71 | ]; | ||||||||||
| 72 | |||||||||||
| 73 | 8 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'constants'} } ); | |||||||||
| 74 | |||||||||||
| 75 | 8 | our @EXPORT = qw(); | |||||||||
| 76 | |||||||||||
| 77 | XSLoader::load('Protocol::OTR', $Protocol::OTR::{VERSION} ? | ||||||||||
| 78 | 8 | ▶ | ${ $Protocol::OTR::{VERSION} } : () | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | ); | ||||||||||
| 80 | |||||||||||
| 81 | 5 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 82 | 5 | my $class = shift; | |||||||||
| 83 | |||||||||||
| 84 | 5 | my %args = validate( | |||||||||
| 85 | @_, | ||||||||||
| 86 | { | ||||||||||
| 87 | privkeys_file => { | ||||||||||
| 88 | type => SCALAR, | ||||||||||
| 89 | optional => 1, | ||||||||||
| 90 | default => 'otr.privkey', | ||||||||||
| 91 | }, | ||||||||||
| 92 | contacts_file => { | ||||||||||
| 93 | type => SCALAR, | ||||||||||
| 94 | optional => 1, | ||||||||||
| 95 | default => 'otr.fingerprints', | ||||||||||
| 96 | }, | ||||||||||
| 97 | instance_tags_file => { | ||||||||||
| 98 | type => SCALAR, | ||||||||||
| 99 | optional => 1, | ||||||||||
| 100 | default => 'otr.instance_tags', | ||||||||||
| 101 | }, | ||||||||||
| 102 | } | ||||||||||
| 103 | ); | ||||||||||
| 104 | |||||||||||
| 105 | my $self = Protocol::OTR::_new( | ||||||||||
| 106 | 4 | @args{qw(privkeys_file contacts_file instance_tags_file)} | |||||||||
| 107 | ); | ||||||||||
| 108 | |||||||||||
| 109 | 4 | return $self; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 6 | ▶ | sub account { | ||||||||
|
Subroutine
account: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 113 | 6 | my $self = shift; | |||||||||
| 114 | |||||||||||
| 115 | 6 | my ($name, $protocol) = validate_pos( | |||||||||
| 116 | @_, | ||||||||||
| 117 | { | ||||||||||
| 118 | type => SCALAR, | ||||||||||
| 119 | }, | ||||||||||
| 120 | { | ||||||||||
| 121 | type => SCALAR, | ||||||||||
| 122 | } | ||||||||||
| 123 | ); | ||||||||||
| 124 | |||||||||||
| 125 | 4 | return Protocol::OTR::Account->_new( | |||||||||
| 126 | $self, | ||||||||||
| 127 | { | ||||||||||
| 128 | name => $name, | ||||||||||
| 129 | protocol => $protocol, | ||||||||||
| 130 | } | ||||||||||
| 131 | ); | ||||||||||
| 132 | } | ||||||||||
| 133 | |||||||||||
| 134 | 1 | ▶ | sub accounts { | ||||||||
|
Subroutine
accounts: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 135 | 1 | my ($self) = @_; | |||||||||
| 136 | |||||||||||
| 137 | return map { | ||||||||||
| 138 | 1 | Protocol::OTR::Account->_new($self, $_) | |||||||||
| 139 | 1 | } @{ $self->_accounts() } | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | 3 | ▶ | sub find_account { | ||||||||
|
Subroutine
find_account: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 143 | 3 | my $self = shift; | |||||||||
| 144 | |||||||||||
| 145 | 3 | my ($name, $protocol) = validate_pos( | |||||||||
| 146 | @_, | ||||||||||
| 147 | { | ||||||||||
| 148 | type => SCALAR, | ||||||||||
| 149 | }, | ||||||||||
| 150 | { | ||||||||||
| 151 | type => SCALAR, | ||||||||||
| 152 | } | ||||||||||
| 153 | ); | ||||||||||
| 154 | |||||||||||
| 155 | 1 | return Protocol::OTR::Account->_new( | |||||||||
| 156 | $self, | ||||||||||
| 157 | { | ||||||||||
| 158 | name => $name, | ||||||||||
| 159 | protocol => $protocol, | ||||||||||
| 160 | }, | ||||||||||
| 161 | 1, # find only | ||||||||||
| 162 | ); | ||||||||||
| 163 | } | ||||||||||
| 164 | |||||||||||
| 165 | 8 | 1; | |||||||||
| 166 | |||||||||||
| 167 | __END__ | ||||||||||