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