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";
34 const std::string& label_want)
36 std::string label_got;
38 if(label_got != label_want)
40 ", got " + label_got);
49 const size_t RANDOM_CHAR_LIMIT = 8;
51 const std::string PEM_HEADER1 =
"-----BEGIN ";
52 const std::string PEM_HEADER2 =
"-----";
55 while(position != PEM_HEADER1.length())
60 if(b == PEM_HEADER1[position])
62 else if(position >= RANDOM_CHAR_LIMIT)
68 while(position != PEM_HEADER2.length())
73 if(b == PEM_HEADER2[position])
79 label +=
static_cast<char>(b);
85 const std::string PEM_TRAILER =
"-----END " + label +
"-----";
87 while(position != PEM_TRAILER.length())
92 if(b == PEM_TRAILER[position])
105 const std::string& label_want)
114 return decode(src, label);
123 const std::string PEM_HEADER =
"-----BEGIN " + extra;
126 size_t got = source.
peek(&search_buf[0], search_buf.size(), 0);
128 if(got < PEM_HEADER.length())
133 for(
size_t j = 0; j != got; ++j)
135 if(search_buf[j] == PEM_HEADER[index])
139 if(index == PEM_HEADER.size())