xref: /AOO41X/main/xmlsecurity/source/framework/signatureengine.hxx (revision ec61c6ed669d81c7df08233ccc38d0040f129ece)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SIGNATUREENGINE_HXX
25 #define _SIGNATUREENGINE_HXX
26 
27 #include <com/sun/star/xml/crypto/sax/XReferenceResolvedListener.hpp>
28 #include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
29 #ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XSIGNATURECOLLECTOR_HPP_
30 #include <com/sun/star/xml/crypto/sax/XReferenceCollector.hpp>
31 #endif
32 #include <com/sun/star/xml/crypto/sax/XKeyCollector.hpp>
33 #include <com/sun/star/xml/crypto/sax/XMissionTaker.hpp>
34 #include <com/sun/star/xml/crypto/sax/XSAXEventKeeper.hpp>
35 #include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
36 #include <com/sun/star/xml/crypto/XXMLSignature.hpp>
37 #include <com/sun/star/xml/crypto/XUriBinding.hpp>
38 #include <com/sun/star/io/XInputStream.hpp>
39 
40 #include <cppuhelper/implbase2.hxx>
41 
42 #include "securityengine.hxx"
43 
44 #ifndef INCLUDED_VECTOR
45 #include <vector>
46 #define INCLUDED_VECTOR
47 #endif
48 
49 class SignatureEngine : public cppu::ImplInheritanceHelper2
50 <
51     SecurityEngine,
52     com::sun::star::xml::crypto::sax::XReferenceCollector,
53     com::sun::star::xml::crypto::XUriBinding
54 >
55 /****** signatureengine.hxx/CLASS SignatureEngine *****************************
56  *
57  *   NAME
58  *  SignatureEngine -- Base class of SignatureCreator and SignatureVerifier
59  *
60  *   FUNCTION
61  *  Maintains common members and methods related with signature operation.
62  *
63  *   HISTORY
64  *  05.01.2004 -    Interface supported: XReferenceCollector
65  *
66  *   AUTHOR
67  *  Michael Mi
68  *  Email: michael.mi@sun.com
69  ******************************************************************************/
70 {
71 protected:
72 
73     /*
74      * the Signature bridge component, which performs signature generation
75      * and verification based on xmlsec library.
76      */
77     com::sun::star::uno::Reference<
78         com::sun::star::xml::crypto::XXMLSignature > m_xXMLSignature;
79 
80     /*
81      * a collection of ElementCollector's ids. Each ElementCollector
82      * represents one element signed by this signature.
83      */
84     std::vector< sal_Int32 > m_vReferenceIds;
85 
86     /*
87      * remembers how many references this signature has.
88      */
89     sal_Int32 m_nTotalReferenceNumber;
90 
91     /*
92      * a collection of Uri binding.
93      *
94      * the m_vUris is used to hold the Uri strings, and the m_vXInputStreams is used
95      * to hold corresponding binded XInputStream interface.
96      */
97     std::vector< rtl::OUString > m_vUris;
98     std::vector< com::sun::star::uno::Reference<
99         com::sun::star::io::XInputStream > > m_vXInputStreams;
100 
101 protected:
102     SignatureEngine( );
~SignatureEngine()103     virtual ~SignatureEngine() {};
104 
105     virtual void tryToPerform( )
106         throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
107     virtual void clearUp( ) const;
108     virtual bool checkReady() const;
109 
110     /*
111      * starts the main function. This method will be implemented by any sub-class.
112      * For a SignatureCreator, it performs signing operation;
113      * for a SignatureVerifier, verification operation is performed.
114      */
startEngine(const com::sun::star::uno::Reference<com::sun::star::xml::crypto::XXMLSignatureTemplate> &)115     virtual void startEngine( const com::sun::star::uno::Reference<
116                               com::sun::star::xml::crypto::XXMLSignatureTemplate >&)
117         throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException)
118         {};
119 
120 public:
121     /* XReferenceCollector */
122     virtual void SAL_CALL setReferenceCount( sal_Int32 count )
123         throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
124 
125     virtual void SAL_CALL setReferenceId( sal_Int32 id )
126         throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
127 
128     /* XUriBinding */
129     virtual void SAL_CALL setUriBinding(
130         const rtl::OUString& uri,
131         const com::sun::star::uno::Reference<
132             com::sun::star::io::XInputStream >& aInputStream )
133         throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
134     virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream >
135         SAL_CALL getUriBinding( const rtl::OUString& uri )
136         throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
137 };
138 
139 #endif
140 
141