~ubuntu-branches/debian/experimental/apt/experimental

« back to all changes in this revision

Viewing changes to apt-pkg/contrib/hashes.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2010-02-18 22:07:23 UTC
  • mfrom: (9.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100218220723-zb7zdh6fmsmp30tr
Tags: 0.7.26~exp2
fix crash when LANGUAGE is not set

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
   ##################################################################### */
12
12
                                                                        /*}}}*/
13
13
// Include Files                                                        /*{{{*/
14
 
#include <apt-pkg/contrib/hashes.h>
15
 
#include <apt-pkg/contrib/fileutl.h>
16
 
#include <apt-pkg/contrib/configuration.h>
17
 
    
 
14
#include <apt-pkg/hashes.h>
 
15
#include <apt-pkg/fileutl.h>
 
16
#include <apt-pkg/configuration.h>
 
17
#include <apt-pkg/macros.h>
 
18
 
18
19
#include <unistd.h>    
19
 
#include <apt-pkg/contrib/system.h>    
20
20
#include <string>
21
21
#include <iostream>
22
22
                                                                        /*}}}*/
34
34
{
35
35
}
36
36
 
37
 
HashString::HashString(string StringedHash)
 
37
HashString::HashString(string StringedHash)                             /*{{{*/
38
38
{
39
39
   // legacy: md5sum without "MD5Sum:" prefix
40
40
   if (StringedHash.find(":") == string::npos && StringedHash.size() == 32)
50
50
   if(_config->FindB("Debug::Hashes",false) == true)
51
51
      std::clog << "HashString(string): " << Type << " : " << Hash << std::endl;
52
52
}
53
 
 
54
 
 
55
 
bool HashString::VerifyFile(string filename) const
 
53
                                                                        /*}}}*/
 
54
bool HashString::VerifyFile(string filename) const                      /*{{{*/
56
55
{
57
56
   FileFd fd;
58
57
   MD5Summation MD5;
83
82
 
84
83
   return (fileHash == Hash);
85
84
}
86
 
 
 
85
                                                                        /*}}}*/
87
86
const char** HashString::SupportedHashes()
88
87
{
89
88
   return _SupportedHashes;
94
93
   return (Type.empty() || Hash.empty());
95
94
}
96
95
 
97
 
 
98
96
string HashString::toStr() const
99
97
{
100
98
   return Type+string(":")+Hash;
101
99
}
102
100
 
103
 
 
104
101
// Hashes::AddFD - Add the contents of the FD                           /*{{{*/
105
102
// ---------------------------------------------------------------------
106
103
/* */
108
105
{
109
106
   unsigned char Buf[64*64];
110
107
   int Res = 0;
111
 
   while (Size != 0)
 
108
   int ToEOF = (Size == 0);
 
109
   while (Size != 0 || ToEOF)
112
110
   {
113
 
      Res = read(Fd,Buf,min(Size,(unsigned long)sizeof(Buf)));
114
 
      if (Res < 0 || (unsigned)Res != min(Size,(unsigned long)sizeof(Buf)))
115
 
         return false;
 
111
      unsigned n = sizeof(Buf);
 
112
      if (!ToEOF) n = min(Size,(unsigned long)n);
 
113
      Res = read(Fd,Buf,n);
 
114
      if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read
 
115
         return false;
 
116
      if (ToEOF && Res == 0) // EOF
 
117
         break;
116
118
      Size -= Res;
117
119
      MD5.Add(Buf,Res);
118
120
      SHA1.Add(Buf,Res);