• Main Page
  • Classes
  • Files
  • File List

Swiften/StringCodecs/SHA1.h

00001 /*
00002  * Copyright (c) 2010-2012 Remko Tronçon
00003  * Licensed under the GNU General Public License v3.
00004  * See Documentation/Licenses/GPLv3.txt for more information.
00005  */
00006 
00007 #pragma once
00008 
00009 #ifdef SWIFTEN_PLATFORM_WIN32
00010 #include "SHA1_Windows.h"
00011 #else
00012 
00013 #include <vector>
00014 #include <boost/cstdint.hpp>
00015 
00016 #include <Swiften/Base/API.h>
00017 #include <Swiften/Base/ByteArray.h>
00018 #include <Swiften/Base/SafeByteArray.h>
00019 
00020 namespace Swift {
00021   class SWIFTEN_API SHA1 {
00022     public:
00023       SHA1();
00024 
00025       SHA1& update(const std::vector<unsigned char>& data);
00026       std::vector<unsigned char> getHash() const;
00027 
00033       static ByteArray getHash(const ByteArray& data);
00034       static ByteArray getHash(const SafeByteArray& data);
00035 
00036       ByteArray operator()(const SafeByteArray& data) {
00037         return getHash(data);
00038       }
00039 
00040       ByteArray operator()(const ByteArray& data) {
00041         return getHash(data);
00042       }
00043 
00044     private:
00045       typedef struct {
00046           boost::uint32_t state[5];
00047           boost::uint32_t count[2];
00048           boost::uint8_t buffer[64];
00049       } CTX;
00050       static void Init(CTX* context);
00051       static void Transform(boost::uint32_t state[5], boost::uint8_t buffer[64]);
00052       static void Update(CTX* context, boost::uint8_t* data, unsigned int len);
00053       static void Final(boost::uint8_t digest[20], CTX* context);
00054 
00055       template<typename Container> static ByteArray getHashInternal(const Container& input);
00056 
00057     private:
00058       CTX context;
00059   };
00060 }
00061 
00062 #endif

Generated on Fri Oct 12 2012 21:00:19 for Swiften by  doxygen 1.7.1