Botan  2.4.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/secmem.h>
12 #include <string>
13 
14 namespace Botan {
15 
16 class DataSource;
17 
18 namespace PEM_Code {
19 
20 /**
21 * Encode some binary data in PEM format
22 * @param data binary data to encode
23 * @param data_len length of binary data in bytes
24 * @param label PEM label put after BEGIN and END
25 * @param line_width after this many characters, a new line is inserted
26 */
27 BOTAN_PUBLIC_API(2,0) std::string encode(const uint8_t data[],
28  size_t data_len,
29  const std::string& label,
30  size_t line_width = 64);
31 
32 /**
33 * Encode some binary data in PEM format
34 * @param data binary data to encode
35 * @param label PEM label
36 * @param line_width after this many characters, a new line is inserted
37 */
38 template<typename Alloc>
39 std::string encode(const std::vector<uint8_t, Alloc>& data,
40  const std::string& label,
41  size_t line_width = 64)
42  {
43  return encode(data.data(), data.size(), label, line_width);
44  }
45 
46 /**
47 * Decode PEM data
48 * @param pem a datasource containing PEM encoded data
49 * @param label is set to the PEM label found for later inspection
50 */
52  std::string& label);
53 
54 /**
55 * Decode PEM data
56 * @param pem a string containing PEM encoded data
57 * @param label is set to the PEM label found for later inspection
58 */
59 BOTAN_PUBLIC_API(2,0) secure_vector<uint8_t> decode(const std::string& pem,
60  std::string& label);
61 
62 /**
63 * Decode PEM data
64 * @param pem a datasource containing PEM encoded data
65 * @param label is what we expect the label to be
66 */
69  const std::string& label);
70 
71 /**
72 * Decode PEM data
73 * @param pem a string containing PEM encoded data
74 * @param label is what we expect the label to be
75 */
77 secure_vector<uint8_t> decode_check_label(const std::string& pem,
78  const std::string& label);
79 
80 /**
81 * Heuristic test for PEM data.
82 */
83 BOTAN_PUBLIC_API(2,0) bool matches(DataSource& source,
84  const std::string& extra = "",
85  size_t search_range = 4096);
86 
87 }
88 
89 }
90 
91 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
Definition: bigint.h:635
secure_vector< uint8_t > decode_check_label(DataSource &source, const std::string &label_want)
Definition: pem.cpp:54
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:43
bool matches(DataSource &source, const std::string &extra, size_t search_range)
Definition: pem.cpp:142
secure_vector< uint8_t > decode(DataSource &source, std::string &label)
Definition: pem.cpp:68
Definition: alg_id.cpp:13
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88