myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9-387-g3


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9-387-g3219a6e
Date: Sun, 08 Nov 2009 21:37:04 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  3219a6e85467821e68315666a67b987abe6af7cc (commit)
      from  223894195e5151fa6533dfe9905c39c814f74e42 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit 3219a6e85467821e68315666a67b987abe6af7cc
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun Nov 8 22:36:13 2009 +0100

    Add two new wrapper methods to the CryptAlgoManager class.
    The CryptAlgoManager class can now be used both with C strings and
    with C++ stl strings.

diff --git a/myserver/include/base/crypt/crypt_algo_manager.h 
b/myserver/include/base/crypt/crypt_algo_manager.h
index 501db9e..79eefea 100644
--- a/myserver/include/base/crypt/crypt_algo_manager.h
+++ b/myserver/include/base/crypt/crypt_algo_manager.h
@@ -31,8 +31,14 @@ public:
   CryptAlgoManager ();
   ~CryptAlgoManager ();
   void registerAlgorithm (string &name, builder bld);
-  CryptAlgo *make (string &s);
-  bool check (string &value, string &result, string &algo);
+  CryptAlgo *make (const char *name);
+  CryptAlgo *make (string &s) {return make (s.c_str ());}
+
+  bool check (const char *value, size_t valueLen, const char *result,
+              const char * algo);
+  bool check (string &value, string &result, string &algo)
+  {return check (value.c_str (), value.length (), result.c_str (),
+                 algo.c_str ());}
 private:
   HashMap<string, builder> algorithms;
 };
diff --git a/myserver/src/base/crypt/crypt_algo_manager.cpp 
b/myserver/src/base/crypt/crypt_algo_manager.cpp
index 973f153..ef18430 100644
--- a/myserver/src/base/crypt/crypt_algo_manager.cpp
+++ b/myserver/src/base/crypt/crypt_algo_manager.cpp
@@ -58,7 +58,7 @@ void CryptAlgoManager::registerAlgorithm (string &name,
  * \return A new instance on success.
  * \return NULL on failure.
  */
-CryptAlgo *CryptAlgoManager::make (string &name)
+CryptAlgo *CryptAlgoManager::make (const char *name)
 {
   builder bdr = algorithms.get (name);
   if (bdr)
@@ -89,25 +89,29 @@ private:
  * Check if F(value)=result, using the F specified by the algorithm.
  *
  * \param value The value to convert.
+ * \param valueLen Length in bytes of value.
  * \param result The final result.
  * \param algo The name of the algorithm to use.
  * \return true if F(value)=result.
  * \throw If the algorithm is not registered, it throws an exception.
  */
-bool CryptAlgoManager::check (string &value, string &result, string &algo)
+/*bool CryptAlgoManager::check (string &value, string &result, string &algo)*/
+bool
+CryptAlgoManager::check (const char *value, size_t valueLen, const char 
*result,
+                         const char * algo)
 {
-  const size_t buffer_len = 256;
-  char buffer[buffer_len];
+  const size_t bufferLen = 256;
+  char buffer[bufferLen];
   CryptAlgo *f = make (algo);
   if (!f)
     {
-      snprintf (buffer, buffer_len, _("%s is not a registered algorithm"),
-                algo.c_str ());
+      snprintf (buffer, bufferLen, _("%s is not a registered algorithm"),
+                algo);
       throw CryptAlgoManagerException (buffer);
     }
   auto_ptr<CryptAlgo> keeper (f);
   f->init ();
-  f->update (value.c_str (), value.length ());
+  f->update (value, valueLen);
   f->end (buffer);
-  return !result.compare (buffer);
+  return !strcmp (result, buffer);
 }
diff --git a/myserver/src/conf/security/auth_method.cpp 
b/myserver/src/conf/security/auth_method.cpp
index 94bda0d..b9134be 100644
--- a/myserver/src/conf/security/auth_method.cpp
+++ b/myserver/src/conf/security/auth_method.cpp
@@ -51,13 +51,10 @@ bool AuthMethod::comparePassword (const char *password,
 
   if (cryptAlgoManager)
     {
-      string pwStr (password);
-      string savedpwStr (savedPassword);
-      string algorithmStr (algorithm);
-
       try
         {
-          return cryptAlgoManager->check (savedpwStr, pwStr, algorithmStr);
+          return cryptAlgoManager->check (savedPassword, strlen 
(savedPassword),
+                                          password, algorithm);
         }
       catch (...)
         {
diff --git a/myserver/tests/test_crypt_algo_manager.cpp 
b/myserver/tests/test_crypt_algo_manager.cpp
index d67f5a9..c60398d 100644
--- a/myserver/tests/test_crypt_algo_manager.cpp
+++ b/myserver/tests/test_crypt_algo_manager.cpp
@@ -34,6 +34,7 @@ class TestCryptAlgoManager : public CppUnit::TestFixture
   CPPUNIT_TEST_SUITE ( TestCryptAlgoManager );
   CPPUNIT_TEST (testRegister);
   CPPUNIT_TEST (testCheck);
+  CPPUNIT_TEST (testNoExists);
   CPPUNIT_TEST_SUITE_END ();
 
 public:
@@ -78,12 +79,30 @@ public:
 
     CPPUNIT_ASSERT (cam.check (value, result, name));
     CPPUNIT_ASSERT (!cam.check (value, wrong, name));
+
+
+    CPPUNIT_ASSERT (cam.check (value.c_str (), value.length (),
+                               result.c_str (), name.c_str ()));
+
+    CPPUNIT_ASSERT (!cam.check (value.c_str (), value.length (),
+                               wrong.c_str (), name.c_str ()));
+  }
+
+  void testNoExists ()
+  {
+    CryptAlgoManager cam;
     bool raised = false;
+    Md5::initialize (&cam);
+
+    string value ("freedom");
+    string result ("d5aa1729c8c253e5d917a5264855eab8");
+    string name  ("it_does_not_exist");
+
     try
       {
         /* Using an algorithm that is not registered causes an
            exception.  */
-        cam.check (value, result, wrong);
+        cam.check (value, result, name);
       }
     catch (...)
       {

-----------------------------------------------------------------------

Summary of changes:
 myserver/include/base/crypt/crypt_algo_manager.h |   10 ++++++++--
 myserver/src/base/crypt/crypt_algo_manager.cpp   |   20 ++++++++++++--------
 myserver/src/conf/security/auth_method.cpp       |    7 ++-----
 myserver/tests/test_crypt_algo_manager.cpp       |   21 ++++++++++++++++++++-
 4 files changed, 42 insertions(+), 16 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

[Prev in Thread] Current Thread [Next in Thread]