[libnet-openid-common-perl] 22/34: make int/byte conversions take strings rather than bigints since crypt::dh::gmp prefers that

gregor herrmann gregoa at debian.org
Sun Feb 7 21:50:17 UTC 2016


This is an automated email from the git hooks/post-receive script.

gregoa pushed a commit to annotated tag v1.030099_001
in repository libnet-openid-common-perl.

commit 58dae548d0c3a97ab18f33e685b06a4363a743e9
Author: Robert Norris <rob at eatenbyagrue.org>
Date:   Fri Nov 5 10:55:11 2010 +1100

    make int/byte conversions take strings rather than bigints since crypt::dh::gmp prefers that
---
 lib/Net/OpenID/Common.pm | 24 ++++++++++++++----------
 t/06-bi2bytes.t          | 14 --------------
 t/06-int2bytes.t         | 16 ++++++++++++++++
 3 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/lib/Net/OpenID/Common.pm b/lib/Net/OpenID/Common.pm
index aa8edb0..9d0813a 100644
--- a/lib/Net/OpenID/Common.pm
+++ b/lib/Net/OpenID/Common.pm
@@ -151,8 +151,11 @@ sub w3c_to_time {
     return $time;
 }
 
-sub bi2bytes {
-    my $bigint = shift;
+sub int2bytes {
+    my ($int) = @_;
+
+    my $bigint = Math::BigInt->new($int);
+
     die "Can't deal with negative numbers" if $bigint->is_negative;
 
     my $bits = $bigint->as_bin;
@@ -165,8 +168,8 @@ sub bi2bytes {
     return pack("B*", $bits);
 }
 
-sub bi2arg {
-    return b64(bi2bytes($_[0]));
+sub int2arg {
+    return b64(int2bytes($_[0]));
 }
 
 sub b64 {
@@ -179,16 +182,17 @@ sub d64 {
     return MIME::Base64::decode_base64($_[0]);
 }
 
-sub bytes2bi {
-    return Math::BigInt->new("0b" . unpack("B*", $_[0]));
+sub bytes2int {
+    return Math::BigInt->new("0b" . unpack("B*", $_[0]))->bstr;
 }
 
-sub arg2bi {
-    return undef unless defined $_[0] and $_[0] ne "";
+sub arg2int {
+    my ($arg) = @_;
+    return undef unless defined $arg and $arg ne "";
     # don't acccept base-64 encoded numbers over 700 bytes.  which means
     # those over 4200 bits.
-    return Math::BigInt->new("0") if length($_[0]) > 700;
-    return bytes2bi(MIME::Base64::decode_base64($_[0]));
+    return 0 if length($arg) > 700;
+    return bytes2int(MIME::Base64::decode_base64($arg));
 }
 
 sub timing_indep_eq {
diff --git a/t/06-bi2bytes.t b/t/06-bi2bytes.t
deleted file mode 100644
index ecd43cc..0000000
--- a/t/06-bi2bytes.t
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/perl
-    
-use strict;
-use Test::More tests => 1080;
-use Net::OpenID::Common;
-use Math::BigInt;
-    
-for my $num (1..1080) {
-    my $bi = Math::BigInt->new("$num");
-    my $bytes = OpenID::util::bi2bytes($bi);
-    my $bi2 = OpenID::util::bytes2bi($bytes);
-    is($bi,$bi2);
-}
-
diff --git a/t/06-int2bytes.t b/t/06-int2bytes.t
new file mode 100644
index 0000000..f14ee83
--- /dev/null
+++ b/t/06-int2bytes.t
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+    
+use strict;
+use Test::More tests => 2048;
+use Net::OpenID::Common;
+use Math::BigInt;
+    
+for my $num (1..2048) {
+    my $bi = Math::BigInt->new("2")->bpow($num);
+    my $bstr = $bi->bstr;
+
+    my $bytes = OpenID::util::int2bytes($bstr);
+    my $bstr2 = OpenID::util::bytes2int($bytes);
+    is($bstr,$bstr2);
+}
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libnet-openid-common-perl.git



More information about the Pkg-perl-cvs-commits mailing list