root/lang/perl/Crypt-DH-GMP/trunk/lib/Crypt/DH/GMP/Compat.pm @ 9476

Revision 9476, 1.3 kB (checked in by daisuke, 6 years ago)

lang/perl/Crypt-DH-GMP; slightly redo method aliasing

  • Property svn:keywords set to Id
Line 
1# $Id$
2
3package Crypt::DH::GMP::Compat;
4
5package # hide from PAUSE
6    Crypt::DH;
7use strict;
8use warnings;
9no warnings 'redefine';
10use vars qw(@ISA);
11
12# Add Crypt::DH::GMP as Crypt::DH's parent, and redefine all methods
13BEGIN
14{
15    unshift @ISA, 'Crypt::DH::GMP';
16
17    *Crypt::DH::new = sub { shift->SUPER::new(@_) };
18    *Crypt::DH::g = sub {
19        my $self = shift;
20        if (@_) {
21            $_[0] = ref $_[0] ? $_[0]->bstr : $_[0];
22        }
23        return Math::BigInt->new( $self->SUPER::g(@_) );
24    };
25    *Crypt::DH::p = sub {
26        my $self = shift;
27        if (@_) {
28            $_[0] = ref $_[0] ? $_[0]->bstr : $_[0];
29        }
30        return Math::BigInt->new($self->SUPER::p(@_))
31    };
32    *Crypt::DH::pub_key = sub { Math::BigInt->new(shift->SUPER::pub_key(@_)) };
33    *Crypt::DH::priv_key = sub { Math::BigInt->new(shift->SUPER::priv_key(@_)) };
34    *Crypt::DH::generate_keys = \&Crypt::DH::GMP::generate_keys;
35    *Crypt::DH::compute_key = \&Crypt::DH::GMP::compute_key;
36    *Crypt::DH::compute_secret = \&Crypt::DH::compute_key;
37}
38
391;
40
41__END__
42
43=head1 NAME
44
45Crypt::DH::GMP::Compat - Compatibility Mode For Crypt::DH
46
47=head1 SYNOPSIS
48
49  use Crypt::DH;
50  use Crypt::DH::GMP qw(-compat);
51
52=head1 DESCRIPTION
53
54Crypt::DH::GMP::Compat is a very invasive module that rewrites Crypt::DH's
55@ISA and method names so that it uses Crypt::DH::GMP
56
57=cut
Note: See TracBrowser for help on using the browser.