8 #include <botan/openpgp.h>
9 #include <botan/filters.h>
10 #include <botan/basefilt.h>
11 #include <botan/charset.h>
12 #include <botan/crc24.h>
20 const byte input[],
size_t length,
21 const std::string& label,
22 const std::map<std::string, std::string>& headers)
24 const std::string PGP_HEADER =
"-----BEGIN PGP " + label +
"-----\n";
25 const std::string PGP_TRAILER =
"-----END PGP " + label +
"-----\n";
26 const size_t PGP_WIDTH = 64;
28 std::string pgp_encoded = PGP_HEADER;
30 if(headers.find(
"Version") != headers.end())
31 pgp_encoded +=
"Version: " + headers.find(
"Version")->second +
'\n';
33 std::map<std::string, std::string>::const_iterator i = headers.begin();
34 while(i != headers.end())
36 if(i->first !=
"Version")
37 pgp_encoded += i->first +
": " + i->second +
'\n';
52 pgp_encoded += PGP_TRAILER;
61 const std::string& type)
63 std::map<std::string, std::string> empty;
72 std::map<std::string, std::string>& headers)
74 const size_t RANDOM_CHAR_LIMIT = 5;
76 const std::string PGP_HEADER1 =
"-----BEGIN PGP ";
77 const std::string PGP_HEADER2 =
"-----";
80 while(position != PGP_HEADER1.length())
85 if(b == PGP_HEADER1[position])
87 else if(position >= RANDOM_CHAR_LIMIT)
93 while(position != PGP_HEADER2.length())
98 if(b == PGP_HEADER2[position])
104 label +=
static_cast<char>(b);
108 bool end_of_headers =
false;
109 while(!end_of_headers)
111 std::string this_header;
118 this_header +=
static_cast<char>(b);
121 end_of_headers =
true;
122 for(
size_t j = 0; j != this_header.length(); ++j)
124 end_of_headers =
false;
128 std::string::size_type pos = this_header.find(
": ");
129 if(pos == std::string::npos)
132 std::string key = this_header.substr(0, pos);
133 std::string value = this_header.substr(pos + 2, std::string::npos);
134 headers[key] = value;
146 const std::string PGP_TRAILER =
"-----END PGP " + label +
"-----";
148 bool newline_seen = 0;
150 while(position != PGP_TRAILER.length())
155 if(b == PGP_TRAILER[position])
160 if(b ==
'=' && newline_seen)
167 crc +=
static_cast<char>(b);
172 else if(position == 0)
175 newline_seen =
false;
191 std::map<std::string, std::string> ignored;
SecureVector< byte > PGP_decode(DataSource &source, std::string &label, std::map< std::string, std::string > &headers)
std::string PGP_encode(const byte input[], size_t length, const std::string &label, const std::map< std::string, std::string > &headers)
std::string read_all_as_string(message_id=DEFAULT_MESSAGE)
void write(const byte in[], size_t length)
SecureVector< byte > read_all(message_id msg=DEFAULT_MESSAGE)
size_t read_byte(byte &out)
void process_msg(const byte in[], size_t length)