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. 8f087cfe87


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 8f087cfe871f9e97206d37907cc77baae0606648
Date: Sat, 24 Oct 2009 09:57:37 +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  8f087cfe871f9e97206d37907cc77baae0606648 (commit)
      from  60931d8e2dea9265ce1fe90c3f0a1ba64c46b5c1 (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 8f087cfe871f9e97206d37907cc77baae0606648
Author: Giuseppe Scrivano <address@hidden>
Date:   Sat Oct 24 11:57:38 2009 +0200

    Add a new class and the relative test wrapping the gnulib SHA1 
implementation

diff --git a/myserver/bootstrap.conf b/myserver/bootstrap.conf
index ec489e4..8df4683 100644
--- a/myserver/bootstrap.conf
+++ b/myserver/bootstrap.conf
@@ -25,6 +25,7 @@ SKIP_PO=t
 gnulib_modules="
 chdir-long
 crypto/md5
+crypto/sha1
 getcwd
 gettext
 gettimeofday
diff --git a/myserver/include/base/crypt/Makefile.am 
b/myserver/include/base/crypt/Makefile.am
index e7d1474..145337b 100644
--- a/myserver/include/base/crypt/Makefile.am
+++ b/myserver/include/base/crypt/Makefile.am
@@ -1,4 +1,4 @@
 cryptincludedir=$(includedir)/myserver/include/base/crypt
-cryptinclude_HEADERS = crypt_algo.h crypt_algo_manager.h md5.h
+cryptinclude_HEADERS = crypt_algo.h crypt_algo_manager.h md5.h sha1.h
 SUBDIRS =
 
diff --git a/myserver/include/base/crypt/md5.h 
b/myserver/include/base/crypt/md5.h
index 54bd908..cdae047 100644
--- a/myserver/include/base/crypt/md5.h
+++ b/myserver/include/base/crypt/md5.h
@@ -18,11 +18,11 @@
 #ifndef MD5_H
 # define MD5_H
 
-#include "stdafx.h"
+# include "stdafx.h"
 
-#include <md5.h>
-#include <include/base/crypt/crypt_algo.h>
-#include <include/base/crypt/crypt_algo_manager.h>
+# include <md5.h>
+# include <include/base/crypt/crypt_algo.h>
+# include <include/base/crypt/crypt_algo_manager.h>
 
 class Md5 : public CryptAlgo
 {
@@ -34,6 +34,7 @@ public:
   virtual char* end (char *buf);
   static void initialize (CryptAlgoManager *manager);
   static CryptAlgo *md5Builder ();
+
 private:
   struct md5_ctx ctx;
 };
diff --git a/myserver/include/base/crypt/md5.h 
b/myserver/include/base/crypt/sha1.h
similarity index 71%
copy from myserver/include/base/crypt/md5.h
copy to myserver/include/base/crypt/sha1.h
index 54bd908..4829bef 100644
--- a/myserver/include/base/crypt/md5.h
+++ b/myserver/include/base/crypt/sha1.h
@@ -15,27 +15,33 @@
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
-#ifndef MD5_H
-# define MD5_H
 
-#include "stdafx.h"
+/* SHA1_H is already used by the gnulib module.  */
+#ifndef SHA1_CRYPT_H
+# define SHA1_CRYPT_H
 
-#include <md5.h>
-#include <include/base/crypt/crypt_algo.h>
-#include <include/base/crypt/crypt_algo_manager.h>
+extern "C"
+{
+#include <sha1.h>
+}
+
+# include "stdafx.h"
+
+# include <include/base/crypt/crypt_algo.h>
+# include <include/base/crypt/crypt_algo_manager.h>
 
-class Md5 : public CryptAlgo
+class Sha1 : public CryptAlgo
 {
 public:
-  Md5 ();
-  virtual ~Md5 ();
+  Sha1 ();
+  virtual ~Sha1 ();
   virtual void init ();
   virtual void update (char const *buf, unsigned long len);
   virtual char* end (char *buf);
   static void initialize (CryptAlgoManager *manager);
-  static CryptAlgo *md5Builder ();
+  static CryptAlgo *sha1Builder ();
 private:
-  struct md5_ctx ctx;
+  struct sha1_ctx ctx;
 };
 
 #endif
diff --git a/myserver/po/POTFILES.in b/myserver/po/POTFILES.in
index 50c70f8..638e124 100644
--- a/myserver/po/POTFILES.in
+++ b/myserver/po/POTFILES.in
@@ -3,6 +3,7 @@ src/base/bitvec/bitvec.cpp
 src/base/crypt/crypt_algo.cpp
 src/base/crypt/crypt_algo_manager.cpp
 src/base/crypt/md5.cpp
+src/base/crypt/sha1.cpp
 src/base/dynamic_lib/dynamiclib.cpp
 src/base/file/file.cpp
 src/base/file/files_utility.cpp
diff --git a/myserver/src/base/crypt/Makefile.am 
b/myserver/src/base/crypt/Makefile.am
index 3af5b69..012ca6c 100644
--- a/myserver/src/base/crypt/Makefile.am
+++ b/myserver/src/base/crypt/Makefile.am
@@ -1,4 +1,4 @@
 lib_LIBRARIES = libcrypt.a
-libcrypt_a_SOURCES = crypt_algo.cpp crypt_algo_manager.cpp md5.cpp
+libcrypt_a_SOURCES = crypt_algo.cpp crypt_algo_manager.cpp md5.cpp sha1.cpp
 SUBDIRS =
 AM_CPPFLAGS = $(all_includes)
diff --git a/myserver/src/base/crypt/sha1.cpp b/myserver/src/base/crypt/sha1.cpp
new file mode 100644
index 0000000..34fe3df
--- /dev/null
+++ b/myserver/src/base/crypt/sha1.cpp
@@ -0,0 +1,93 @@
+/*
+ MyServer
+ Copyright (C) 2005-2009 Free Software Foundation, Inc.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "stdafx.h"
+#include <include/base/crypt/sha1.h>
+
+/*!
+ * Start SHA1 accumulation.  Set bit count to 0 and buffer to mysterious
+ * initialization constants.
+ */
+void Sha1::init ()
+{
+  sha1_init_ctx (&ctx);
+}
+
+/*!
+ * Update context to reflect the concatenation of another buffer full
+ * of bytes.
+ */
+void Sha1::update (char const *buf, unsigned long len)
+{
+  sha1_process_bytes (buf, len, &ctx);
+}
+
+/*!
+ * Initialize the object via a constructor.
+ */
+Sha1::Sha1 ()
+{
+  init ();
+}
+
+/*!
+ * Destroy the object.
+ */
+Sha1::~Sha1 ()
+{
+}
+
+/*!
+ * Write the final hash to the buffer.
+ */
+char* Sha1::end (char *buf)
+{
+  unsigned char tmp[22];
+  char *ret = buf;
+  if (!buf)
+    return NULL;
+
+  sha1_finish_ctx (&ctx, tmp);
+
+  static const char hex[] = "0123456789abcdef";
+
+  for (long i = 0; i < 22; i++)
+    {
+      *buf++ = hex[tmp[i] >> 4];
+      *buf++ = hex[tmp[i] & 0x0f];
+    }
+
+  *buf = '\0';
+
+  return ret;
+}
+
+CryptAlgo *Sha1::sha1Builder ()
+{
+  return new Sha1 ();
+}
+
+/*!
+ * Register the algorithm on the specified manager.
+ *
+ * \param manager The manager where register SHA1.
+ */
+void Sha1::initialize (CryptAlgoManager *manager)
+{
+  string name ("sha1");
+  manager->registerAlgorithm (name, Sha1::sha1Builder);
+}
diff --git a/myserver/src/server/server.cpp b/myserver/src/server/server.cpp
index fb032c0..69bd25f 100644
--- a/myserver/src/server/server.cpp
+++ b/myserver/src/server/server.cpp
@@ -32,6 +32,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 #include <include/base/socket/ssl_socket.h>
 
 #include <include/base/crypt/md5.h>
+#include <include/base/crypt/sha1.h>
 
 #include <include/conf/main/xml_main_configuration.h>
 
@@ -352,6 +353,7 @@ void Server::loadPlugins ()
     }
 
   Md5::initialize (&cryptAlgoManager);
