XRootD
XrdCksCalczcrc32.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d C k s C a l c z c r c 3 2 . h h */
4 /* */
5 /* Copyright (c) 2012 by European Organization of Nuclear Research (CERN) */
6 /* Produced by Lukasz Janyst <ljanyst@cern.ch> */
7 /* */
8 /* This file is part of the XRootD software suite. */
9 /* */
10 /* XRootD is free software: you can redistribute it and/or modify it under */
11 /* the terms of the GNU Lesser General Public License as published by the */
12 /* Free Software Foundation, either version 3 of the License, or (at your */
13 /* option) any later version. */
14 /* */
15 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
16 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
17 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
18 /* License for more details. */
19 /* */
20 /* You should have received a copy of the GNU Lesser General Public License */
21 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
22 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
23 /* */
24 /* The copyright holder's institutional names and contributor's names may not */
25 /* be used to endorse or promote products derived from this software without */
26 /* specific prior written permission of the institution or contributor. */
27 /******************************************************************************/
28 
29 #ifndef __XRDCKSCALCZCRC32_HH__
30 #define __XRDCKSCALCZCRC32_HH__
31 
32 #include "XrdCks/XrdCksCalc.hh"
33 #include "XrdSys/XrdSysError.hh"
34 #include "XrdVersion.hh"
35 #include <cstdint>
36 #include <zlib.h>
37 
38 //------------------------------------------------------------------------------
39 // CRC32 checkum according to the algorithm implemented in zlib
40 //------------------------------------------------------------------------------
42 {
43  public:
44 
45  //--------------------------------------------------------------------------
47  //--------------------------------------------------------------------------
49  {
50  Init();
51  }
52 
53  //--------------------------------------------------------------------------
55  //--------------------------------------------------------------------------
57  {
58  }
59 
60  //--------------------------------------------------------------------------
62  //--------------------------------------------------------------------------
63  char *Final()
64  {
65  return (char *)&pCheckSum;
66  }
67 
68  //--------------------------------------------------------------------------
70  //--------------------------------------------------------------------------
71  void Init()
72  {
73  pCheckSum = crc32( 0L, Z_NULL, 0 );
74  }
75 
76  //--------------------------------------------------------------------------
78  //--------------------------------------------------------------------------
80  {
81  return new XrdCksCalczcrc32();
82  }
83 
84  //--------------------------------------------------------------------------
86  //--------------------------------------------------------------------------
87  void Update( const char *Buff, int BLen )
88  {
89  pCheckSum = crc32( pCheckSum, (const Bytef*)Buff, BLen );
90  }
91 
92  //--------------------------------------------------------------------------
94  //--------------------------------------------------------------------------
95  const char *Type(int &csSz)
96  {
97  csSz = 4; return "zcrc32";
98  }
99 
100  private:
101  uint32_t pCheckSum;
102 };
103 
104 //------------------------------------------------------------------------------
105 // Plugin callback
106 //------------------------------------------------------------------------------
108  const char *csName,
109  const char *cFN,
110  const char *Parms)
111 {
112  return new XrdCksCalczcrc32();
113 }
114 
116 
117 #endif // __XRDCKSCALCZCRC32_HH__
XrdVERSIONINFO(XrdCksCalcInit, zcrc32)
XrdCksCalc * XrdCksCalcInit(XrdSysError *eDest, const char *csName, const char *cFN, const char *Parms)
static XrdSysError eDest(0,"crypto_")
char * Final()
Final checksum.
XrdCksCalczcrc32()
Constructor.
const char * Type(int &csSz)
Checksum algorithm name.
void Init()
Initialize.
void Update(const char *Buff, int BLen)
Update current checksum.
virtual ~XrdCksCalczcrc32()
Destructor.
XrdCksCalc * New()
Virtual constructor.