Botan 3.9.0
Crypto and TLS for C&
key_constraint.cpp
Go to the documentation of this file.
1/*
2* (C) 1999-2007,2016 Jack Lloyd
3* (C) 2016 René Korthaus, Rohde & Schwarz Cybersecurity
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/pkix_enums.h>
9
10#include <botan/pk_keys.h>
11#include <botan/internal/parsing.h>
12#include <vector>
13
14namespace Botan {
15
16std::string Key_Constraints::to_string() const {
17 if(this->m_value == Key_Constraints::None) {
18 return "no_constraints";
19 }
20
21 std::vector<std::string> str;
22
23 auto usage_set = [value = m_value](const Key_Constraints::Bits usage) { return ((value & usage) == usage); };
24
26 str.push_back("digital_signature");
27 }
28
29 if(usage_set(Key_Constraints::NonRepudiation)) {
30 str.push_back("non_repudiation");
31 }
32
34 str.push_back("key_encipherment");
35 }
36
38 str.push_back("data_encipherment");
39 }
40
41 if(usage_set(Key_Constraints::KeyAgreement)) {
42 str.push_back("key_agreement");
43 }
44
45 if(usage_set(Key_Constraints::KeyCertSign)) {
46 str.push_back("key_cert_sign");
47 }
48
49 if(usage_set(Key_Constraints::CrlSign)) {
50 str.push_back("crl_sign");
51 }
52
53 if(usage_set(Key_Constraints::EncipherOnly)) {
54 str.push_back("encipher_only");
55 }
56
57 if(usage_set(Key_Constraints::DecipherOnly)) {
58 str.push_back("decipher_only");
59 }
60
61 // Not 0 (checked at start) but nothing matched above!
62 if(str.empty()) {
63 return "other_unknown_constraints";
64 }
65
66 return string_join(str, ',');
67}
68
69/*
70* Make sure the given key constraints are permitted for the given key type
71*/
98
99} // namespace Botan
virtual bool supports_operation(PublicKeyOperation op) const =0
bool compatible_with(const Public_Key &key) const
std::string to_string() const
uint32_t value() const
Definition pkix_enums.h:180
std::string string_join(const std::vector< std::string > &strs, char delim)
Definition parsing.cpp:140