csutil/digest.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

csutil/digest.h
Go to the documentation of this file.

    00001 /*
    00002   Copyright (C) 2011 by Frank Richter
    00003
    00004   This library is free software; you can redistribute it and/or
    00005   modify it under the terms of the GNU Library General Public
    00006   License as published by the Free Software Foundation; either
    00007   version 2 of the License, or (at your option) any later version.
    00008
    00009   This library is distributed in the hope that it will be useful,
    00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    00012   Library General Public License for more details.
    00013
    00014   You should have received a copy of the GNU Library General Public
    00015   License along with this library; if not, write to the Free
    00016   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00017 */
    00018
    00019 #ifndef __CS_CSUTIL_DIGEST_H__
    00020 #define __CS_CSUTIL_DIGEST_H__
    00021
    00026 #include "csutil/csstring.h"
    00027 #include "csutil/hash.h"
    00028
    00029 namespace CS
    00030 {
    00031   namespace Utility
    00032   {
    00033     namespace Checksum
    00034     {
    00036       struct CS_CRYSTALSPACE_EXPORT DigestFormat
    00037       {
    00039         static csString HexString (const uint8* data, uint size);
    00041         static csString HEXString (const uint8* data, uint size);
    00042       };
    00043
    00047       template<uint Size>
    00048       class Digest : protected DigestFormat
    00049       {
    00050       public:
    00051         enum { DigestLen = Size };
    00053         uint8 data[DigestLen];
    00055         csString HexString() const
    00056         { return DigestFormat::HexString (data, Size); }
    00058         csString HEXString() const
    00059         { return DigestFormat::HEXString (data, Size); }
    00060
    00061         bool operator==(const Digest& other) const
    00062         { return memcmp (data, other.data, sizeof (data)) == 0; }
    00063         bool operator!=(const Digest& other) const
    00064         { return memcmp (data, other.data, sizeof (data)) != 0; }
    00065       };
    00066     } // namespace Checksum
    00067   } // namespace Utility
    00068 } // namespace CS
    00069
    00070 template<uint Size>
    00071 class csHashComputer<CS::Utility::Checksum::Digest<Size> > :
    00072   public csHashComputerStruct<CS::Utility::Checksum::Digest<Size> > {};
    00073
    00074 template<uint Size>
    00075 class csComparator<CS::Utility::Checksum::Digest<Size> > :
    00076   public csComparatorStruct<CS::Utility::Checksum::Digest<Size> > {};
    00077
    00078 #endif // __CS_CSUTIL_DIGEST_H__