-
Notifications
You must be signed in to change notification settings - Fork 45
/
Digest.h
82 lines (71 loc) · 3.39 KB
/
Digest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* libdigidocpp
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#pragma once
#include "../Exports.h"
#include <string>
#include <vector>
#define URI_SHA1 "http://www.w3.org/2000/09/xmldsig#sha1"
#define URI_SHA224 "http://www.w3.org/2001/04/xmldsig-more#sha224"
#define URI_SHA256 "http://www.w3.org/2001/04/xmlenc#sha256"
#define URI_SHA384 "http://www.w3.org/2001/04/xmldsig-more#sha384"
#define URI_SHA512 "http://www.w3.org/2001/04/xmlenc#sha512"
#define URI_RSA_SHA1 "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
#define URI_RSA_SHA224 "http://www.w3.org/2001/04/xmldsig-more#rsa-sha224"
#define URI_RSA_SHA256 "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
#define URI_RSA_SHA384 "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384"
#define URI_RSA_SHA512 "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"
#define URI_RSA_PSS_SHA224 "http://www.w3.org/2007/05/xmldsig-more#sha224-rsa-MGF1"
#define URI_RSA_PSS_SHA256 "http://www.w3.org/2007/05/xmldsig-more#sha256-rsa-MGF1"
#define URI_RSA_PSS_SHA384 "http://www.w3.org/2007/05/xmldsig-more#sha384-rsa-MGF1"
#define URI_RSA_PSS_SHA512 "http://www.w3.org/2007/05/xmldsig-more#sha512-rsa-MGF1"
#define URI_ECDSA_SHA1 "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1"
#define URI_ECDSA_SHA224 "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha224"
#define URI_ECDSA_SHA256 "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"
#define URI_ECDSA_SHA384 "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384"
#define URI_ECDSA_SHA512 "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512"
namespace digidoc
{
/**
* Digest calculation interface.
*/
class Digest
{
public:
Digest(const std::string &uri = {});
~Digest();
void reset(const std::string &uri = {});
void update(const std::vector<unsigned char> &data);
void update(const unsigned char *data, size_t length);
std::vector<unsigned char> result() const;
std::string uri() const;
static bool isRsaPssUri(const std::string &uri);
static std::string toRsaUri(const std::string &uri);
static std::string toRsaPssUri(const std::string &uri);
static std::string toEcUri(const std::string &uri);
static int toMethod(const std::string &uri);
static std::string toUri(int nid);
static std::vector<unsigned char> addDigestInfo(const std::vector<unsigned char> &digest, const std::string &uri);
static std::vector<unsigned char> digestInfoDigest(const std::vector<unsigned char> &digest);
static std::string digestInfoUri(const std::vector<unsigned char> &digest);
private:
DISABLE_COPY(Digest);
class Private;
Private *d;
};
}