+  Sha1::initialize (&cryptAlgoManager);
 
   getPluginsManager ()->preLoad (this, externalPath);
   getPluginsManager ()->load (this);
diff --git a/myserver/tests/Makefile.am b/myserver/tests/Makefile.am
index 5a757d1..e95f1ae 100644
--- a/myserver/tests/Makefile.am
+++ b/myserver/tests/Makefile.am
@@ -16,7 +16,7 @@ tests_suite_SOURCES = main.cpp test_auth_domain.cpp 
test_base64.cpp \
        test_plugin_info.cpp test_read_directory.cpp test_recursive_mutex.cpp \
        test_regex.cpp test_safetime.cpp test_security_cache.cpp \
        test_security_domain.cpp test_security_manager.cpp \
-       test_security_token.cpp test_semaphore.cpp test_slab.cpp \
+       test_security_token.cpp test_sha1.cpp test_semaphore.cpp test_slab.cpp \
        test_socket.cpp test_socket_pair.cpp test_socket_stream_creator.cpp \
        test_ssl_socket.cpp test_thread.cpp test_unix_socket.cpp test_url.cpp \
        test_utility.cpp test_validator.cpp test_validator_factory.cpp \
diff --git a/myserver/tests/test_sha1.cpp b/myserver/tests/test_sha1.cpp
new file mode 100644
index 0000000..044497d
--- /dev/null
+++ b/myserver/tests/test_sha1.cpp
@@ -0,0 +1,64 @@
+/*
+ MyServer Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <include/base/crypt/sha1.h>
+
+#include <ctype.h>
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <string.h>
+
+class TestSha1 : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE ( TestSha1 );
+  CPPUNIT_TEST ( testHash );
+  CPPUNIT_TEST_SUITE_END ();
+
+  Sha1* sha1;
+public:
+  void setUp ()
+  {
+    sha1 = new Sha1();
+
+  }
+
+  void tearDown ()
+  {
+    delete sha1;
+  }
+
+  void testHash ()
+  {
+    char out[45];
+    const char* msg = "GNU is not UNIX";
+
+    char *expected = (char*) "5ef99232e377af054b479eae19b1b06d688f2a7e";
+
+    sha1->init ();
+    sha1->update (msg, strlen (msg));
+    char *ret = sha1->end (out);
+
+    CPPUNIT_ASSERT_EQUAL (ret, &out[0]);
+
+    for (int i = 0; i < 32; i++)
+      CPPUNIT_ASSERT_EQUAL (tolower (expected[i]), tolower (out[i]));
+  }
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION ( TestSha1 );

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

Summary of changes:
 myserver/bootstrap.conf                        |    1 +
 myserver/include/base/crypt/Makefile.am        |    2 +-
 myserver/include/base/crypt/md5.h              |    9 +++--
 myserver/include/base/crypt/{md5.h => sha1.h}  |   28 +++++++++++-------
 myserver/po/POTFILES.in                        |    1 +
 myserver/src/base/crypt/Makefile.am            |    2 +-
 myserver/src/base/crypt/{md5.cpp => sha1.cpp}  |   36 ++++++++++++------------
 myserver/src/server/server.cpp                 |    2 +
 myserver/tests/Makefile.am                     |    2 +-
 myserver/tests/{test_md5.cpp => test_sha1.cpp} |   34 ++++++++++------------
 10 files changed, 63 insertions(+), 54 deletions(-)
 copy myserver/include/base/crypt/{md5.h => sha1.h} (71%)
 copy myserver/src/base/crypt/{md5.cpp => sha1.cpp} (67%)
 copy myserver/tests/{test_md5.cpp => test_sha1.cpp} (67%)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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