1a197e8264aeb4dd5871c93818b1b3e0f2812564
[shibboleth/cpp-opensaml.git] / saml / signature / ContentReference.h
1 /*
2  *  Copyright 2001-2007 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 #include <xmltooling/XMLObject.h>
28 #include <xmltooling/signature/ContentReference.h>
29
30 #include <set>
31 #include <string>
32
33 namespace opensaml {
34
35     class SAML_API SignableObject;
36
37 #if defined (_MSC_VER)
38     #pragma warning( push )
39     #pragma warning( disable : 4251 )
40 #endif
41
42     /**
43      * SAML-specific signature reference profile.
44      */
45     class SAML_API ContentReference : public virtual xmlsignature::ContentReference
46     {
47     public:
48         /**
49          * Constructor.
50          * 
51          * @param signableObject    reference to object being signed
52          */
53         ContentReference(const SignableObject& signableObject)
54             : m_signableObject(signableObject), m_digest(NULL), m_c14n(NULL) {
55         }
56     
57         virtual ~ContentReference() {}
58
59         /**
60          * Given a "blank" native signature, creates signature reference
61          * appropriate for the SAML object being signed.
62          * 
63          * @param sig   native signature interface
64          */
65         virtual void createReferences(DSIGSignature* sig);
66         
67         /**
68          * Adds a namespace prefix for "inclusive" processing by an
69          * Exclusive C14N Transform applied to the object.
70          * An empty string will be transformed into "#default".
71          * 
72          * @param prefix    the prefix to add 
73          */
74         void addInclusivePrefix(const XMLCh* prefix);
75         
76         /**
77          * Sets the digest algorithm for the signature reference,
78          * using a constant.
79          * 
80          * @param digest    the digest algorithm
81          */
82         void setDigestAlgorithm(const XMLCh* digest) {
83             m_digest = digest;
84         }
85
86         /**
87          * Sets the canonicalization method to include in the reference,
88          * using a constant.
89          * 
90          * @param c14n  the canonicalization method
91          */
92         void setCanonicalizationMethod(const XMLCh* c14n) {
93             m_c14n = c14n;
94         }
95         
96     private:
97         void addPrefixes(const std::set<xmltooling::Namespace>& namespaces);
98         void addPrefixes(const xmltooling::XMLObject& xmlObject);
99
100         const SignableObject& m_signableObject;
101 #ifdef HAVE_GOOD_STL
102         std::set<xmltooling::xstring> m_prefixes;
103 #else
104         std::set<std::string> m_prefixes;
105 #endif
106         const XMLCh* m_digest;
107         const XMLCh* m_c14n;
108     };
109
110 #if defined (_MSC_VER)
111     #pragma warning( pop )
112 #endif
113 };
114
115 #endif /* __saml_sigref_h__ */