Botan 1.10.17

x509_obj.h
Go to the documentation of this file.
1 /*
2 * X.509 SIGNED Object
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_X509_OBJECT_H__
9 #define BOTAN_X509_OBJECT_H__
10
11 #include <botan/asn1_obj.h>
12 #include <botan/pipe.h>
13 #include <botan/pubkey_enums.h>
14 #include <botan/rng.h>
15 #include <vector>
16
17 namespace Botan {
18
19 /**
20 * This class represents abstract X.509 signed objects as
21 * in the X.500 SIGNED macro
22 */
23 class BOTAN_DLL X509_Object
24 {
25 public:
26 /**
27 * The underlying data that is to be or was signed
28 * @return data that is or was signed
29 */
30 MemoryVector<byte> tbs_data() const;
31
32 /**
33 * @return signature on tbs_data()
34 */
35 MemoryVector<byte> signature() const;
36
37 /**
38 * @return signature algorithm that was used to generate signature
39 */
40 AlgorithmIdentifier signature_algorithm() const;
41
42 /**
43 * @return hash algorithm that was used to generate signature
44 */
45 std::string hash_used_for_signature() const;
46
47 /**
48 * Create a signed X509 object.
49 * @param signer the signer used to sign the object
50 * @param rng the random number generator to use
51 * @param alg_id the algorithm identifier of the signature scheme
52 * @param tbs the tbs bits to be signed
53 * @return signed X509 object
54 */
55 static MemoryVector<byte> make_signed(class PK_Signer* signer,
56 RandomNumberGenerator& rng,
57 const AlgorithmIdentifier& alg_id,
58 const MemoryRegion<byte>& tbs);
59
60 /**
61 * Check the signature on this data
62 * @param key the public key purportedly used to sign this data
63 * @return true if the signature is valid, otherwise false
64 */
65 bool check_signature(class Public_Key& key) const;
66
67 /**
68 * Check the signature on this data
69 * @param key the public key purportedly used to sign this data
70 * the pointer will be deleted after use
71 * @return true if the signature is valid, otherwise false
72 */
73 bool check_signature(class Public_Key* key) const;
74
75 /**
76 * @return BER encoding of this
77 */
78 MemoryVector<byte> BER_encode() const;
79
80 /**
81 * @return PEM encoding of this
82 */
83 std::string PEM_encode() const;
84
85 /**
86 * Encode this to a pipe
87 * @deprecated use BER_encode or PEM_encode instead
88 * @param out the pipe to write to
89 * @param encoding the encoding to use
90 */
91 BOTAN_DEPRECATED("Use BER_encode or PEM_encode")
92 void encode(Pipe& out, X509_Encoding encoding = PEM) const;
93
94 virtual ~X509_Object() {}
95 protected:
96 X509_Object(DataSource& src, const std::string& pem_labels);
97 X509_Object(const std::string& file, const std::string& pem_labels);
98
99 void do_decode();
100 X509_Object() {}
101 AlgorithmIdentifier sig_algo;
102 MemoryVector<byte> tbs_bits, sig;
103 private:
104 virtual void force_decode() = 0;
105 void init(DataSource&, const std::string&);
106 void decode_info(DataSource&);
107 std::vector<std::string> PEM_labels_allowed;
108 std::string PEM_label_pref;
109 };
110
111 }
112
113 #endif
Botan::X509_Object::tbs_bits
MemoryVector< byte > tbs_bits
Definition: x509_obj.h:102
Botan::PKCS8::BER_encode
SecureVector< byte > BER_encode(const Private_Key &key)
Definition: pkcs8.cpp:134
Botan::RandomNumberGenerator
Definition: rng.h:20
Botan::X509_Encoding
X509_Encoding
Definition: pubkey_enums.h:67
Botan::PKCS8::PEM_encode
std::string PEM_encode(const Private_Key &key)
Definition: pkcs8.cpp:150
Botan::DataSource
Definition: data_src.h:20
Botan::X509_Object::sig_algo
AlgorithmIdentifier sig_algo
Definition: x509_obj.h:101
Botan::X509_Object::X509_Object
X509_Object()
Definition: x509_obj.h:100
Botan::X509_Object
Definition: x509_obj.h:23
Botan::X509_Object::~X509_Object
virtual ~X509_Object()
Definition: x509_obj.h:94
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::PEM
Definition: pubkey_enums.h:67
Botan::MemoryVector< byte >
Botan::Public_Key
Definition: pk_keys.h:21
Botan::PEM_Code::encode
std::string encode(const byte der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:19
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::Pipe
Definition: pipe.h:25
Botan::PK_Signer
Definition: pubkey.h:123