/usr/include/crystalspace-2.0/csutil/checksum.h is in libcrystalspace-dev 2.0+dfsg-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | /*
Copyright (C) 2009-2011 by Frank Richter
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CS_CSUTIL_CHECKSUM_H__
#define __CS_CSUTIL_CHECKSUM_H__
#include "csextern.h"
#include "iutil/databuff.h"
namespace CS
{
namespace Utility
{
namespace Checksum
{
/**
* Compute Adler-32 checksum for some data.
*
* This class can be used in two ways, function-style (for checksumming
* a single block of data) and as an instance (to checksum data in
* multiple chunks).
*
* Example for function-style use:
* \code
* uint32 check = CS::Utility::Checksum::Adler32 (data, dataSize);
* \endcode
*
* Example for use as an instance:
* \code
* CS::Utility::Checksum::Adler32 computeSum;
* computeSum.Append (dataPart1, dataPart1Size);
* // ...
* computeSum.Append (dataPart2, dataPart2Size);
* uint32 checksum = computeSum.Finish();
* \endcode
*/
class Adler32
{
static inline uint32 Initial() { return 1; }
static CS_CRYSTALSPACE_EXPORT uint32 Compute (uint32 prevCheckSum,
const void* data, size_t size);
uint32 checksum;
public:
Adler32 () : checksum (Initial()) {}
//@{
/// Compute Adler-32 checksum for given data buffer.
Adler32 (const void* data, size_t size) : checksum (Compute (Initial(), data, size)) {}
Adler32 (iDataBuffer* data)
: checksum (Compute (Initial(), data->GetData(), data->GetSize())) {}
//@}
//@{
/**
* Continue computing Adler-32 checksum for given data buffer.
* \remarks It's recommended to use the Append() method to compute the
* checksum over multiple chunks of data.
*/
Adler32 (uint32 prevCheckSum, const void* data, size_t size)
: checksum (Compute (prevCheckSum, data, size)) {}
Adler32 (uint32 prevCheckSum, iDataBuffer* data)
: checksum (Compute (prevCheckSum, data->GetData(), data->GetSize())) {}
//@}
/// Feed in more data to checksum.
void Append (const uint8* data, size_t size)
{ checksum = Compute (checksum, data, size); }
/// "Finish" checksum computation and return checksum over all data.
uint32 Finish ()
{ return checksum; }
/// Return current checksum. For function-style use.
operator uint32() const
{ return checksum; }
};
/**
* Compute CRC32 checksum for some data.
*
* This class can be used in two ways, function-style (for checksumming
* a single block of data) and as an instance (to checksum data in
* multiple chunks).
*
* Example for function-style use:
* \code
* uint32 check = CS::Utility::Checksum::CRC32 (data, dataSize);
* \endcode
*
* Example for use as an instance:
* \code
* CS::Utility::Checksum::CRC32 computeSum;
* computeSum.Append (dataPart1, dataPart1Size);
* // ...
* computeSum.Append (dataPart2, dataPart2Size);
* uint32 checksum = computeSum.Finish();
* \endcode
*/
class CRC32
{
static inline uint32 Initial() { return 0; }
static CS_CRYSTALSPACE_EXPORT uint32 Compute (uint32 prevCheckSum,
const void* data, size_t size);
uint32 checksum;
public:
CRC32 () : checksum (Initial()) {}
//@{
/// Compute CRC-32 checksum for given data buffer.
CRC32 (const void* data, size_t size) : checksum (Compute (Initial(), data, size)) {}
CRC32 (iDataBuffer* data)
: checksum (Compute (Initial(), data->GetData(), data->GetSize())) {}
//@}
//@{
/**
* Continue computing CRC-32 checksum for given data buffer.
* \remarks It's recommended to use the Append() method to compute the
* checksum over multiple chunks of data.
*/
CRC32 (uint32 prevCheckSum, const void* data, size_t size)
: checksum (Compute (prevCheckSum, data, size)) {}
CRC32 (uint32 prevCheckSum, iDataBuffer* data)
: checksum (Compute (prevCheckSum, data->GetData(), data->GetSize())) {}
//@}
/// Feed in more data to checksum.
void Append (const uint8* data, size_t size)
{ checksum = Compute (checksum, data, size); }
/// "Finish" checksum computation and return checksum over all data.
uint32 Finish ()
{ return checksum; }
/// Return current checksum. For function-style use.
operator uint32() const
{ return checksum; }
};
} // namespace Checksum
} // namespace Utility
} // namespace CS
#endif // __CS_CSUTIL_CHECKSUM_H__
|