libzypp 17.31.23
mediablocklist.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_CURL_PARSER_MEDIABLOCKLIST_H
13#define ZYPP_CURL_PARSER_MEDIABLOCKLIST_H
14
15#include <sys/types.h>
16#include <vector>
17#include <optional>
18
19#include <zypp-core/Digest.h>
20
21namespace zypp {
22 namespace media {
23
27struct MediaBlock {
28 MediaBlock( off_t off_r, size_t size_r )
29 : off( off_r )
30 , size( size_r )
31 {}
32 off_t off;
33 size_t size;
34};
35
37public:
38 MediaBlockList(off_t filesize=off_t(-1));
39
44 inline bool haveBlocks() const {
45 return haveblocks;
46 }
52 size_t addBlock(off_t off, size_t size);
53
57 inline const MediaBlock &getBlock(size_t blkno) const {
58 return blocks[blkno];
59 }
63 inline size_t numBlocks() const {
64 return blocks.size();
65 }
66
70 inline void setFilesize(off_t newfilesize=off_t(-1)) {
71 filesize = newfilesize;
72 }
73 inline off_t getFilesize() const {
74 return filesize;
75 }
76 inline bool haveFilesize() const {
77 return filesize != off_t(-1);
78 }
79
83 void setFileChecksum(std::string ctype, int cl, unsigned char *c);
84 std::string fileChecksumType () const;
85
87 bool createFileDigest(Digest &digest) const;
88 bool verifyFileDigest(Digest &digest) const;
89 inline bool haveFileChecksum() const {
90 return !fsumtype.empty() && fsum.size();
91 }
92
96 void setChecksum(size_t blkno, std::string cstype, int csl, unsigned char *cs, size_t cspad=0);
97 bool checkChecksum(size_t blkno, const unsigned char *buf, size_t bufl) const;
98 UByteArray getChecksum( size_t blkno ) const;
99 std::string getChecksumType( ) const;
100 size_t checksumPad() const;
101 bool createDigest(Digest &digest) const;
102 bool verifyDigest(size_t blkno, Digest &digest) const;
103 inline bool haveChecksum(size_t blkno) const {
104 return chksumlen && chksums.size() >= chksumlen * (blkno + 1);
105 }
106
110 void setRsum(size_t blkno, int rsl, unsigned int rs, size_t rspad=0);
111
116 void setRsumSequence( uint seq );
117 bool checkRsum(size_t blkno, const unsigned char *buf, size_t bufl) const;
118 unsigned int updateRsum(unsigned int rs, const char *bytes, size_t len) const;
119 bool verifyRsum(size_t blkno, unsigned int rs) const;
120 inline bool haveRsum(size_t blkno) const {
121 return rsumlen && rsums.size() >= blkno + 1;
122 }
123
128 void reuseBlocksOld(FILE *wfp, std::string filename);
129 void reuseBlocks(FILE *wfp, std::string filename);
130
134 std::string asString() const;
135
136private:
137 void writeBlock(size_t blkno, FILE *fp, const unsigned char *buf, size_t bufl, size_t start, std::vector<bool> &found) const;
138 bool checkChecksumRotated(size_t blkno, const unsigned char *buf, size_t bufl, size_t start) const;
139
140 off_t filesize;
141 std::string fsumtype;
143
145 std::vector<MediaBlock> blocks;
146
147 std::string chksumtype;
149 size_t chksumpad;
150 std::vector<unsigned char> chksums;
151
153 uint rsumseq; // < how many consecutive matches are required
154 size_t rsumpad;
155 std::vector<unsigned int> rsums;
156};
157
158inline std::ostream & operator<<(std::ostream &str, const MediaBlockList &bl)
159{ return str << bl.asString(); }
160
161 } // namespace media
162} // namespace zypp
163
164#endif // ZYPP_CURL_PARSER_MEDIABLOCKLIST_H
Compute Message Digests (MD5, SHA1 etc)
Definition: Digest.h:37
std::vector< unsigned int > rsums
void setRsum(size_t blkno, int rsl, unsigned int rs, size_t rspad=0)
set / verify the (weak) rolling checksum over a single block
bool haveChecksum(size_t blkno) const
void setFileChecksum(std::string ctype, int cl, unsigned char *c)
set / verify the checksum over the whole file
bool verifyRsum(size_t blkno, unsigned int rs) const
void reuseBlocks(FILE *wfp, std::string filename)
const UByteArray & getFileChecksum()
void writeBlock(size_t blkno, FILE *fp, const unsigned char *buf, size_t bufl, size_t start, std::vector< bool > &found) const
bool createDigest(Digest &digest) const
std::string asString() const
return block list as string
void setRsumSequence(uint seq)
how many blocks in sequence need to have the correct checksums to be considered a match
const MediaBlock & getBlock(size_t blkno) const
return the offset/size of a block with number blkno
UByteArray getChecksum(size_t blkno) const
bool checkChecksumRotated(size_t blkno, const unsigned char *buf, size_t bufl, size_t start) const
std::vector< unsigned char > chksums
size_t addBlock(off_t off, size_t size)
add a block with offset off and size size to the block list.
unsigned int updateRsum(unsigned int rs, const char *bytes, size_t len) const
void setChecksum(size_t blkno, std::string cstype, int csl, unsigned char *cs, size_t cspad=0)
set / verify the (strong) checksum over a single block
bool verifyDigest(size_t blkno, Digest &digest) const
bool haveBlocks() const
do we have a blocklist describing the file? set to true when addBlock() is called
bool checkRsum(size_t blkno, const unsigned char *buf, size_t bufl) const
std::vector< MediaBlock > blocks
std::string getChecksumType() const
bool createFileDigest(Digest &digest) const
size_t numBlocks() const
return the number of blocks in the blocklist
bool verifyFileDigest(Digest &digest) const
void reuseBlocksOld(FILE *wfp, std::string filename)
scan a file for blocks from our blocklist.
std::string fileChecksumType() const
bool haveRsum(size_t blkno) const
void setFilesize(off_t newfilesize=off_t(-1))
set / return the size of the whole file
bool checkChecksum(size_t blkno, const unsigned char *buf, size_t bufl) const
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
a single block from the blocklist, consisting of an offset and a size
MediaBlock(off_t off_r, size_t size_r)