001    package org.apache.commons.openpgp;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import java.io.IOException;
021    import java.io.InputStream;
022    
023    /**
024     * Verify signatures using the Bouncy Castle OpenPGP provider.
025     *
026     * @author <a href="mailto:brett@apache.org">Brett Porter</a>
027     */
028    public class BouncyCastleOpenPgpSignatureVerifier
029        implements OpenPgpSignatureVerifier
030    {
031        private static final int BUFFER_SIZE = 1024;
032    
033        public SignatureStatus verifySignature( InputStream data, KeyRing keyRing )
034            throws OpenPgpException, UnknownKeyException
035        {
036            // TODO: implement
037            return null;  //To change body of implemented methods use File | Settings | File Templates.
038        }
039    
040        public SignatureStatus verifyDetachedSignature( InputStream data, InputStream signature, KeyRing keyRing )
041            throws OpenPgpException, UnknownKeyException, IOException
042        {
043            OpenPgpStreamingSignatureVerifier verifier =
044                new BouncyCastleOpenPgpStreamingSignatureVerifier( signature, keyRing );
045    
046            byte[] buf = new byte[BUFFER_SIZE];
047    
048            int len;
049            do
050            {
051                len = data.read( buf );
052                if ( len > 0 )
053                {
054                    verifier.update( buf, 0, len );
055                }
056            }
057            while ( len >= 0 );
058    
059            return verifier.finish();
060        }
061    }