xref: /aoo41x/main/extensions/workben/testpgp.cxx (revision 2a97ec55)
1*2a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2a97ec55SAndrew Rist  * distributed with this work for additional information
6*2a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
9*2a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2a97ec55SAndrew Rist  *
11*2a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2a97ec55SAndrew Rist  *
13*2a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2a97ec55SAndrew Rist  * software distributed under the License is distributed on an
15*2a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2a97ec55SAndrew Rist  * specific language governing permissions and limitations
18*2a97ec55SAndrew Rist  * under the License.
19*2a97ec55SAndrew Rist  *
20*2a97ec55SAndrew Rist  *************************************************************/
21*2a97ec55SAndrew Rist 
22*2a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir #include <sal/types.h>
27cdf0e10cSrcweir #include <rtl/memory.h>
28cdf0e10cSrcweir #ifndef _RTL_WSTRING_
29cdf0e10cSrcweir #include <rtl/wstring>
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir #include <vos/macros.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #ifndef _USR_SMARTSERVICES_HXX_
34cdf0e10cSrcweir #include <usr/smartservices.hxx>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
38cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
39cdf0e10cSrcweir #include <com/sun/star/pgp/RecipientsEvent.hpp>
40cdf0e10cSrcweir #include <com/sun/star/pgp/SignatureEvent.hpp>
41cdf0e10cSrcweir #include <com/sun/star/pgp/XPGPDecoder.hpp>
42cdf0e10cSrcweir #include <com/sun/star/pgp/XPGPDecoderListener.hpp>
43cdf0e10cSrcweir #include <com/sun/star/pgp/XPGPEncoder.hpp>
44cdf0e10cSrcweir #include <com/sun/star/pgp/XPGPPreferences.hpp>
45cdf0e10cSrcweir #include <com/sun/star/uno/XInterface.hpp>
46cdf0e10cSrcweir #include <com/sun/star/uno/Any.h>
47cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
48cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
49cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include <stdio.h>
52cdf0e10cSrcweir #include <stdlib.h>
53cdf0e10cSrcweir #include <string.h>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #include <fcntl.h>
56cdf0e10cSrcweir #include <io.h>
57cdf0e10cSrcweir 
58cdf0e10cSrcweir using namespace com::sun::star::lang;
59cdf0e10cSrcweir using namespace com::sun::star::io;
60cdf0e10cSrcweir using namespace com::sun::star::pgp;
61cdf0e10cSrcweir using namespace com::sun::star::uno;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir /*========================================================================
64cdf0e10cSrcweir  *
65cdf0e10cSrcweir  * DataSource_Impl interface.
66cdf0e10cSrcweir  *
67cdf0e10cSrcweir  *======================================================================*/
68cdf0e10cSrcweir class DataSource_Impl :
69cdf0e10cSrcweir 	public OWeakObject,
70cdf0e10cSrcweir 	public XInputStream
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	Sequence<sal_Int8> m_buffer;
73cdf0e10cSrcweir 	sal_Int32          m_position;
74cdf0e10cSrcweir 	int                m_fd;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir public:
77cdf0e10cSrcweir 	DataSource_Impl (int fd = 0);
78cdf0e10cSrcweir 	virtual ~DataSource_Impl (void);
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	void setBuffer (const Sequence<sal_Int8> &rBuffer);
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	/** XInterface.
83cdf0e10cSrcweir 	 */
84cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL queryInterface (
85cdf0e10cSrcweir 		const Uik &rUik, Any &rIfc) throw(RuntimeException);
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	virtual void SAL_CALL acquire (void) throw(RuntimeException);
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	virtual void SAL_CALL release (void) throw(RuntimeException);
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	/** XInputStream.
92cdf0e10cSrcweir 	 */
93cdf0e10cSrcweir 	virtual sal_Int32 SAL_CALL readBytes (
94cdf0e10cSrcweir 		Sequence<sal_Int8> &rData, sal_Int32 nBytesToRead)
95cdf0e10cSrcweir 		throw (NotConnectedException,
96cdf0e10cSrcweir 			   BufferSizeExceededException,
97cdf0e10cSrcweir 			   IOException);
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	virtual sal_Int32 SAL_CALL readSomeBytes (
100cdf0e10cSrcweir 		Sequence<sal_Int8> &rData, sal_Int32 nMaxBytesToRead)
101cdf0e10cSrcweir 		throw (NotConnectedException,
102cdf0e10cSrcweir 			   BufferSizeExceededException,
103cdf0e10cSrcweir 			   IOException);
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	virtual void SAL_CALL skipBytes (sal_Int32 nBytesToSkip)
106cdf0e10cSrcweir 		throw (NotConnectedException,
107cdf0e10cSrcweir 			   BufferSizeExceededException,
108cdf0e10cSrcweir 			   IOException);
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	virtual sal_Int32 SAL_CALL available (void)
111cdf0e10cSrcweir 		throw (NotConnectedException, IOException);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	virtual void SAL_CALL closeInput (void)
114cdf0e10cSrcweir 		throw (NotConnectedException, IOException);
115cdf0e10cSrcweir };
116cdf0e10cSrcweir 
117cdf0e10cSrcweir /*========================================================================
118cdf0e10cSrcweir  *
119cdf0e10cSrcweir  * DataSink_Impl interface.
120cdf0e10cSrcweir  *
121cdf0e10cSrcweir  *======================================================================*/
122cdf0e10cSrcweir class DataSink_Impl :
123cdf0e10cSrcweir 	public OWeakObject,
124cdf0e10cSrcweir 	public XOutputStream
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	Sequence<sal_Int8> m_buffer;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir public:
129cdf0e10cSrcweir 	DataSink_Impl (void);
130cdf0e10cSrcweir 	virtual ~DataSink_Impl (void);
131cdf0e10cSrcweir 
getBuffer(void) const132cdf0e10cSrcweir 	const Sequence<sal_Int8>& getBuffer (void) const { return m_buffer; }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	/** XInterface.
135cdf0e10cSrcweir 	 */
136cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL queryInterface (
137cdf0e10cSrcweir 		const Uik &rUik, Any &rIfc) throw(RuntimeException);
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	virtual void SAL_CALL acquire (void) throw(RuntimeException);
140cdf0e10cSrcweir 	virtual void SAL_CALL release (void) throw(RuntimeException);
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	/** XOutputStream.
143cdf0e10cSrcweir 	 */
144cdf0e10cSrcweir 	virtual void SAL_CALL writeBytes (
145cdf0e10cSrcweir 		const Sequence<sal_Int8> &rBuffer)
146cdf0e10cSrcweir 		throw (NotConnectedException,
147cdf0e10cSrcweir 			   BufferSizeExceededException,
148cdf0e10cSrcweir 			   IOException);
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 	virtual void SAL_CALL flush (void)
151cdf0e10cSrcweir 		throw (NotConnectedException,
152cdf0e10cSrcweir 			   BufferSizeExceededException,
153cdf0e10cSrcweir 			   IOException);
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	virtual void SAL_CALL closeOutput (void)
156cdf0e10cSrcweir 		throw (NotConnectedException,
157cdf0e10cSrcweir 			   BufferSizeExceededException,
158cdf0e10cSrcweir 			   IOException);
159cdf0e10cSrcweir };
160cdf0e10cSrcweir 
161cdf0e10cSrcweir /*========================================================================
162cdf0e10cSrcweir  *
163cdf0e10cSrcweir  * DecoderListener_Impl interface.
164cdf0e10cSrcweir  *
165cdf0e10cSrcweir  *======================================================================*/
166cdf0e10cSrcweir class DecoderListener_Impl :
167cdf0e10cSrcweir 	public OWeakObject,
168cdf0e10cSrcweir 	public XPGPDecoderListener
169cdf0e10cSrcweir {
170cdf0e10cSrcweir public:
171cdf0e10cSrcweir 	DecoderListener_Impl (void);
172cdf0e10cSrcweir 	virtual ~DecoderListener_Impl (void);
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 	/** XInterface.
175cdf0e10cSrcweir 	 */
176cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL queryInterface (
177cdf0e10cSrcweir 		const Uik &rUik, Any &rIfc) throw(RuntimeException);
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 	virtual void SAL_CALL acquire (void) throw(RuntimeException);
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 	virtual void SAL_CALL release (void) throw(RuntimeException);
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	/** XEventListener.
184cdf0e10cSrcweir 	 */
185cdf0e10cSrcweir 	virtual void SAL_CALL disposing (const EventObject &rSource);
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 	/** XPGPDecoderListener.
188cdf0e10cSrcweir 	 */
189cdf0e10cSrcweir 	virtual void SAL_CALL decrypted (const RecipientsEvent &rEvent);
190cdf0e10cSrcweir 	virtual void SAL_CALL verified  (const SignatureEvent &rEvent);
191cdf0e10cSrcweir };
192cdf0e10cSrcweir 
193cdf0e10cSrcweir /*========================================================================
194cdf0e10cSrcweir  *
195cdf0e10cSrcweir  * DataSource_Impl implementation.
196cdf0e10cSrcweir  *
197cdf0e10cSrcweir  *======================================================================*/
198cdf0e10cSrcweir /*
199cdf0e10cSrcweir  * DataSource_Impl.
200cdf0e10cSrcweir  */
DataSource_Impl(int fd)201cdf0e10cSrcweir DataSource_Impl::DataSource_Impl (int fd)
202cdf0e10cSrcweir 	: m_fd (fd), m_position (0)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir /*
207cdf0e10cSrcweir  * ~DataSource_Impl.
208cdf0e10cSrcweir  */
~DataSource_Impl(void)209cdf0e10cSrcweir DataSource_Impl::~DataSource_Impl (void)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir }
212cdf0e10cSrcweir 
213cdf0e10cSrcweir /*
214cdf0e10cSrcweir  * DataSource_Impl: setBuffer.
215cdf0e10cSrcweir  */
setBuffer(const Sequence<sal_Int8> & rBuffer)216cdf0e10cSrcweir void DataSource_Impl::setBuffer (const Sequence<sal_Int8> &rBuffer)
217cdf0e10cSrcweir {
218cdf0e10cSrcweir 	m_buffer = rBuffer;
219cdf0e10cSrcweir 	if (!m_buffer.getLength())
220cdf0e10cSrcweir 	{
221cdf0e10cSrcweir 		// Fill buffer from file descriptor.
222cdf0e10cSrcweir 		char buffer[1024];
223cdf0e10cSrcweir 		rtl_zeroMemory (buffer, sizeof(buffer));
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 		int k = read (m_fd, buffer, sizeof(buffer));
226cdf0e10cSrcweir 		while (k > 0)
227cdf0e10cSrcweir 		{
228cdf0e10cSrcweir 			sal_Int32 n = m_buffer.getLength();
229cdf0e10cSrcweir 			m_buffer.realloc (n + k);
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 			rtl_copyMemory (m_buffer.getArray() + n, buffer, k);
232cdf0e10cSrcweir 			n += k;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 			rtl_zeroMemory (buffer, k);
235cdf0e10cSrcweir 			k = read (m_fd, buffer, sizeof(buffer));
236cdf0e10cSrcweir 		}
237cdf0e10cSrcweir 	}
238cdf0e10cSrcweir 	m_position = 0;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir /*
242cdf0e10cSrcweir  * XInterface: queryInterface.
243cdf0e10cSrcweir  */
queryInterface(const Uik & rUik,Any & rIfc)244cdf0e10cSrcweir sal_Bool SAL_CALL DataSource_Impl::queryInterface (
245cdf0e10cSrcweir 	const Uik &rUik, Any &rIfc) throw(RuntimeException)
246cdf0e10cSrcweir {
247cdf0e10cSrcweir 	if (com::sun::star::uno::queryInterface (
248cdf0e10cSrcweir 		rUik, rIfc,
249cdf0e10cSrcweir 		SAL_STATIC_CAST (XInputStream*, this)))
250cdf0e10cSrcweir 		return sal_True;
251cdf0e10cSrcweir 	else
252cdf0e10cSrcweir 		return OWeakObject::queryInterface (rUik, rIfc);
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir /*
256cdf0e10cSrcweir  * XInterface: acquire.
257cdf0e10cSrcweir  */
acquire(void)258cdf0e10cSrcweir void SAL_CALL DataSource_Impl::acquire (void) throw(RuntimeException)
259cdf0e10cSrcweir {
260cdf0e10cSrcweir 	OWeakObject::acquire();
261cdf0e10cSrcweir }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir /*
264cdf0e10cSrcweir  * XInterface: release.
265cdf0e10cSrcweir  */
release(void)266cdf0e10cSrcweir void SAL_CALL DataSource_Impl::release (void) throw(RuntimeException)
267cdf0e10cSrcweir {
268cdf0e10cSrcweir 	OWeakObject::release();
269cdf0e10cSrcweir }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir /*
272cdf0e10cSrcweir  * XInputStream: readBytes.
273cdf0e10cSrcweir  */
readBytes(Sequence<sal_Int8> & rData,sal_Int32 nBytesToRead)274cdf0e10cSrcweir sal_Int32 SAL_CALL DataSource_Impl::readBytes (
275cdf0e10cSrcweir 	Sequence<sal_Int8> &rData, sal_Int32 nBytesToRead)
276cdf0e10cSrcweir 	throw (NotConnectedException, BufferSizeExceededException, IOException)
277cdf0e10cSrcweir {
278cdf0e10cSrcweir 	if (nBytesToRead < 0)
279cdf0e10cSrcweir 		throw IOException();
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 	sal_Int32 k = m_buffer.getLength() - m_position;
282cdf0e10cSrcweir 	k = VOS_BOUND(k, 0, nBytesToRead);
283cdf0e10cSrcweir 	if (k > 0)
284cdf0e10cSrcweir 	{
285cdf0e10cSrcweir 		rData.realloc(k);
286cdf0e10cSrcweir 		rtl_copyMemory (
287cdf0e10cSrcweir 			rData.getArray(), m_buffer.getConstArray() + m_position, k);
288cdf0e10cSrcweir 		m_position += k;
289cdf0e10cSrcweir 	}
290cdf0e10cSrcweir 	return k;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir /*
294cdf0e10cSrcweir  * XInputStream: readSomeBytes.
295cdf0e10cSrcweir  */
readSomeBytes(Sequence<sal_Int8> & rData,sal_Int32 nMaxBytesToRead)296cdf0e10cSrcweir sal_Int32 SAL_CALL DataSource_Impl::readSomeBytes (
297cdf0e10cSrcweir 	Sequence<sal_Int8> &rData, sal_Int32 nMaxBytesToRead)
298cdf0e10cSrcweir 	throw (NotConnectedException, BufferSizeExceededException, IOException)
299cdf0e10cSrcweir {
300cdf0e10cSrcweir 	return readBytes (rData, nMaxBytesToRead);
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir /*
304cdf0e10cSrcweir  * XInputStream: skipBytes.
305cdf0e10cSrcweir  */
skipBytes(sal_Int32 nBytesToSkip)306cdf0e10cSrcweir void SAL_CALL DataSource_Impl::skipBytes (sal_Int32 nBytesToSkip)
307cdf0e10cSrcweir 	throw (NotConnectedException, BufferSizeExceededException, IOException)
308cdf0e10cSrcweir {
309cdf0e10cSrcweir 	if (nBytesToSkip < 0)
310cdf0e10cSrcweir 		throw IOException();
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 	m_position += nBytesToSkip;
313cdf0e10cSrcweir }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir /*
316cdf0e10cSrcweir  * XInputStream: available.
317cdf0e10cSrcweir  */
available(void)318cdf0e10cSrcweir sal_Int32 SAL_CALL DataSource_Impl::available (void)
319cdf0e10cSrcweir 	throw (NotConnectedException, IOException)
320cdf0e10cSrcweir {
321cdf0e10cSrcweir 	sal_Int32 k = m_buffer.getLength() - m_position;
322cdf0e10cSrcweir 	return ((k > 0) ? k : 0);
323cdf0e10cSrcweir }
324cdf0e10cSrcweir 
325cdf0e10cSrcweir /*
326cdf0e10cSrcweir  * XInputStream: closeInput.
327cdf0e10cSrcweir  */
closeInput(void)328cdf0e10cSrcweir void SAL_CALL DataSource_Impl::closeInput (void)
329cdf0e10cSrcweir 	throw (NotConnectedException, IOException)
330cdf0e10cSrcweir {
331cdf0e10cSrcweir }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir /*========================================================================
334cdf0e10cSrcweir  *
335cdf0e10cSrcweir  * DataSink_Impl implementation.
336cdf0e10cSrcweir  *
337cdf0e10cSrcweir  *======================================================================*/
338cdf0e10cSrcweir /*
339cdf0e10cSrcweir  * DataSink_Impl.
340cdf0e10cSrcweir  */
DataSink_Impl(void)341cdf0e10cSrcweir DataSink_Impl::DataSink_Impl (void)
342cdf0e10cSrcweir {
343cdf0e10cSrcweir }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir /*
346cdf0e10cSrcweir  * ~DataSink_Impl.
347cdf0e10cSrcweir  */
~DataSink_Impl(void)348cdf0e10cSrcweir DataSink_Impl::~DataSink_Impl (void)
349cdf0e10cSrcweir {
350cdf0e10cSrcweir }
351cdf0e10cSrcweir 
352cdf0e10cSrcweir /*
353cdf0e10cSrcweir  * XInterface: queryInterface.
354cdf0e10cSrcweir  */
queryInterface(const Uik & rUik,Any & rIfc)355cdf0e10cSrcweir sal_Bool SAL_CALL DataSink_Impl::queryInterface (
356cdf0e10cSrcweir 	const Uik &rUik, Any &rIfc) throw(RuntimeException)
357cdf0e10cSrcweir {
358cdf0e10cSrcweir 	if (com::sun::star::uno::queryInterface (
359cdf0e10cSrcweir 		rUik, rIfc,
360cdf0e10cSrcweir 		SAL_STATIC_CAST (XOutputStream*, this)))
361cdf0e10cSrcweir 		return sal_True;
362cdf0e10cSrcweir 	else
363cdf0e10cSrcweir 		return OWeakObject::queryInterface (rUik, rIfc);
364cdf0e10cSrcweir }
365cdf0e10cSrcweir 
366cdf0e10cSrcweir /*
367cdf0e10cSrcweir  * XInterface: acquire.
368cdf0e10cSrcweir  */
acquire(void)369cdf0e10cSrcweir void SAL_CALL DataSink_Impl::acquire (void) throw(RuntimeException)
370cdf0e10cSrcweir {
371cdf0e10cSrcweir 	OWeakObject::acquire();
372cdf0e10cSrcweir }
373cdf0e10cSrcweir 
374cdf0e10cSrcweir /*
375cdf0e10cSrcweir  * XInterface: release.
376cdf0e10cSrcweir  */
release(void)377cdf0e10cSrcweir void SAL_CALL DataSink_Impl::release (void) throw(RuntimeException)
378cdf0e10cSrcweir {
379cdf0e10cSrcweir 	OWeakObject::release();
380cdf0e10cSrcweir }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir /*
383cdf0e10cSrcweir  * XOutputStream: writeBytes.
384cdf0e10cSrcweir  */
writeBytes(const Sequence<sal_Int8> & rBuffer)385cdf0e10cSrcweir void SAL_CALL DataSink_Impl::writeBytes (const Sequence<sal_Int8> &rBuffer)
386cdf0e10cSrcweir 	throw (NotConnectedException, BufferSizeExceededException, IOException)
387cdf0e10cSrcweir {
388cdf0e10cSrcweir 	if (rBuffer.getLength())
389cdf0e10cSrcweir 	{
390cdf0e10cSrcweir 		sal_Int32 n = m_buffer.getLength();
391cdf0e10cSrcweir 		m_buffer.realloc (n + rBuffer.getLength());
392cdf0e10cSrcweir 
393cdf0e10cSrcweir 		rtl_copyMemory (
394cdf0e10cSrcweir 			m_buffer.getArray() + n,
395cdf0e10cSrcweir 			rBuffer.getConstArray(),
396cdf0e10cSrcweir 			rBuffer.getLength());
397cdf0e10cSrcweir 	}
398cdf0e10cSrcweir }
399cdf0e10cSrcweir 
400cdf0e10cSrcweir /*
401cdf0e10cSrcweir  * XOutputStream: flush.
402cdf0e10cSrcweir  */
flush(void)403cdf0e10cSrcweir void SAL_CALL DataSink_Impl::flush (void)
404cdf0e10cSrcweir 	throw (NotConnectedException, BufferSizeExceededException, IOException)
405cdf0e10cSrcweir {
406cdf0e10cSrcweir 	if (m_buffer.getLength())
407cdf0e10cSrcweir 	{
408cdf0e10cSrcweir 		// Write data to stdout.
409cdf0e10cSrcweir 		const sal_Int8 *pData = m_buffer.getConstArray();
410cdf0e10cSrcweir 		sal_Int32       nData = m_buffer.getLength();
411cdf0e10cSrcweir 
412cdf0e10cSrcweir 		int prev = ::setmode (1, O_BINARY);
413cdf0e10cSrcweir 		if (!(prev < 0))
414cdf0e10cSrcweir 		{
415cdf0e10cSrcweir 			int k = ::write (1, pData, nData);
416cdf0e10cSrcweir 			if (k > 0)
417cdf0e10cSrcweir 				::write (1, "\n", 1);
418cdf0e10cSrcweir 			::setmode (1, prev);
419cdf0e10cSrcweir 		}
420cdf0e10cSrcweir 	}
421cdf0e10cSrcweir }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir /*
424cdf0e10cSrcweir  * XOutputStream: closeOutput.
425cdf0e10cSrcweir  */
closeOutput(void)426cdf0e10cSrcweir void SAL_CALL DataSink_Impl::closeOutput (void)
427cdf0e10cSrcweir 	throw (NotConnectedException, BufferSizeExceededException, IOException)
428cdf0e10cSrcweir {
429cdf0e10cSrcweir 	flush();
430cdf0e10cSrcweir }
431cdf0e10cSrcweir 
432cdf0e10cSrcweir /*========================================================================
433cdf0e10cSrcweir  *
434cdf0e10cSrcweir  * DecoderListener_Impl implementation.
435cdf0e10cSrcweir  *
436cdf0e10cSrcweir  *======================================================================*/
437cdf0e10cSrcweir /*
438cdf0e10cSrcweir  * DecoderListener_Impl.
439cdf0e10cSrcweir  */
DecoderListener_Impl(void)440cdf0e10cSrcweir DecoderListener_Impl::DecoderListener_Impl (void)
441cdf0e10cSrcweir {
442cdf0e10cSrcweir }
443cdf0e10cSrcweir 
444cdf0e10cSrcweir /*
445cdf0e10cSrcweir  * ~DecoderListener_Impl.
446cdf0e10cSrcweir  */
~DecoderListener_Impl(void)447cdf0e10cSrcweir DecoderListener_Impl::~DecoderListener_Impl (void)
448cdf0e10cSrcweir {
449cdf0e10cSrcweir }
450cdf0e10cSrcweir 
451cdf0e10cSrcweir /*
452cdf0e10cSrcweir  * XInterface: queryInterface.
453cdf0e10cSrcweir  */
queryInterface(const Uik & rUik,Any & rIfc)454cdf0e10cSrcweir sal_Bool SAL_CALL DecoderListener_Impl::queryInterface (
455cdf0e10cSrcweir 	const Uik &rUik, Any &rIfc) throw(RuntimeException)
456cdf0e10cSrcweir {
457cdf0e10cSrcweir 	if (com::sun::star::uno::queryInterface (
458cdf0e10cSrcweir 		rUik, rIfc,
459cdf0e10cSrcweir 		SAL_STATIC_CAST (XEventListener*, this),
460cdf0e10cSrcweir 		SAL_STATIC_CAST (XPGPDecoderListener*, this)))
461cdf0e10cSrcweir 		return sal_True;
462cdf0e10cSrcweir 	else
463cdf0e10cSrcweir 		return OWeakObject::queryInterface (rUik, rIfc);
464cdf0e10cSrcweir }
465cdf0e10cSrcweir 
466cdf0e10cSrcweir /*
467cdf0e10cSrcweir  * XInterface: acquire.
468cdf0e10cSrcweir  */
acquire(void)469cdf0e10cSrcweir void SAL_CALL DecoderListener_Impl::acquire (void) throw(RuntimeException)
470cdf0e10cSrcweir {
471cdf0e10cSrcweir 	OWeakObject::acquire();
472cdf0e10cSrcweir }
473cdf0e10cSrcweir 
474cdf0e10cSrcweir /*
475cdf0e10cSrcweir  * XInterface: release.
476cdf0e10cSrcweir  */
release(void)477cdf0e10cSrcweir void SAL_CALL DecoderListener_Impl::release (void) throw(RuntimeException)
478cdf0e10cSrcweir {
479cdf0e10cSrcweir 	OWeakObject::release();
480cdf0e10cSrcweir }
481cdf0e10cSrcweir 
482cdf0e10cSrcweir /*
483cdf0e10cSrcweir  * XEventListener: disposing.
484cdf0e10cSrcweir  */
disposing(const EventObject & rSource)485cdf0e10cSrcweir void SAL_CALL DecoderListener_Impl::disposing (const EventObject &rSource)
486cdf0e10cSrcweir {
487cdf0e10cSrcweir }
488cdf0e10cSrcweir 
489cdf0e10cSrcweir /*
490cdf0e10cSrcweir  * XPGPDecoderListener: decrypted.
491cdf0e10cSrcweir  */
decrypted(const RecipientsEvent & rEvent)492cdf0e10cSrcweir void SAL_CALL DecoderListener_Impl::decrypted (const RecipientsEvent &rEvent)
493cdf0e10cSrcweir {
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir /*
497cdf0e10cSrcweir  * XPGPDecoderListener: verified.
498cdf0e10cSrcweir  */
verified(const SignatureEvent & rEvent)499cdf0e10cSrcweir void SAL_CALL DecoderListener_Impl::verified (const SignatureEvent &rEvent)
500cdf0e10cSrcweir {
501cdf0e10cSrcweir }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir /*========================================================================
504cdf0e10cSrcweir  *
505cdf0e10cSrcweir  * Main.
506cdf0e10cSrcweir  *
507cdf0e10cSrcweir  *======================================================================*/
S2U(const sal_Char * ascii)508cdf0e10cSrcweir inline rtl::OWString S2U (const sal_Char *ascii)
509cdf0e10cSrcweir {
510cdf0e10cSrcweir 	return rtl::OWString::createFromAscii (ascii);
511cdf0e10cSrcweir }
512cdf0e10cSrcweir 
513cdf0e10cSrcweir #if 0  /* OLD */
514cdf0e10cSrcweir 
515cdf0e10cSrcweir /*
516cdf0e10cSrcweir  * queryModuleActivator.
517cdf0e10cSrcweir  */
518cdf0e10cSrcweir BOOL queryModuleActivator (
519cdf0e10cSrcweir 	const XServiceManagerRef &rxManager,
520cdf0e10cSrcweir 	XServiceActivatorRef     &rxActivator)
521cdf0e10cSrcweir {
522cdf0e10cSrcweir 	XServiceProviderRef xProv;
523cdf0e10cSrcweir 	XInterfaceRef       xProvInst;
524cdf0e10cSrcweir 
525cdf0e10cSrcweir 	xProv = rxManager->queryServiceProvider (
526cdf0e10cSrcweir 		L"stardiv.uno.ServiceActivator.module");
527cdf0e10cSrcweir 	if (!xProv.is())
528cdf0e10cSrcweir 	{
529cdf0e10cSrcweir 		printf ("Error: no ServiceActivator service.\n");
530cdf0e10cSrcweir 		return FALSE;
531cdf0e10cSrcweir 	}
532cdf0e10cSrcweir 
533cdf0e10cSrcweir 	xProvInst = xProv->createInstance();
534cdf0e10cSrcweir 	if (!xProvInst.is())
535cdf0e10cSrcweir 	{
536cdf0e10cSrcweir 		printf ("Error: no ServiceActivator instance.\n");
537cdf0e10cSrcweir 		return FALSE;
538cdf0e10cSrcweir 	}
539cdf0e10cSrcweir 
540cdf0e10cSrcweir 	return xProvInst->queryInterface (
541cdf0e10cSrcweir 		XServiceActivator::getSmartUik(), rxActivator);
542cdf0e10cSrcweir }
543cdf0e10cSrcweir 
544cdf0e10cSrcweir /*
545cdf0e10cSrcweir  * install.
546cdf0e10cSrcweir  */
547cdf0e10cSrcweir BOOL install (
548cdf0e10cSrcweir 	const XServiceActivatorRef &rxActivator,
549cdf0e10cSrcweir 	const char                 *prefix)
550cdf0e10cSrcweir {
551cdf0e10cSrcweir 	String aModule ("module://");
552cdf0e10cSrcweir 	char   pBuffer[1024];
553cdf0e10cSrcweir 
554cdf0e10cSrcweir 	vos::ORealDynamicLoader::computeModuleName (
555cdf0e10cSrcweir 		prefix, pBuffer, sizeof(pBuffer));
556cdf0e10cSrcweir 	aModule += pBuffer;
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 	return rxActivator->install (
559cdf0e10cSrcweir 		StringToUString (aModule, CHARSET_SYSTEM));
560cdf0e10cSrcweir }
561cdf0e10cSrcweir 
562cdf0e10cSrcweir /*
563cdf0e10cSrcweir  * uninstall.
564cdf0e10cSrcweir  */
565cdf0e10cSrcweir BOOL uninstall (
566cdf0e10cSrcweir 	const XServiceActivatorRef &rxActivator,
567cdf0e10cSrcweir 	const char                 *prefix)
568cdf0e10cSrcweir {
569cdf0e10cSrcweir 	String aModule ("module://");
570cdf0e10cSrcweir 	char   pBuffer[1024];
571cdf0e10cSrcweir 
572cdf0e10cSrcweir 	vos::ORealDynamicLoader::computeModuleName (
573cdf0e10cSrcweir 		prefix, pBuffer, sizeof(pBuffer));
574cdf0e10cSrcweir 	aModule += pBuffer;
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 	return rxActivator->deinstall (
577cdf0e10cSrcweir 		StringToUString (aModule, CHARSET_SYSTEM));
578cdf0e10cSrcweir }
579cdf0e10cSrcweir 
580cdf0e10cSrcweir #endif /* OLD */
581cdf0e10cSrcweir 
582cdf0e10cSrcweir /*
583cdf0e10cSrcweir  * main.
584cdf0e10cSrcweir  */
main(int argc,char ** argv)585cdf0e10cSrcweir int SAL_CALL main (int argc, char **argv)
586cdf0e10cSrcweir {
587cdf0e10cSrcweir 	enum Option
588cdf0e10cSrcweir 	{
589cdf0e10cSrcweir 		OPTION_INSTALL   = 0x01,
590cdf0e10cSrcweir 		OPTION_UNINSTALL = 0x02,
591cdf0e10cSrcweir 
592cdf0e10cSrcweir 		OPTION_DECRYPT   = 0x04,
593cdf0e10cSrcweir 		OPTION_ENCRYPT   = 0x08,
594cdf0e10cSrcweir 		OPTION_SIGN      = 0x10,
595cdf0e10cSrcweir 
596cdf0e10cSrcweir 		OPTION_FILE      = 0x20,
597cdf0e10cSrcweir 		OPTION_HELP      = 0x40
598cdf0e10cSrcweir 	};
599cdf0e10cSrcweir 
600cdf0e10cSrcweir 	int fd = 0;
601cdf0e10cSrcweir 	unsigned long nOptions = 0;
602cdf0e10cSrcweir 
603cdf0e10cSrcweir 	for (int i = 1; i < argc; i++)
604cdf0e10cSrcweir 	{
605cdf0e10cSrcweir 		const char *opt = argv[i];
606cdf0e10cSrcweir 		if (opt[0] == '-')
607cdf0e10cSrcweir 		{
608cdf0e10cSrcweir 			switch (opt[1])
609cdf0e10cSrcweir 			{
610cdf0e10cSrcweir 				case 'i':
611cdf0e10cSrcweir 					nOptions |= OPTION_INSTALL;
612cdf0e10cSrcweir 					break;
613cdf0e10cSrcweir 
614cdf0e10cSrcweir 				case 'u':
615cdf0e10cSrcweir 					nOptions |= OPTION_UNINSTALL;
616cdf0e10cSrcweir 					break;
617cdf0e10cSrcweir 
618cdf0e10cSrcweir 				case 'd':
619cdf0e10cSrcweir 					nOptions |= OPTION_DECRYPT;
620cdf0e10cSrcweir 					break;
621cdf0e10cSrcweir 
622cdf0e10cSrcweir 				case 'e':
623cdf0e10cSrcweir 					nOptions |= OPTION_ENCRYPT;
624cdf0e10cSrcweir 					break;
625cdf0e10cSrcweir 
626cdf0e10cSrcweir 				case 's':
627cdf0e10cSrcweir 					nOptions |= OPTION_SIGN;
628cdf0e10cSrcweir 					break;
629cdf0e10cSrcweir 
630cdf0e10cSrcweir 				case 'f':
631cdf0e10cSrcweir 					nOptions |= OPTION_FILE;
632cdf0e10cSrcweir 					break;
633cdf0e10cSrcweir 
634cdf0e10cSrcweir 				case 'h':
635cdf0e10cSrcweir 				default:
636cdf0e10cSrcweir 					nOptions |= OPTION_HELP;
637cdf0e10cSrcweir 					break;
638cdf0e10cSrcweir 			}
639cdf0e10cSrcweir 		}
640cdf0e10cSrcweir 		else
641cdf0e10cSrcweir 		{
642cdf0e10cSrcweir 			if (nOptions & OPTION_FILE)
643cdf0e10cSrcweir 			{
644cdf0e10cSrcweir 				if ((fd = open (argv[i], O_RDONLY | O_BINARY)) < 0)
645cdf0e10cSrcweir 				{
646cdf0e10cSrcweir 					printf ("Error: can't open file: %s\n", argv[i]);
647cdf0e10cSrcweir 					exit (0);
648cdf0e10cSrcweir 				}
649cdf0e10cSrcweir 			}
650cdf0e10cSrcweir 		}
651cdf0e10cSrcweir 	}
652cdf0e10cSrcweir 
653cdf0e10cSrcweir 	if ((nOptions == 0) || (nOptions & OPTION_HELP))
654cdf0e10cSrcweir 	{
655cdf0e10cSrcweir 		printf ("Options:\n");
656cdf0e10cSrcweir 		printf ("-i\tinstall module\n");
657cdf0e10cSrcweir 		printf ("-u\tuninstall module\n");
658cdf0e10cSrcweir 		printf ("-d\tdecrypt and verify\n");
659cdf0e10cSrcweir 		printf ("-e\tencrypt test pattern\n");
660cdf0e10cSrcweir 		printf ("-s\tsign test pattern\n");
661cdf0e10cSrcweir 		printf ("-h\thelp\n");
662cdf0e10cSrcweir 		exit (0);
663cdf0e10cSrcweir 	}
664cdf0e10cSrcweir 
665cdf0e10cSrcweir 	Reference<XMultiServiceFactory> xManager (
666cdf0e10cSrcweir 		usr::createDefaultSmartRegistryServiceFactory());
667cdf0e10cSrcweir 	if (!xManager.is())
668cdf0e10cSrcweir 	{
669cdf0e10cSrcweir 		printf ("Error: no ProcessServiceManager.\n");
670cdf0e10cSrcweir 		exit (1);
671cdf0e10cSrcweir 	}
672cdf0e10cSrcweir 	usr::setProcessServiceFactory (xManager);
673cdf0e10cSrcweir 
674cdf0e10cSrcweir 	if (nOptions & OPTION_INSTALL)
675cdf0e10cSrcweir 	{
676cdf0e10cSrcweir #if 0  /* OLD */
677cdf0e10cSrcweir 		XServiceActivatorRef xActivator;
678cdf0e10cSrcweir 		if (queryModuleActivator (xManager, xActivator))
679cdf0e10cSrcweir 		{
680cdf0e10cSrcweir 			if (install (xActivator, "pgp"))
681cdf0e10cSrcweir 				printf ("Module PGP installed.\n");
682cdf0e10cSrcweir 			else
683cdf0e10cSrcweir 				printf ("Error: module PGP not installed.\n");
684cdf0e10cSrcweir 		}
685cdf0e10cSrcweir 		nOptions &= ~OPTION_INSTALL;
686cdf0e10cSrcweir #endif /* OLD */
687cdf0e10cSrcweir 	}
688cdf0e10cSrcweir 
689cdf0e10cSrcweir 	if (nOptions & (OPTION_DECRYPT | OPTION_ENCRYPT | OPTION_SIGN))
690cdf0e10cSrcweir 	{
691cdf0e10cSrcweir 		Reference<XMultiServiceFactory> xProv (
692cdf0e10cSrcweir 			xManager->createInstance (
693cdf0e10cSrcweir 				S2U("com.sun.star.pgp.PGPFactory")),
694cdf0e10cSrcweir 			UNO_QUERY);
695cdf0e10cSrcweir 		if (!xProv.is())
696cdf0e10cSrcweir 		{
697cdf0e10cSrcweir 			printf ("Error: no PGPFactory service.\n");
698cdf0e10cSrcweir 			exit (1);
699cdf0e10cSrcweir 		}
700cdf0e10cSrcweir 
701cdf0e10cSrcweir 		Reference<XInterface> xProvInst (
702cdf0e10cSrcweir 			xProv->createInstance (
703cdf0e10cSrcweir 				S2U("com.sun.star.pgp.SimplePGPMailer")));
704cdf0e10cSrcweir 		if (!xProvInst.is())
705cdf0e10cSrcweir 		{
706cdf0e10cSrcweir 			printf ("Error: no SimplePGPMailer service.\n");
707cdf0e10cSrcweir 			exit (2);
708cdf0e10cSrcweir 		}
709cdf0e10cSrcweir 
710cdf0e10cSrcweir 		Reference<XPGPPreferences> xPrefs (xProvInst, UNO_QUERY);
711cdf0e10cSrcweir 		if (xPrefs.is())
712cdf0e10cSrcweir 		{
713cdf0e10cSrcweir 			unsigned long nDefaults = 0;
714cdf0e10cSrcweir 
715cdf0e10cSrcweir 			if (xPrefs->getEncryptByDefault())
716cdf0e10cSrcweir 				nDefaults |= OPTION_ENCRYPT;
717cdf0e10cSrcweir 			if (xPrefs->getSignByDefault())
718cdf0e10cSrcweir 				nDefaults |= OPTION_SIGN;
719cdf0e10cSrcweir 			if (xPrefs->getAutoDecrypt())
720cdf0e10cSrcweir 				nDefaults |= OPTION_DECRYPT;
721cdf0e10cSrcweir 
722cdf0e10cSrcweir 			if (nDefaults)
723cdf0e10cSrcweir 			{
724cdf0e10cSrcweir 			}
725cdf0e10cSrcweir 		}
726cdf0e10cSrcweir 
727cdf0e10cSrcweir 		static const sal_Int8 pData[] = "" /* "Hello PGP World." */;
728cdf0e10cSrcweir 		Sequence<sal_Int8> buffer (pData, sizeof (pData) - 1);
729cdf0e10cSrcweir 
730cdf0e10cSrcweir 		if (nOptions & (OPTION_ENCRYPT | OPTION_SIGN))
731cdf0e10cSrcweir 		{
732cdf0e10cSrcweir 			Reference<XPGPEncoder> xEncoder (xProvInst, UNO_QUERY);
733cdf0e10cSrcweir 			if (!xEncoder.is())
734cdf0e10cSrcweir 			{
735cdf0e10cSrcweir 				printf ("Error: no PGPEncoder interface.\n");
736cdf0e10cSrcweir 				exit (4);
737cdf0e10cSrcweir 			}
738cdf0e10cSrcweir 
739cdf0e10cSrcweir 			DataSource_Impl *source = new DataSource_Impl (fd);
740cdf0e10cSrcweir 			source->setBuffer (buffer);
741cdf0e10cSrcweir 
742cdf0e10cSrcweir 			DataSink_Impl *sink = new DataSink_Impl;
743cdf0e10cSrcweir 
744cdf0e10cSrcweir 			Reference<XInputStream>  xPlainText  (source);
745cdf0e10cSrcweir 			Reference<XOutputStream> xCipherText (sink);
746cdf0e10cSrcweir 
747cdf0e10cSrcweir 			if (nOptions & OPTION_ENCRYPT)
748cdf0e10cSrcweir 			{
749cdf0e10cSrcweir 				rtl::OWString aRecipients[] =
750cdf0e10cSrcweir 				{
751cdf0e10cSrcweir 					S2U("er@stardiv.de"),
752cdf0e10cSrcweir 					// L"mhu@stardivision.de",
753cdf0e10cSrcweir 					S2U("mhu@rabbit")
754cdf0e10cSrcweir 				};
755cdf0e10cSrcweir 
756cdf0e10cSrcweir 				sal_Int32 nRecipients =
757cdf0e10cSrcweir 					sizeof(aRecipients) / sizeof(aRecipients[0]);
758cdf0e10cSrcweir 
759cdf0e10cSrcweir 				if (nOptions & OPTION_SIGN)
760cdf0e10cSrcweir 				{
761cdf0e10cSrcweir 					xEncoder->encryptAndSign (
762cdf0e10cSrcweir 						Sequence<rtl::OWString>(aRecipients, nRecipients),
763cdf0e10cSrcweir 						xPlainText,
764cdf0e10cSrcweir 						xCipherText);
765cdf0e10cSrcweir 					nOptions &= ~OPTION_SIGN;
766cdf0e10cSrcweir 				}
767cdf0e10cSrcweir 				else
768cdf0e10cSrcweir 				{
769cdf0e10cSrcweir 					xEncoder->encrypt (
770cdf0e10cSrcweir 						Sequence<rtl::OWString>(aRecipients, nRecipients),
771cdf0e10cSrcweir 						xPlainText,
772cdf0e10cSrcweir 						xCipherText);
773cdf0e10cSrcweir 				}
774cdf0e10cSrcweir 				nOptions &= ~OPTION_ENCRYPT;
775cdf0e10cSrcweir 			}
776cdf0e10cSrcweir 
777cdf0e10cSrcweir 			if (nOptions & OPTION_SIGN)
778cdf0e10cSrcweir 			{
779cdf0e10cSrcweir 				sal_Bool bDataIsAscii = (fd == 0); // stdin.
780cdf0e10cSrcweir 
781cdf0e10cSrcweir 				xEncoder->sign (
782cdf0e10cSrcweir 					bDataIsAscii,
783cdf0e10cSrcweir 					xPlainText,
784cdf0e10cSrcweir 					xCipherText);
785cdf0e10cSrcweir 				nOptions &= ~OPTION_SIGN;
786cdf0e10cSrcweir 			}
787cdf0e10cSrcweir 
788cdf0e10cSrcweir 			buffer = sink->getBuffer();
789cdf0e10cSrcweir 		}
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 		if (nOptions & OPTION_DECRYPT)
792cdf0e10cSrcweir 		{
793cdf0e10cSrcweir 			Reference<XPGPDecoder> xDecoder (xProvInst, UNO_QUERY);
794cdf0e10cSrcweir 			if (!xDecoder.is())
795cdf0e10cSrcweir 			{
796cdf0e10cSrcweir 				printf ("Error: no PGPDecoder interface.\n");
797cdf0e10cSrcweir 				exit (5);
798cdf0e10cSrcweir 			}
799cdf0e10cSrcweir 
800cdf0e10cSrcweir 			DataSource_Impl *source = new DataSource_Impl;
801cdf0e10cSrcweir 			source->setBuffer (buffer);
802cdf0e10cSrcweir 
803cdf0e10cSrcweir 			DataSink_Impl *sink = new DataSink_Impl;
804cdf0e10cSrcweir 
805cdf0e10cSrcweir 			Reference<XInputStream>  xCipherText (source);
806cdf0e10cSrcweir 			Reference<XOutputStream> xPlainText  (sink);
807cdf0e10cSrcweir 
808cdf0e10cSrcweir 			Reference<XPGPDecoderListener> xListener (
809cdf0e10cSrcweir 				new DecoderListener_Impl);
810cdf0e10cSrcweir 			xDecoder->addDecoderListener (xListener);
811cdf0e10cSrcweir 
812cdf0e10cSrcweir 			xDecoder->decryptAndVerify (
813cdf0e10cSrcweir 				xCipherText,
814cdf0e10cSrcweir 				xPlainText);
815cdf0e10cSrcweir 			nOptions &= ~OPTION_DECRYPT;
816cdf0e10cSrcweir 
817cdf0e10cSrcweir 			xDecoder->removeDecoderListener (xListener);
818cdf0e10cSrcweir 
819cdf0e10cSrcweir 			buffer = sink->getBuffer();
820cdf0e10cSrcweir 		}
821cdf0e10cSrcweir 	}
822cdf0e10cSrcweir 
823cdf0e10cSrcweir 	if (nOptions & OPTION_UNINSTALL)
824cdf0e10cSrcweir 	{
825cdf0e10cSrcweir #if 0  /* OLD */
826cdf0e10cSrcweir 		XServiceActivatorRef xActivator;
827cdf0e10cSrcweir 		if (queryModuleActivator (xManager, xActivator))
828cdf0e10cSrcweir 		{
829cdf0e10cSrcweir 			if (uninstall (xActivator, "pgp"))
830cdf0e10cSrcweir 				printf ("Module PGP uninstalled.\n");
831cdf0e10cSrcweir 			else
832cdf0e10cSrcweir 				printf ("Error: module PGP not uninstalled.\n");
833cdf0e10cSrcweir 		}
834cdf0e10cSrcweir 		nOptions &= ~OPTION_UNINSTALL;
835cdf0e10cSrcweir #endif /* OLD */
836cdf0e10cSrcweir 	}
837cdf0e10cSrcweir 
838cdf0e10cSrcweir 	return 0;
839cdf0e10cSrcweir }
840cdf0e10cSrcweir 
841