Botan  2.1.0
Crypto and TLS for C++11
pem.h
Go to the documentation of this file.
1 /*
2 * PEM Encoding/Decoding
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_PEM_H__
9 #define BOTAN_PEM_H__
10 
11 #include <botan/data_src.h>
12 
13 namespace Botan {
14 
15 namespace PEM_Code {
16 
17 /**
18 * Encode some binary data in PEM format
19 * @param data binary data to encode
20 * @param data_len length of binary data in bytes
21 * @param label PEM label put after BEGIN and END
22 * @param line_width after this many characters, a new line is inserted
23 */
24 BOTAN_DLL std::string encode(const uint8_t data[],
25  size_t data_len,
26  const std::string& label,
27  size_t line_width = 64);
28 
29 /**
30 * Encode some binary data in PEM format
31 * @param data binary data to encode
32 * @param label PEM label
33 * @param line_width after this many characters, a new line is inserted
34 */
35 inline std::string encode(const std::vector<uint8_t>& data,
36  const std::string& label,
37  size_t line_width = 64)
38  {
39  return encode(data.data(), data.size(), label, line_width);
40  }
41 
42 /**
43 * Encode some binary data in PEM format
44 * @param data binary data to encode
45 * @param label PEM label put after BEGIN and END
46 * @param line_width after this many characters, a new line is inserted
47 */
48 inline std::string encode(const secure_vector<uint8_t>& data,
49  const std::string& label,
50  size_t line_width = 64)
51  {
52  return encode(data.data(), data.size(), label, line_width);
53  }
54 
55 /**
56 * Decode PEM data
57 * @param pem a datasource containing PEM encoded data
58 * @param label is set to the PEM label found for later inspection
59 */
61  std::string& label);
62 
63 /**
64 * Decode PEM data
65 * @param pem a string containing PEM encoded data
66 * @param label is set to the PEM label found for later inspection
67 */
68 BOTAN_DLL secure_vector<uint8_t> decode(const std::string& pem,
69  std::string& label);
70 
71 /**
72 * Decode PEM data
73 * @param pem a datasource containing PEM encoded data
74 * @param label is what we expect the label to be
75 */
77  DataSource& pem,
78  const std::string& label);
79 
80 /**
81 * Decode PEM data
82 * @param pem a string containing PEM encoded data
83 * @param label is what we expect the label to be
84 */
86  const std::string& pem,
87  const std::string& label);
88 
89 /**
90 * Heuristic test for PEM data.
91 */
92 BOTAN_DLL bool matches(DataSource& source,
93  const std::string& extra = "",
94  size_t search_range = 4096);
95 
96 }
97 
98 }
99 
100 #endif
secure_vector< uint8_t > decode(DataSource &source, std::string &label)
Definition: pem.cpp:68
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:43
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Definition: alg_id.cpp:13
bool matches(DataSource &source, const std::string &extra, size_t search_range)
Definition: pem.cpp:140
secure_vector< uint8_t > decode_check_label(DataSource &source, const std::string &label_want)
Definition: pem.cpp:54