forked from calccrypto/OpenPGP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCleartextSignature.h
111 lines (93 loc) · 4.67 KB
/
CleartextSignature.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
CleartextSignature.h
OpenPGP Cleartext Signature Framework data structure (RFC 4880 sec 7)
Copyright (c) 2013 - 2018 Jason Lee @ calccrypto at gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef __OPENPGP_CLEARTEXT_SIGNATURE__
#define __OPENPGP_CLEARTEXT_SIGNATURE__
#include "Misc/sigcalc.h"
#include "PGP.h"
#include "DetachedSignature.h"
namespace OpenPGP {
// 7. Cleartext Signature Framework
//
// It is desirable to be able to sign a textual octet stream without
// ASCII armoring the stream itself, so the signed text is still
// readable without special software. In order to bind a signature to
// such a cleartext, this framework is used. (Note that this framework
// is not intended to be reversible. RFC 3156 [RFC3156] defines another
// way to sign cleartext messages for environments that support MIME.)
//
// The cleartext signed message consists of:
//
// - The cleartext header ’-----BEGIN PGP SIGNED MESSAGE-----’ on a
// single line,
//
// - One or more "Hash" Armor Headers,
//
// - Exactly one empty line not included into the message digest,
//
// - The dash-escaped cleartext that is included into the message
// digest,
//
// - The ASCII armored signature(s) including the ’-----BEGIN PGP
// SIGNATURE-----’ Armor Header and Armor Tail Lines.
//
// If the "Hash" Armor Header is given, the specified message digest
// algorithm(s) are used for the signature. If there are no such
// headers, MD5 is used. If MD5 is the only hash used, then an
// implementation MAY omit this header for improved V2.x compatibility.
// If more than one message digest is used in the signature, the "Hash"
// armor header contains a comma-delimited list of used message digests.
// Current message digest names are described below with the algorithm
// IDs.
//
// An implementation SHOULD add a line break after the cleartext, but
// MAY omit it if the cleartext ends with a line break. This is for
// visual clarity.
class CleartextSignature {
private:
PGP::Armor_Keys hash_armor_header;
std::string message;
DetachedSignature sig;
public:
typedef std::shared_ptr <CleartextSignature> Ptr;
CleartextSignature();
CleartextSignature(const CleartextSignature & copy);
CleartextSignature(const std::string & data);
CleartextSignature(std::istream & stream);
void read(const std::string & data);
void read(std::istream & stream);
std::string show(const std::size_t indents = 0, const std::size_t indent_size = 4) const;
std::string write(const Packet::Tag::Format header = Packet::Tag::Format::DEFAULT) const;
PGP::Armor_Keys get_hash_armor_header() const;
std::string get_message() const;
DetachedSignature get_sig() const;
void set_hash_armor_header(const PGP::Armor_Keys & keys);
void set_message(const std::string & data);
void set_sig(const DetachedSignature & s);
static std::string dash_escape(const std::string & text);
static std::string reverse_dash_escape(const std::string & text);
std::string data_to_text() const; // remove trailing whitespace
static std::string data_to_text(const std::string & text); // remove trailing whitespace
bool meaningful() const;
CleartextSignature & operator=(const CleartextSignature & copy);
CleartextSignature::Ptr clone() const;
};
}
#endif