1 // -*- mode: cpp; mode: fold -*-
3 // $Id: hashes.h,v 1.2 2001/03/11 05:30:20 jgg Exp $
4 /* ######################################################################
6 Hashes - Simple wrapper around the hash functions
8 This is just used to make building the methods simpler, this is the
9 only interface required..
11 ##################################################################### */
13 #ifndef APTPKG_HASHES_H
14 #define APTPKG_HASHES_H
17 #include <apt-pkg/md5.h>
18 #include <apt-pkg/sha1.h>
19 #include <apt-pkg/sha2.h>
24 #ifndef APT_8_CLEANER_HEADERS
28 #ifndef APT_10_CLEANER_HEADERS
29 #include <apt-pkg/fileutl.h>
37 // helper class that contains hash function name
44 static const char* _SupportedHashes
[10];
47 std::string
GetHashForFile(std::string filename
) const;
50 HashString(std::string Type
, std::string Hash
);
51 HashString(std::string StringedHashString
); // init from str as "type:hash"
55 std::string
HashType() { return Type
; };
57 // verify the given filename against the currently loaded hash
58 bool VerifyFile(std::string filename
) const;
60 // generate a hash string from the given filename
61 bool FromFile(std::string filename
);
65 std::string
toStr() const; // convert to str as "type:hash"
68 // return the list of hashes we support
69 static APT_CONST
const char** SupportedHashes();
78 SHA256Summation SHA256
;
79 SHA512Summation SHA512
;
81 static const int UntilEOF
= 0;
83 inline bool Add(const unsigned char *Data
,unsigned long long Size
)
85 return MD5
.Add(Data
,Size
) && SHA1
.Add(Data
,Size
) && SHA256
.Add(Data
,Size
) && SHA512
.Add(Data
,Size
);
87 inline bool Add(const char *Data
) {return Add((unsigned char const *)Data
,strlen(Data
));};
88 inline bool AddFD(int const Fd
,unsigned long long Size
= 0)
89 { return AddFD(Fd
, Size
, true, true, true, true); };
90 bool AddFD(int const Fd
, unsigned long long Size
, bool const addMD5
,
91 bool const addSHA1
, bool const addSHA256
, bool const addSHA512
);
92 inline bool AddFD(FileFd
&Fd
,unsigned long long Size
= 0)
93 { return AddFD(Fd
, Size
, true, true, true, true); };
94 bool AddFD(FileFd
&Fd
, unsigned long long Size
, bool const addMD5
,
95 bool const addSHA1
, bool const addSHA256
, bool const addSHA512
);
96 inline bool Add(const unsigned char *Beg
,const unsigned char *End
)
97 {return Add(Beg
,End
-Beg
);};