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