From 3b1fcbe825c90dcb5e358ad7632b45d4cd512f54 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Tue, 6 Sep 2005 20:08:39 +0000 Subject: New namespace for message digest algorithms. --- src/security/digest/messageDigestFactory.cpp | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/security/digest/messageDigestFactory.cpp (limited to 'src/security/digest/messageDigestFactory.cpp') diff --git a/src/security/digest/messageDigestFactory.cpp b/src/security/digest/messageDigestFactory.cpp new file mode 100644 index 00000000..eccc545c --- /dev/null +++ b/src/security/digest/messageDigestFactory.cpp @@ -0,0 +1,80 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard +// +// 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 2 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, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#include "vmime/security/digest/messageDigestFactory.hpp" +#include "vmime/exception.hpp" + +#include "vmime/security/digest/md5/md5MessageDigest.hpp" +#include "vmime/security/digest/sha1/sha1MessageDigest.hpp" + + +namespace vmime { +namespace security { +namespace digest { + + +messageDigestFactory::messageDigestFactory() +{ + registerAlgorithm ("md5"); + registerAlgorithm ("sha1"); +} + + +messageDigestFactory::~messageDigestFactory() +{ +} + + +messageDigestFactory* messageDigestFactory::getInstance() +{ + static messageDigestFactory instance; + return (&instance); +} + + +ref messageDigestFactory::create(const string& name) +{ + const MapType::const_iterator it = m_algos.find + (utility::stringUtils::toLower(name)); + + if (it != m_algos.end()) + return (*it).second->create(); + + throw exceptions::no_digest_algorithm_available(name); +} + + +const std::vector messageDigestFactory::getSupportedAlgorithms() const +{ + std::vector res; + + for (MapType::const_iterator it = m_algos.begin() ; + it != m_algos.end() ; ++it) + { + res.push_back((*it).first); + } + + return res; +} + + +} // digest +} // security +} // vmime + -- cgit v1.2.3