Move CertificateChain into the right header.
[libdcp.git] / src / signer.h
1 /*
2     Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef LIBDCP_SIGNER_H
21 #define LIBDCP_SIGNER_H
22
23 /** @file  src/signer.h
24  *  @brief Signer class.
25  */
26
27 #include "certificates.h"
28 #include "certificate_chain.h"
29 #include "types.h"
30 #include <boost/filesystem.hpp>
31
32 namespace xmlpp {
33         class Element;
34         class Node;
35 }
36
37 namespace dcp {
38
39 /** @class Signer
40  *  @brief A class which can sign XML files.
41  */
42 class Signer
43 {
44 public:
45         Signer (boost::filesystem::path openssl);
46
47         Signer (
48                 boost::filesystem::path openssl,
49                 std::string organisation,
50                 std::string organisational_unit,
51                 std::string root_common_name,
52                 std::string intermediate_common_name,
53                 std::string leaf_common_name
54                 );
55
56         /** @param c Certificate chain to sign with.
57          *  @param k Key to sign with as a PEM-format string.
58          */
59         Signer (CertificateChain c, std::string k)
60                 : _certificates (c)
61                 , _key (k)
62         {}
63
64         void sign (xmlpp::Element* parent, Standard standard) const;
65         void add_signature_value (xmlpp::Node* parent, std::string ns) const;
66
67         CertificateChain const & certificates () const {
68                 return _certificates;
69         }
70
71         CertificateChain& certificates () {
72                 return _certificates;
73         }
74
75         std::string key () const {
76                 return _key;
77         }
78
79         void set_key (std::string k) {
80                 _key = k;
81         }
82
83         bool valid () const;
84
85 private:
86         void create (boost::filesystem::path directory);
87
88         /** Certificate chain to sign with */
89         CertificateChain _certificates;
90         /** Key to sign with as a PEM-format string */
91         std::string _key;
92 };
93
94 }
95
96 #endif