]> git.saurik.com Git - apt.git/blame - apt-pkg/contrib/sha256.h
* add "purge" commandline argument, closes: #133421)
[apt.git] / apt-pkg / contrib / sha256.h
CommitLineData
cde41ae8
MV
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3// $Id: sha1.h,v 1.3 2001/05/07 05:05:47 jgg Exp $
4/* ######################################################################
5
6 SHA256SumValue - Storage for a SHA-256 hash.
7 SHA256Summation - SHA-256 Secure Hash Algorithm.
8
9 This is a C++ interface to a set of SHA256Sum functions, that mirrors
10 the equivalent MD5 & SHA1 classes.
11
12 ##################################################################### */
13 /*}}}*/
14#ifndef APTPKG_SHA256_H
15#define APTPKG_SHA256_H
16
cde41ae8
MV
17#include <string>
18#include <algorithm>
cde41ae8
MV
19
20using std::string;
21using std::min;
22
23class SHA256Summation;
24
25class SHA256SumValue
26{
27 friend class SHA256Summation;
28 unsigned char Sum[32];
29
30 public:
31
32 // Accessors
33 bool operator ==(const SHA256SumValue &rhs) const;
34 string Value() const;
35 inline void Value(unsigned char S[32])
36 {for (int I = 0; I != sizeof(Sum); I++) S[I] = Sum[I];};
37 inline operator string() const {return Value();};
38 bool Set(string Str);
39 inline void Set(unsigned char S[32])
40 {for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];};
41
42 SHA256SumValue(string Str);
43 SHA256SumValue();
44};
45
46struct sha256_ctx {
47 uint32_t count[2];
48 uint32_t state[8];
49 uint8_t buf[128];
50};
51
52class SHA256Summation
53{
54 struct sha256_ctx Sum;
55
56 bool Done;
57
58 public:
59
60 bool Add(const unsigned char *inbuf,unsigned long inlen);
61 inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
62 bool AddFD(int Fd,unsigned long Size);
63 inline bool Add(const unsigned char *Beg,const unsigned char *End)
64 {return Add(Beg,End-Beg);};
65 SHA256SumValue Result();
66
67 SHA256Summation();
68};
69
70#endif