Reducing header overuse, non-inlining selected methods (CPPOST-35).
[shibboleth/cpp-opensaml.git] / saml / signature / ContentReference.h
1 /*
2  *  Copyright 2001-2009 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file saml/signature/ContentReference.h
19  * 
20  * SAML-specific signature reference profile.
21  */
22
23 #ifndef __saml_sigref_h__
24 #define __saml_sigref_h__
25
26 #include <saml/base.h>
27
28 #include <set>
29 #include <string>
30 #ifdef HAVE_GOOD_STL
31 # include <xmltooling/unicode.h>
32 #endif
33 #include <xmltooling/signature/ContentReference.h>
34
35 namespace xmltooling {
36     class XMLTOOL_API Namespace;
37     class XMLTOOL_API XMLObject;
38 };
39
40 namespace opensaml {
41
42     class SAML_API SignableObject;
43
44 #if defined (_MSC_VER)
45     #pragma warning( push )
46     #pragma warning( disable : 4251 )
47 #endif
48
49     /**
50      * SAML-specific signature reference profile.
51      */
52     class SAML_API ContentReference : public virtual xmlsignature::ContentReference
53     {
54     public:
55         /**
56          * Constructor.
57          * 
58          * @param signableObject    reference to object being signed
59          */
60         ContentReference(const SignableObject& signableObject)
61             : m_signableObject(signableObject), m_digest(NULL), m_c14n(NULL) {
62         }
63     
64         virtual ~ContentReference() {}
65
66         /**
67          * Given a "blank" native signature, creates signature reference
68          * appropriate for the SAML object being signed.
69          * 
70          * @param sig   native signature interface
71          */
72         virtual void createReferences(DSIGSignature* sig);
73         
74         /**
75          * Adds a namespace prefix for "inclusive" processing by an
76          * Exclusive C14N Transform applied to the object.
77          * An empty string will be transformed into "#default".
78          * 
79          * @param prefix    the prefix to add 
80          */
81         void addInclusivePrefix(const XMLCh* prefix);
82         
83         /**
84          * Sets the digest algorithm for the signature reference,
85          * using a constant.
86          * 
87          * @param digest    the digest algorithm
88          */
89         void setDigestAlgorithm(const XMLCh* digest) {
90             m_digest = digest;
91         }
92
93         /**
94          * Sets the canonicalization method to include in the reference,
95          * using a constant.
96          * 
97          * @param c14n  the canonicalization method
98          */
99         void setCanonicalizationMethod(const XMLCh* c14n) {
100             m_c14n = c14n;
101         }
102         
103     private:
104         void addPrefixes(const std::set<xmltooling::Namespace>& namespaces);
105         void addPrefixes(const xmltooling::XMLObject& xmlObject);
106
107         const SignableObject& m_signableObject;
108 #ifdef HAVE_GOOD_STL
109         std::set<xmltooling::xstring> m_prefixes;
110 #else
111         std::set<std::string> m_prefixes;
112 #endif
113         const XMLCh* m_digest;
114         const XMLCh* m_c14n;
115     };
116
117 #if defined (_MSC_VER)
118     #pragma warning( pop )
119 #endif
120 };
121
122 #endif /* __saml_sigref_h__ */