Botan 3.0.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#include <botan/pk_keys.h>
10#include <botan/internal/parsing.h>
11#include <vector>
12
13namespace Botan {
14
15std::string Key_Constraints::to_string() const
16 {
17 if(this->m_value == Key_Constraints::None)
18 return "no_constraints";
19
20 std::vector<std::string> str;
21
22 if(this->m_value & Key_Constraints::DigitalSignature)
23 str.push_back("digital_signature");
24
25 if(this->m_value & Key_Constraints::NonRepudiation)
26 str.push_back("non_repudiation");
27
28 if(this->m_value & Key_Constraints::KeyEncipherment)
29 str.push_back("key_encipherment");
30
31 if(this->m_value & Key_Constraints::DataEncipherment)
32 str.push_back("data_encipherment");
33
34 if(this->m_value & Key_Constraints::KeyAgreement)
35 str.push_back("key_agreement");
36
37 if(this->m_value & Key_Constraints::KeyCertSign)
38 str.push_back("key_cert_sign");
39
40 if(this->m_value & Key_Constraints::CrlSign)
41 str.push_back("crl_sign");
42
43 if(this->m_value & Key_Constraints::EncipherOnly)
44 str.push_back("encipher_only");
45
46 if(this->m_value & Key_Constraints::DecipherOnly)
47 str.push_back("decipher_only");
48
49 // Not 0 (checked at start) but nothing matched above!
50 if(str.empty())
51 return "other_unknown_constraints";
52
53 return string_join(str, ',');
54 }
55
56/*
57* Make sure the given key constraints are permitted for the given key type
58*/
60 {
61 uint32_t permitted = 0;
62
64 {
68 }
69
72 {
75 }
76
78 {
83 }
84
85 if((m_value & permitted) != m_value)
86 {
87 return false;
88 }
89
90 return true;
91 }
92
93}
virtual bool supports_operation(PublicKeyOperation op) const =0
bool compatible_with(const Public_Key &key) const
std::string to_string() const
Definition: alg_id.cpp:12
std::string string_join(const std::vector< std::string > &strs, char delim)
Definition: parsing.cpp:147