XRootD
Loading...
Searching...
No Matches
XrdCksCalccrc32.cc
Go to the documentation of this file.
1
/******************************************************************************/
2
/* */
3
/* X r d C k s C a l c c r c 3 2 . c c */
4
/* */
5
/* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */
6
/* All Rights Reserved */
7
/* Produced by Andrew Hanushevsky for Stanford University under contract */
8
/* DE-AC02-76-SFO0515 with the Department of Energy */
9
/* */
10
/* This file is part of the XRootD software suite. */
11
/* */
12
/* XRootD is free software: you can redistribute it and/or modify it under */
13
/* the terms of the GNU Lesser General Public License as published by the */
14
/* Free Software Foundation, either version 3 of the License, or (at your */
15
/* option) any later version. */
16
/* */
17
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20
/* License for more details. */
21
/* */
22
/* You should have received a copy of the GNU Lesser General Public License */
23
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25
/* */
26
/* The copyright holder's institutional names and contributor's names may not */
27
/* be used to endorse or promote products derived from this software without */
28
/* specific prior written permission of the institution or contributor. */
29
/******************************************************************************/
30
31
#include "
XrdCks/XrdCksCalccrc32.hh
"
32
#include "
XrdSys/XrdSysPlatform.hh
"
33
34
#include <arpa/inet.h>
35
#include <cstring>
36
#include <zlib.h>
37
38
/******************************************************************************/
39
/* L o c a l F u n c t i o n s */
40
/******************************************************************************/
41
42
namespace
43
{
44
uint32_t getCS(
const
char
* csVal)
45
{uint32_t aVal;
46
memcpy(&aVal, csVal,
sizeof
(aVal));
47
#ifndef Xrd_Big_Endian
48
aVal = ntohl(aVal);
49
#endif
50
return
aVal;
51
}
52
}
53
54
/******************************************************************************/
55
/* X r d C k s C a l c c r c 3 2 */
56
/******************************************************************************/
57
58
//------------------------------------------------------------------------------
59
// CRC32 checkum according to the algorithm implemented in zlib
60
// WARNING: zlib always output the result in the endian byte order that is
61
// natural to the machine being used. This version adopts the common
62
// standard of representing the checksum in big endian order. To get
63
// the explicit zlib version, using the XrdCksCalczcrc32 plugin.
64
//------------------------------------------------------------------------------
65
66
//--------------------------------------------------------------------------
68
//--------------------------------------------------------------------------
69
const
char
*
XrdCksCalccrc32::Combine
(
const
char
* Cksum,
int
DLen)
70
{
71
uint32_t crc2 = getCS(Cksum);
72
73
pCheckSumTmp = pCheckSum = crc32_combine(pCheckSum, crc2, (z_off_t)DLen);
74
75
#ifndef Xrd_Big_Endian
76
pCheckSumTmp = ntohl(pCheckSumTmp);
77
#endif
78
79
return
(
char
*)&pCheckSumTmp;
80
}
81
82
//--------------------------------------------------------------------------
84
//--------------------------------------------------------------------------
85
const
char
*
XrdCksCalccrc32::Combine
(
const
char
* Cksum1,
const
char
* Cksum2,
86
int
DLen)
87
{
88
uint32_t crc1 = getCS(Cksum1), crc2 = getCS(Cksum2);
89
90
pCheckSumTmp = crc32_combine(crc1, crc2, (z_off_t)DLen);
91
92
#ifndef Xrd_Big_Endian
93
pCheckSumTmp = ntohl(pCheckSumTmp);
94
#endif
95
96
return
(
char
*)&pCheckSumTmp;
97
}
98
99
//--------------------------------------------------------------------------
101
//--------------------------------------------------------------------------
102
char
*
XrdCksCalccrc32::Final
()
103
{
104
pCheckSumTmp = pCheckSum;
105
106
#ifndef Xrd_Big_Endian
107
pCheckSumTmp = ntohl(pCheckSumTmp);
108
#endif
109
110
return
(
char
*)&pCheckSumTmp;
111
}
112
113
//--------------------------------------------------------------------------
115
//--------------------------------------------------------------------------
116
void
XrdCksCalccrc32::Init
()
117
{
118
pCheckSum = crc32( 0L, Z_NULL, 0 );
119
}
120
121
//--------------------------------------------------------------------------
123
//--------------------------------------------------------------------------
124
void
XrdCksCalccrc32::Update
(
const
char
*Buff,
int
BLen )
125
{
126
pCheckSum = crc32( pCheckSum, (
const
Bytef*)Buff, BLen );
127
}
XrdCksCalccrc32.hh
XrdSysPlatform.hh
XrdCksCalccrc32::Final
char * Final() override
Final checksum.
Definition
XrdCksCalccrc32.cc:102
XrdCksCalccrc32::Init
void Init() override
Initialize.
Definition
XrdCksCalccrc32.cc:116
XrdCksCalccrc32::Update
void Update(const char *Buff, int BLen) override
Update current checksum.
Definition
XrdCksCalccrc32.cc:124
XrdCksCalccrc32::Combine
const char * Combine(const char *Cksum, int DLen) override
Combine checksum into current checksum.
Definition
XrdCksCalccrc32.cc:69
XrdCks
XrdCksCalccrc32.cc
Generated by
1.18.0