From e1bb1b811ba3ca7fc4635929e36d5f27a634b7b7 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Tue, 13 May 2008 15:02:38 +0000
Subject: [PATCH] Utilities: Added stringToHex function and changed generateID
 to use this.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@550 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Utilities.php | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index b7b5c35f9..73dfd2f12 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -177,12 +177,7 @@ class SimpleSAML_Utilities {
 	}
 	
 	public static function generateID() {
-		$bytes = self::generateRandomBytes(21);
-		$key = '_';
-		for($i = 0; $i < 21; $i++) {
-			$key .= sprintf('%02x', ord($bytes[$i]));
-		}
-		return $key;
+		return '_' . self::stringToHex(self::generateRandomBytes(21));
 	}
 	
 
@@ -917,6 +912,21 @@ class SimpleSAML_Utilities {
 		return $data;
 	}
 
+
+	/**
+	 * This function converts a binary string to hexadecimal characters.
+	 *
+	 * @param $bytes  Input string.
+	 * @return String with lowercase hexadecimal characters.
+	 */
+	public function stringToHex($bytes) {
+		$ret = '';
+		for($i = 0; $i < strlen($bytes); $i++) {
+			$ret .= sprintf('%02x', ord($bytes[$i]));
+		}
+		return $ret;
+	}
+
 }
 
 ?>
\ No newline at end of file
-- 
GitLab