From 9da0c33bb02d849f1201a0f6f6d77c8f8deb9242 Mon Sep 17 00:00:00 2001
From: Jake Bell <jake@theunraveler.com>
Date: Thu, 19 May 2011 09:29:01 -0500
Subject: [PATCH] Initial port to D7.

---
 encrypt.info                 |    3 +-
 encrypt.module               |   56 ++++++++++++++++++++++++------------------
 includes/encrypt.encrypt.inc |    7 +++--
 3 files changed, 38 insertions(+), 28 deletions(-)

diff --git a/encrypt.info b/encrypt.info
index 3756143..9ffacca 100644
--- a/encrypt.info
+++ b/encrypt.info
@@ -1,3 +1,4 @@
 name = Encrypt
 description = Provides an API for two-way encryption
-core = 6.x
+core = 7.x
+configure = admin/config/system/encrypt
diff --git a/encrypt.module b/encrypt.module
index f4ccdaf..51bcfdc 100644
--- a/encrypt.module
+++ b/encrypt.module
@@ -57,10 +57,33 @@ function encrypt_help($path, $arg) {
 
   switch ($path) {
     case 'admin/help#encrypt':
-      $output = '<p>'. t('The encrypt module Provides an API for two-way encryption.  Drupal has no native way to do two-way encryption.  PHP\'s ability to do two-way encryption is a little more involved than most people care to get into.  This module provides an easy way to encrypt() and decrypt().') .'</p>';
+      $output = '<p>'. t('The encrypt module Provides an API for two-way encryption. Drupal has no native way to do two-way encryption. PHP\'s ability to do two-way encryption is a little more involved than most people care to get into.  This module provides an easy way to encrypt() and decrypt().') .'</p>';
+      
+      if (!function_exists('mcrypt_encrypt')) {
+        $output .= '<p>' . t('MCrypt is currently not installed or configured properly on your server. If you would like to use the "MCrypt AES 256" method for encryption, follow the instructions for installing MCrypt !link.', array('!link' => l('here', 'http://www.php.net/manual/en/mcrypt.setup.php'))) . '</p>';
+      }
+
+      return $output;
   }
+}
 
-  return $output;
+/**
+ * Implementation of hook_menu().
+ */
+function encrypt_menu() {
+  $items = array();
+
+  $items['admin/config/system/encrypt'] = array(
+    'title' => 'Encrypt',
+    'description' => 'Main settings for encryption.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('encrypt_admin_settings'),
+    'access arguments' => array('administer encrypt'),
+    'file' => 'includes/encrypt.admin.inc',
+    'type' => MENU_NORMAL_ITEM,
+  );
+
+  return $items;
 }
 
 /**
@@ -78,29 +101,14 @@ function encrypt_theme($existing, $type, $theme, $path) {
 }
 
 /**
- * Implementation of hook_perm().
+ * Implementation of hook_permission().
  */
-function encrypt_perm() {
-  return array('administer encrypt');
-}
-
-/**
- * Implementation of hook_menu().
- */
-function encrypt_menu() {
-  $items = array();
-
-  $items['admin/settings/encrypt'] = array(
-    'title' => 'Encrypt',
-    'description' => 'Main settings for encrypt.',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('encrypt_admin_settings'),
-    'access arguments' => array('administer encrypt'),
-    'file' => 'includes/encrypt.admin.inc',
-    'type' => MENU_NORMAL_ITEM
+function encrypt_permission() {
+  return array(
+    'administer encrypt' => array(
+      'title' => t('Administer encryption settings'),
+    ),
   );
-
-  return $items;
 }
 
 /**
@@ -167,6 +175,6 @@ function decrypt($text = '', $options = array(), $method = NULL, $key_name = NUL
 function encrypt_encrypt_api() {
   return array(
     'file' => drupal_get_path('module', 'encrypt') . '/includes/encrypt.encrypt.inc',
-    'api version' => '1.0',
+    'api' => '1.0',
   );
 }
diff --git a/includes/encrypt.encrypt.inc b/includes/encrypt.encrypt.inc
index 4f8bf21..b35ec63 100644
--- a/includes/encrypt.encrypt.inc
+++ b/includes/encrypt.encrypt.inc
@@ -8,7 +8,7 @@
  */
 
 /**
- * Implementation of encrypt_method_info().
+ * Implementation of hook_encrypt_method_info().
  */
 function encrypt_encrypt_method_info() {
   $methods = array();
@@ -104,12 +104,13 @@ function encrypt_encrypt_mcrypt_rij_256($op = 'encrypt', $text = '', $key = ENCR
   // Define iv cipher
   $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
   $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
+  $use_base64 = array_key_exists('base64', $options) && $options['base64'] !== FALSE;
 
   // Check op
   if ($op == 'decrypt') {
     // Decrypt
     // Check if we are using base64 encoding
-    if ($options['base64'] !== FALSE) {
+    if ($use_base64) {
       $text = base64_decode($text);
     }
 
@@ -121,7 +122,7 @@ function encrypt_encrypt_mcrypt_rij_256($op = 'encrypt', $text = '', $key = ENCR
     $processed_text = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
 
     // Check if we are using base64 encoding
-    if ($options['base64'] !== FALSE) {
+    if ($use_base64) {
       $processed_text = base64_encode($processed_text);
     }
   }
-- 
1.7.5.1

