From b4fdcacdb15cec4c1b2c1016e000b72075f3ac0f Mon Sep 17 00:00:00 2001
From: Martin Nilsson <nilsson@opera.com>
Date: Thu, 8 May 2014 15:11:54 +0200
Subject: [PATCH] Relax the typing a bit, and add a missing integer sign check.

---
 lib/7.8/modules/Crypto.pmod/RSA.pike |  2 +-
 lib/modules/Crypto.pmod/Random.pmod  | 14 +++++++-------
 src/post_modules/Nettle/nettle.cmod  |  4 +++-
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/lib/7.8/modules/Crypto.pmod/RSA.pike b/lib/7.8/modules/Crypto.pmod/RSA.pike
index 369cca8277..f8d69db281 100644
--- a/lib/7.8/modules/Crypto.pmod/RSA.pike
+++ b/lib/7.8/modules/Crypto.pmod/RSA.pike
@@ -307,7 +307,7 @@ Gmp.mpz get_prime(int bits, function(int:string) r)
 this_program generate_key(int(128..) bits, function(int:string)|void r)
 {
   if (!r)
-    r = [function(int:string)]Crypto.Random.random_string;
+    r = Crypto.Random.random_string;
   if (bits < 128)
     error( "Ridiculously small key.\n" );
 
diff --git a/lib/modules/Crypto.pmod/Random.pmod b/lib/modules/Crypto.pmod/Random.pmod
index 8a3e29b2a2..63eee76f08 100644
--- a/lib/modules/Crypto.pmod/Random.pmod
+++ b/lib/modules/Crypto.pmod/Random.pmod
@@ -36,7 +36,7 @@ protected class RND
     ::reseed(data);
   }
 
-  string(8bit) random_string(int(0..) len)
+  string(8bit) random_string(int len)
   {
     // The original Fortuna design has an entropy pool reseeding the
     // generator when enough external events have been collected, but
@@ -54,25 +54,25 @@ protected class RND
 }
 
 protected RND rnd_obj = RND();
-protected function(int(0..):string(8bit)) rnd_func = rnd_obj->random_string;
+protected function(int:string(8bit)) rnd_func = rnd_obj->random_string;
 
 //! Returns a string of length @[len] with random content. The content
 //! is generated by a Fortuna random generator that is updated with
 //! output from /dev/urandom on UNIX and CryptGenRandom on NT.
-string(8bit) random_string(int(0..) len) {
+string(8bit) random_string(int len) {
   return rnd_func(len);
 }
 
 __deprecated__ string(8bit) blocking_random_string(int len)
 {
-  return rnd_func([int(0..)]len);
+  return rnd_func(len);
 }
 
 //! Returns a @[Gmp.mpz] object with a random value between @expr{0@}
 //! and @[top]. Uses @[random_string].
-Gmp.mpz random(int(0..) top) {
-  return [object(Gmp.mpz)]( Gmp.mpz(rnd_func( (int(0..))ceil( log((float)top)/
-                                                              log(2.0) ) ),
+Gmp.mpz random(int top) {
+  return [object(Gmp.mpz)]( Gmp.mpz(rnd_func( (int)ceil( log((float)top)/
+                                                         log(2.0) ) ),
 				    256) % top);
 }
 
diff --git a/src/post_modules/Nettle/nettle.cmod b/src/post_modules/Nettle/nettle.cmod
index 3f29581857..3932edd333 100644
--- a/src/post_modules/Nettle/nettle.cmod
+++ b/src/post_modules/Nettle/nettle.cmod
@@ -355,10 +355,12 @@ PIKECLASS Fortuna
    *! bytes of random data per call, the necessary rekey operations
    *! are here performed internally, so no such restrictions apply.
    */
-  PIKEFUN string(8bit) random_string(int(0..) len)
+  PIKEFUN string(8bit) random_string(int len)
   {
     unsigned stored = 0;
     struct string_builder s;
+
+    if(len<0) Pike_error("Length has to be positive.\n");
     init_string_builder_alloc(&s, len+16, 0);
 
     while( stored < len )
-- 
GitLab