This file is indexed.

/usr/share/perl5/Net/OpenID/IndirectMessage.pm is in libnet-openid-common-perl 1.20-1.

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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
package Net::OpenID::IndirectMessage;
$Net::OpenID::IndirectMessage::VERSION = '1.20';
use strict;
use Carp;
use Net::OpenID::Common;

sub new {
    my $class = shift;
    my $what = shift;
    my %opts = @_;

    my $self = bless {}, $class;

    $self->{minimum_version} = delete $opts{minimum_version};

    Carp::croak("Unknown options: " . join(", ", keys %opts)) if %opts;

    my $getter;
    my $enumer;
    if (ref $what eq "HASH") {
        # In this case it's the caller's responsibility to determine
        # whether the method is GET or POST.
        $getter = sub { $what->{$_[0]}; };
        $enumer = sub { keys(%$what); };
    }
    elsif (ref $what eq "Apache") {
        my %get;
        if ($what->method eq 'POST') {
            %get = $what->content;
        }
        else {
            %get = $what->args;
        }
        $getter = sub { $get{$_[0]}; };
        $enumer = sub { keys(%get); };
    }
    elsif (ref $what eq "Plack::Request") {
        my $p = $what->method eq 'POST' ? $what->body_parameters : $what->query_parameters;
        $getter = sub { $p->get($_[0]); };
        $enumer = sub { keys %{$p}; };
    }
    elsif (ref $what ne "CODE") {
        # assume an object that follows the CGI interface and has a param() method
        # CGI does the right thing and omits query parameters if this is a POST
        # others (Apache::Request, Apache2::Request) mix query and body params.
        $getter = sub { scalar $what->param($_[0]); };
        $enumer = sub { $what->param; };
    }

    else {
        # CODE reference
        my @keys = ();
        my $enumerated;
        $getter = $what;
        $enumer = sub {
            unless ($enumerated) {
                $enumerated = 1;
                # In Consumer/Common 1.03 and predecessors, coderefs
                # did not have to be able to enumerate all keys.
                # Therefore, we must cope with legacy coderefs being
                # passed in which don't expect to be called with no
                # arguments, and then, most likely, fail in one of
                # three ways:
                #   (1) return empty list
                #   (2) retrieve undef/'' value for undef/'' key.
                #   (3) raise an error
                # We normalize these all to empty list, which our
                # caller can then recognize as obviously wrong
                # and do something about it.
                eval { @keys = $what->() };
                @keys = ()
                  if (@keys == 1 &&
                      !(defined($keys[0]) && length($keys[0])));
            }
            return @keys;
        }
    }
    $self->{getter} = $getter;
    $self->{enumer} = $enumer;

    # Now some quick pre-configuration of a few bits

    # Is this an OpenID message at all?
    # All OpenID messages have an openid.mode value...
    return undef unless $self->get('mode');

    # Is this an OpenID 2.0 message?
    my $ns = $self->get('ns');


    # The 2.0 spec section 4.1.2 requires that we support these namespace values
    # but act like it's a normal 1.1 request.
    # We do this by just pretending that ns wasn't set at all.
    if ($ns && ($ns eq 'http://openid.net/signon/1.1' || $ns eq 'http://openid.net/signon/1.0')) {
        $ns = undef;
    }

    if (defined($ns) && $ns eq OpenID::util::version_2_namespace()) {
        $self->{protocol_version} = 2;
    }
    elsif (! defined($ns)) {
        # No namespace at all means a 1.1 message
        if (($self->{minimum_version}||0) <= 1) {
            $self->{protocol_version} = 1;
        }
        else {
            # Pretend we don't understand the message.
            return undef;
        }
    }
    else {
        # Unknown version is the same as not being an OpenID message at all
        return undef;
    }

    # This will be populated in on demand
    $self->{extension_prefixes} = undef;

    return $self;
}

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

sub mode {
    my $self = shift;
    return $self->get('mode');
}

sub get {
    my $self = shift;
    my $key = shift or Carp::croak("No argument name supplied to get method");

    # Arguments can only contain letters, numbers, underscores and dashes
    Carp::croak("Invalid argument key $key") unless $key =~ /^[\w\-]+$/;
    Carp::croak("Too many arguments") if scalar(@_);

    return $self->{getter}->("openid.$key");
}

sub raw_get {
    my $self = shift;
    my $key = shift or Carp::croak("No argument name supplied to raw_get method");

    return $self->{getter}->($key);
}

sub getter {
    my $self = shift;

    return $self->{getter};
}

# NOTE RE all_parameters():
#
# It was originally thought that enumeration of URL parameters was
# unnecessary except to support extensions, i.e., that support of the
# core protocol did not need it.  While this is true in OpenID 1.1, it
# is not the case in OpenID 2.0 where check_authentication requires
# sending back a complete copy of the positive assertion message
# that was received indirectly.
#
# In cases where legacy client code is not supplying a real enumerator,
# this routine will return an empty list and callers will need to
# check for this.  Recall that actual messages in all versions of the
# Openid protocol (thus far) are guaranteed to have at least an
# 'openid.mode' parameter.

