~ubuntu-branches/ubuntu/trusty/libauthen-sasl-cyrus-perl/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/Authen/SASL/Cyrus/Security.pm

  • Committer: Bazaar Package Importer
  • Author(s): Russ Allbery
  • Date: 2011-03-05 22:56:44 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110305225644-76yxl95fd1ek5c8t
Tags: 0.13-server-8
Explicitly set USER when running the test suite, since it may not be
set in a buildd environment.  This fix was accidentally dropped in
0.13-server-6.

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
# all the data to be encrypted is immediately available
74
74
sub WRITE {
75
75
  my($ref,$string,$len) = @_;
76
 
  my($fh, $clearbuf, $cryptbuf);
 
76
  my($fh, $clearbuf, $cryptbuf, $maxbuf);
77
77
 
78
78
  $fh = $ref->{fh};
79
79
  $clearbuf = substr($string, 0, $len);
80
 
  $cryptbuf = $ref->{conn}->encode($clearbuf);
81
 
  print $fh $cryptbuf;
 
80
  $len = length($clearbuf);
 
81
  $maxbuf = $ref->{conn}->property("maxout");
 
82
  if ($len < $maxbuf) {
 
83
    $cryptbuf = $ref->{conn}->encode($clearbuf);
 
84
    return(-1) if not defined ($cryptbuf);
 
85
  } else {
 
86
    my ($partial, $chunk, $chunksize);
 
87
    my $offset = 0;
 
88
    $cryptbuf = '';
 
89
    while ($offset < $len) {
 
90
      $chunksize = (($offset + $maxbuf) > $len) ? $len - $offset : $maxbuf;
 
91
      $chunk = substr($clearbuf, $offset, $chunksize);
 
92
      $partial = $ref->{conn}->encode($chunk);
 
93
      return(-1) if not defined ($partial);
 
94
      $cryptbuf .= $partial;
 
95
      $offset += $chunksize;
 
96
    }
 
97
  }
 
98
  return (print $fh $cryptbuf) ? $len : -1;
82
99
}
83
100
 
84
101
# Given a GLOB ref, tie the filehandle of the GLOB to this class