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