9 #include <botan/filters.h>
10 #include <botan/parsing.h>
19 std::string
encode(
const byte der[],
size_t length,
const std::string& label,
22 const std::string PEM_HEADER =
"-----BEGIN " + label +
"-----\n";
23 const std::string PEM_TRAILER =
"-----END " + label +
"-----\n";
36 return encode(&data[0], data.
size(), label, width);
43 const std::string& label_want)
45 std::string label_got;
47 if(label_got != label_want)
49 ", got " + label_got);
58 const size_t RANDOM_CHAR_LIMIT = 8;
60 const std::string PEM_HEADER1 =
"-----BEGIN ";
61 const std::string PEM_HEADER2 =
"-----";
64 while(position != PEM_HEADER1.length())
69 if(b == PEM_HEADER1[position])
71 else if(position >= RANDOM_CHAR_LIMIT)
77 while(position != PEM_HEADER2.length())
82 if(b == PEM_HEADER2[position])
88 label +=
static_cast<char>(b);
94 const std::string PEM_TRAILER =
"-----END " + label +
"-----";
96 while(position != PEM_TRAILER.length())
101 if(b == PEM_TRAILER[position])
119 const std::string PEM_HEADER =
"-----BEGIN " + extra;
122 size_t got = source.
peek(&search_buf[0], search_buf.
size(), 0);
124 if(got < PEM_HEADER.length())
129 for(
size_t j = 0; j != got; ++j)
131 if(search_buf[j] == PEM_HEADER[index])
135 if(index == PEM_HEADER.size())
std::string read_all_as_string(message_id=DEFAULT_MESSAGE)
void write(const byte in[], size_t length)
SecureVector< byte > decode(DataSource &source, std::string &label)
SecureVector< byte > read_all(message_id msg=DEFAULT_MESSAGE)
virtual size_t peek(byte out[], size_t length, size_t peek_offset) const =0
size_t read_byte(byte &out)
bool matches(DataSource &source, const std::string &extra, size_t search_range)
std::string encode(const byte der[], size_t length, const std::string &label, size_t width)
SecureVector< byte > decode_check_label(DataSource &source, const std::string &label_want)
void process_msg(const byte in[], size_t length)