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 _CIPHERCONTEXT_HXX
25 #define _CIPHERCONTEXT_HXX
26 
27 #include <com/sun/star/xml/crypto/XCipherContext.hpp>
28 
29 #include <cppuhelper/implbase1.hxx>
30 #include <osl/mutex.hxx>
31 #include <pk11pub.h>
32 
33 class OCipherContext : public cppu::WeakImplHelper1< ::com::sun::star::xml::crypto::XCipherContext >
34 {
35 private:
36     ::osl::Mutex m_aMutex;
37 
38     PK11SlotInfo* m_pSlot;
39     PK11SymKey* m_pSymKey;
40     SECItem* m_pSecParam;
41     PK11Context* m_pContext;
42 
43     sal_Int32 m_nBlockSize;
44     ::com::sun::star::uno::Sequence< sal_Int8 > m_aLastBlock;
45 
46     bool m_bEncryption;
47     bool m_bPadding;
48     bool m_bW3CPadding;
49     sal_Int64 m_nConverted;
50 
51     bool m_bDisposed;
52     bool m_bBroken;
53 
54     void Dispose();
55 
OCipherContext()56     OCipherContext()
57     : m_pSlot( NULL )
58     , m_pSymKey( NULL )
59     , m_pSecParam( NULL )
60     , m_pContext( NULL )
61     , m_nBlockSize( 0 )
62     , m_bEncryption( false )
63     , m_bPadding( false )
64     , m_bW3CPadding( false )
65     , m_nConverted( 0 )
66     , m_bDisposed( false )
67     , m_bBroken( false )
68     {}
69 
70 public:
71 
~OCipherContext()72     virtual ~OCipherContext()
73     {
74         Dispose();
75     }
76 
77     static ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XCipherContext > Create( CK_MECHANISM_TYPE nNSSCipherID, const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aKey, const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aInitializationVector, bool bEncryption, bool bW3CPadding );
78 
79     // XCipherContext
80     virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL convertWithCipherContext( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException);
81     virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL finalizeCipherContextAndDispose(  ) throw (::com::sun::star::lang::DisposedException, ::com::sun::star::uno::RuntimeException);
82 };
83 
84 #endif
85 
86