23#include <zypp/base/Logger.h>
24#include <zypp/base/String.h>
56 memcpy(&
fsum[0], c, cl);
81 if (dig.empty() || dig.size() <
fsum.size())
83 return memcmp(&dig[0], &
fsum[0],
fsum.size()) ? false :
true;
102 memcpy(&
chksums[csl * blkno], cs, csl);
133 size_t size =
blocks[blkno].size;
143 if (dig.empty() || dig.size() <
size_t(
chksumlen))
154 s = (rs >> 16) & 65535;
156 for (; len > 0 ; len--)
158 unsigned short c = (
unsigned char)*bytes++;
162 return (s & 65535) << 16 | (m & 65535);
170 size_t size =
blocks[blkno].size;
176 s = (rs >> 16) & 65535;
179 rs = (s & 65535) << 16 | (m & 65535);
192 return rs ==
rsums[blkno];
198 if (blkno >=
blocks.size() || bufl <
blocks[blkno].size)
207 if (blkno >=
blocks.size() || bufl <
blocks[blkno].size)
235 if (blkno >=
blocks.size() || bufl <
blocks[blkno].size)
242 size_t size =
blocks[blkno].size;
243 size_t len = bufl - start > size ? size : bufl - start;
244 dig.
update((
const char *)buf + start, len);
246 dig.
update((
const char *)buf, size - len);
254 if (blkno >=
blocks.size() || bufl <
blocks[blkno].size)
256 off_t off =
blocks[blkno].off;
257 size_t size =
blocks[blkno].size;
258 if (fseeko(fp, off, SEEK_SET))
262 size_t len = bufl - start > size ? size : bufl - start;
263 if (fwrite(buf + start, len, 1, fp) != 1)
265 if (size > len && fwrite(buf, size - len, 1, fp) != 1)
268 found[
blocks.size()] =
true;
272fetchnext(FILE *fp,
unsigned char *bp,
size_t blksize,
size_t pushback,
unsigned char *pushbackp)
280 memmove(bp, pushbackp, pushback);
303 if (!
chksumlen || (fp = fopen(filename.c_str(),
"r")) == 0)
305 size_t nblks =
blocks.size();
306 std::vector<bool> found;
307 found.resize(nblks + 1);
310 size_t blksize =
blocks[0].size;
314 unsigned int hm =
rsums.size() * 2;
315 while (hm & (hm - 1))
320 unsigned int *ht =
new unsigned int[hm + 1];
321 memset(ht, 0, (hm + 1) *
sizeof(
unsigned int));
322 for (
unsigned int i = 0; i <
rsums.size(); i++)
324 if (
blocks[i].size != blksize && (i != nblks - 1 ||
rsumpad != blksize))
326 unsigned int r =
rsums[i];
327 unsigned int h = r & hm;
334 unsigned char *buf =
new unsigned char[blksize];
335 unsigned char *buf2 =
new unsigned char[blksize];
337 unsigned char *pushbackp = 0;
339 if ((blksize & (blksize - 1)) == 0)
340 for (bshift = 0; size_t(1 << bshift) != blksize; bshift++)
344 memset(buf, 0, blksize);
347 int sql = nblks > 1 &&
chksumlen < 16 ? 2 : 1;
350 for (
size_t i = 0; i < blksize; i++)
376 b += a - (oc << bshift);
378 b += a - oc * blksize;
381 if (
size_t(i) != blksize - 1)
387 r = ((
unsigned int)b & 255);
389 r = ((
unsigned int)b & 65535);
391 r = ((
unsigned int)a & 255) << 16 | ((
unsigned int)b & 65535);
393 r = ((
unsigned int)a & 65535) << 16 | ((
unsigned int)b & 65535);
394 unsigned int h = r & hm;
396 for (; ht[h]; h = (h + hh++) & hm)
398 size_t blkno = ht[h] - 1;
399 if (
rsums[blkno] != r)
405 if (eof || blkno + 1 >= nblks)
407 pushback =
fetchnext(fp, buf2, blksize, pushback, pushbackp);
411 if (!
checkRsum(blkno + 1, buf2, blksize))
418 writeBlock(blkno, wfp, buf, blksize, i + 1, found);
421 writeBlock(blkno + 1, wfp, buf2, blksize, 0, found);
428 pushback =
fetchnext(fp, buf2, blksize, pushback, pushbackp);
436 writeBlock(blkno, wfp, buf2, blksize, 0, found);
440 memset(buf, 0, blksize);
456 unsigned char *buf =
new unsigned char[bufl];
457 for (
size_t blkno = 0; blkno <
blocks.size(); ++blkno)
459 if (off >
blocks[blkno].off)
461 size_t blksize =
blocks[blkno].size;
466 buf =
new unsigned char[bufl];
468 size_t skip =
blocks[blkno].off - off;
471 size_t l = skip > bufl ? bufl : skip;
472 if (fread(buf, l, 1, fp) != 1)
477 if (fread(buf, blksize, 1, fp) != 1)
480 writeBlock(blkno, wfp, buf, blksize, 0, found);
487 std::vector<MediaBlock> nblocks;
488 std::vector<unsigned char> nchksums;
489 std::vector<unsigned int> nrsums;
491 for (
size_t blkno = 0; blkno <
blocks.size(); ++blkno)
496 nblocks.push_back(
blocks[blkno]);
499 nchksums.resize(nblocks.size() *
chksumlen);
503 nrsums.push_back(
rsums[blkno]);
523 s =
"[ BlockList, filesize unknown\n";
525 s +=
" No block information\n";
530 for (i = 0; i <
blocks.size(); ++i)
532 long long off=
blocks[i].off;
533 long long size=
blocks[i].size;
Compute Message Digests (MD5, SHA1 etc)
UByteArray digestVector()
get vector of unsigned char representation of the digest
bool update(const char *bytes, size_t len)
feed data into digest computation algorithm
bool create(const std::string &name)
initialize creation of a new message digest
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Easy-to use interface to the ZYPP dependency resolver.