forked from calccrypto/OpenPGP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetachedSignature.cpp
77 lines (60 loc) · 1.77 KB
/
DetachedSignature.cpp
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
#include "DetachedSignature.h"
namespace OpenPGP {
DetachedSignature::DetachedSignature()
: PGP()
{
type = SIGNATURE;
}
DetachedSignature::DetachedSignature(const PGP & copy)
: PGP(copy)
{}
DetachedSignature::DetachedSignature(const DetachedSignature & copy)
: PGP(copy)
{
type = SIGNATURE;
}
DetachedSignature::DetachedSignature(const std::string & data)
: PGP(data)
{
type = SIGNATURE;
// warn if packet sequence is not meaningful
if (!meaningful()){
throw std::runtime_error("Error: Data does not form a meaningful PGP Detached Signature");
}
}
DetachedSignature::DetachedSignature(std::istream & stream)
: PGP(stream)
{
type = SIGNATURE;
// warn if packet sequence is not meaningful
if (!meaningful()){
throw std::runtime_error("Error: Data does not form a meaningful PGP Detached Signature");
}
}
DetachedSignature::~DetachedSignature(){}
bool DetachedSignature::meaningful(const PGP & pgp){
if (pgp.get_type() != SIGNATURE){
// "Error: ASCII Armor type is not SIGNATURE.\n";
return false;
}
if (pgp.get_packets().size() != 1){
// "Error: Wrong number of packets.\n";
return false;
}
// if (pgp.get_packets()[0] -> get_tag() != Packet::SIGNATURE){
// // "Error: Packet is not a signature packet.\n";
// return false;
// }
// if (!Signature_Type::is_signed_document(std::static_pointer_cast <Packet::Tag2> (pgp.get_packets()[0]) -> get_type())){
// // "Error: Signature type is not over a document.\n";
// return false;
// }
return true;
}
bool DetachedSignature::meaningful() const{
return meaningful(*this);
}
PGP::Ptr DetachedSignature::clone() const{
return std::make_shared <DetachedSignature> (*this);
}
}