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