sub all_parameters {
    my $self = shift;

    return $self->{enumer}->();
}

sub get_ext {
    my $self = shift;
    my $namespace = shift or Carp::croak("No namespace URI supplied to get_ext method");
    my $key = shift;

    Carp::croak("Too many arguments") if scalar(@_);

    $self->_compute_extension_prefixes() unless defined($self->{extension_prefixes});

    my $alias = $self->{extension_prefixes}{$namespace};
    return $key ? undef : {} unless $alias;

    if ($key) {
        return $self->{getter}->("openid.$alias.$key");
    }
    else {
        my $prefix = "openid.$alias.";
        my $prefixlen = length($prefix);
        my $ret = {};
        foreach my $key ($self->all_parameters) {
            next unless substr($key, 0, $prefixlen) eq $prefix;
            $ret->{substr($key, $prefixlen)} = $self->{getter}->($key);
        }
        return $ret;
    }
}

sub has_ext {
    my $self = shift;
    my $namespace = shift or Carp::croak("No namespace URI supplied to get_ext method");

    Carp::croak("Too many arguments") if scalar(@_);

    $self->_compute_extension_prefixes() unless defined($self->{extension_prefixes});

    return defined($self->{extension_prefixes}{$namespace}) ? 1 : 0;
}

sub _compute_extension_prefixes {
    my ($self) = @_;

    # return unless $self->{enumer};

    $self->{extension_prefixes} = {};
    if ($self->protocol_version != 1) {
        foreach my $key ($self->all_parameters) {
            next unless $key =~ /^openid\.ns\.(\w+)$/;
            my $alias = $1;
            my $uri = $self->{getter}->($key);
            $self->{extension_prefixes}{$uri} = $alias;
        }
    }
    else {
        # Synthesize the SREG namespace as it was used in OpenID 1.1
        $self->{extension_prefixes}{"http://openid.net/extensions/sreg/1.1"} = "sreg";
    }
}

1;

=head1 NAME

Net::OpenID::IndirectMessage - Class representing a collection of namespaced arguments

=head1 VERSION

version 1.20

=head1 DESCRIPTION

This class acts as an abstraction layer over a collection of flat URL arguments
which supports namespaces as defined by the OpenID Auth 2.0 specification.

It also recognises when it is given OpenID 1.1 non-namespaced arguments and
acts as if the relevant namespaces were present. In this case, it only
supports the basic OpenID 1.1 arguments and the extension arguments
for Simple Registration.

This class can operate on
a normal hashref,
a L<CGI> object or any object with a C<param> method that behaves similarly
(L<Apache::Request>, L<Apache2::Request>, L<Mojo::Parameters>,...),
an L<Apache> object,
a L<Plack::Request> object, or
an arbitrary C<CODE> ref that when given a key name as its first parameter
and returns a value and if given no arguments returns a list of all keys present.

If you pass in a hashref or a coderef it is your responsibility as the caller
to check the HTTP request method and pass in the correct set of arguments.
For the other kinds of objects, this module will do the right thing automatically.

=head1 SYNOPSIS

    use Net::OpenID::IndirectMessage;

    # Pass in something suitable for the underlying flat dictionary.
    # Will return an instance if the request arguments can be understood
    # as a supported OpenID Message format.
    # Will return undef if this doesn't seem to be an OpenID Auth message.
    # Will croak if the $argumenty_thing is not of a suitable type.
    my $args = Net::OpenID::IndirectMessage->new($argumenty_thing);

    # Determine which protocol version the message is using.
    # Currently this can be either 1 for 1.1 or 2 for 2.0.
    # Expect larger numbers for other versions in future.
    # Most callers don't really need to care about this.
    my $version = $args->protocol_version();

    # Get a core argument value ("openid.mode")
    my $mode = $args->get("mode");

    # Get an extension argument value
    my $nickname = $args->get_ext("http://openid.net/extensions/sreg/1.1", "nickname");

    # Get hashref of all arguments in a given namespace
    my $sreg = $args->get_ext("http://openid.net/extensions/sreg/1.1");

Most of the time callers won't need to use this class directly, but will instead
access it through a L<Net::OpenID::Consumer> instance.

=head1 METHODS

=over 4

=item B<protocol_version>

Currently returns 1 or 2, according as this is an OpenID 1.0/1.1 or an OpenID 2.0 message.

=item B<has_ext>

Takes an extension namespace and returns true if the named extension is used in this message.

=item B<get_ext>

Takes an extension namespace and an optional parameter name, returns the parameter value,
or if no parameter given, the parameter value.

=back