/usr/lib/x86_64-linux-gnu/perl5/5.20/AnyEvent/Util/idna.pl is in libanyevent-perl 7.070-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | # based on RFC 3492
use AnyEvent (); BEGIN { AnyEvent::common_sense }
use Carp ();
use List::Util ();
use integer;
sub pyc_base () { 36 }
sub pyc_tmin () { 1 }
sub pyc_tmax () { 26 }
sub pyc_initial_bias () { 72 }
sub pyc_initial_n () { 128 }
sub pyc_digits () { "abcdefghijklmnopqrstuvwxyz0123456789" }
sub pyc_adapt($$$) {
my ($delta, $numpoints, $firsttime) = @_;
$delta = $firsttime ? $delta / 700 : $delta >> 1;
$delta += $delta / $numpoints;
my $k;
while ($delta > (pyc_base - pyc_tmin) * pyc_tmax / 2) {
$delta /= pyc_base - pyc_tmin;
$k += pyc_base;
}
$k + $delta * (pyc_base - pyc_tmin + 1) / ($delta + 38)
}
sub punycode_encode($) {
my ($input) = @_;
my ($n, $bias, $delta) = (pyc_initial_n, pyc_initial_bias);
(my $output = $input) =~ y/\x00-\x7f//cd;
my $h = my $b = length $output;
my @input = split '', $input;
$output .= "-" if $b && $h < @input;
while ($h < @input) {
my $m = List::Util::min grep { $_ >= $n } map ord, @input;
$m - $n <= (0x7fffffff - $delta) / ($h + 1)
or Carp::croak "punycode_encode: overflow in punycode delta encoding";
$delta += ($m - $n) * ($h + 1);
$n = $m;
for my $i (@input) {
my $c = ord $i;
++$delta < 0x7fffffff
or Carp::croak "punycode_encode: overflow in punycode delta encoding"
if $c < $n;
if ($c == $n) {
my ($q, $k) = ($delta, pyc_base);
while () {
my $t = List::Util::min pyc_tmax, List::Util::max pyc_tmin, $k - $bias;
last if $q < $t;
$output .= substr pyc_digits, $t + (($q - $t) % (pyc_base - $t)), 1;
$q = ($q - $t) / (pyc_base - $t);
$k += pyc_base;
}
$output .= substr pyc_digits, $q, 1;
$bias = pyc_adapt $delta, $h + 1, $h == $b;
$delta = 0;
++$h;
}
}
++$delta;
++$n;
}
$output
}
sub punycode_decode($) {
my ($input) = @_;
my ($n, $bias, $i) = (pyc_initial_n, pyc_initial_bias);
my $output;
if ($input =~ /^(.*?)-([^-]*)$/x) {
$output = $1;
$input = $2;
$output =~ /[^\x00-\x7f]/
and Carp::croak "punycode_decode: malformed punycode";
}
while (length $input) {
my $oldi = $i;
my $w = 1;
for (my $k = pyc_base; ; $k += pyc_base) {
(my $digit = index pyc_digits, substr $input, 0, 1, "")
>= 0
or Carp::croak "punycode_decode: malformed punycode";
$i += $digit * $w;
my $t = List::Util::max pyc_tmin, List::Util::min pyc_tmax, $k - $bias;
last if $digit < $t;
$w *= pyc_base - $t;
}
my $outlen = 1 + length $output;
$bias = pyc_adapt $i - $oldi, $outlen, $oldi == 0;
$n += $i / $outlen;
$i %= $outlen;
substr $output, $i, 0, chr $n;
++$i;
}
$output
}
1
|