]> git.saurik.com Git - apt.git/blame - apt-pkg/contrib/sha2.cc
apt-pkg/contrib/sha2.{cc,h}: move duplicated AddFD to baseclass
[apt.git] / apt-pkg / contrib / sha2.cc
CommitLineData
54ce88fd 1/*
84a0890e 2 * Cryptographic API. {{{
54ce88fd 3 *
84a0890e
MV
4 * SHA-512, as specified in
5 * http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf
54ce88fd 6 *
84a0890e
MV
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
54ce88fd 11 *
84a0890e 12 */ /*}}}*/
54ce88fd 13
84a0890e 14#ifdef __GNUG__
7ac56f8f 15#pragma implementation "apt-pkg/sha2.h"
54ce88fd
MV
16#endif
17
84a0890e
MV
18#include <apt-pkg/sha2.h>
19#include <apt-pkg/strutl.h>
20
31693a8f 21// SHA2Summation::AddFD - Add content of file into the checksum /*{{{*/
84a0890e
MV
22// ---------------------------------------------------------------------
23/* */
31693a8f 24bool SHA2SummationBase::AddFD(int Fd,unsigned long Size){
84a0890e
MV
25 unsigned char Buf[64 * 64];
26 int Res = 0;
27 int ToEOF = (Size == 0);
28 while (Size != 0 || ToEOF)
29 {
30 unsigned n = sizeof(Buf);
31 if (!ToEOF) n = min(Size,(unsigned long)n);
32 Res = read(Fd,Buf,n);
33 if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read
34 return false;
35 if (ToEOF && Res == 0) // EOF
36 break;
37 Size -= Res;
38 Add(Buf,Res);
39 }
40 return true;
41}
42 /*}}}*/
54ce88fd 43