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 static org.junit.Assert.assertNotNull;
021    
022    import java.io.IOException;
023    
024    import org.junit.Before;
025    import org.junit.Test;
026    
027    /**
028     * Test the open pgp key ring.
029     *
030     * @author <a href="mailto:brett@apache.org">Brett Porter</a>
031     */
032    public class BouncyCastleKeyRingTest
033    {
034        private String[] pubKeyId = { "A7D16BD4", "84C9113", "E6C2AB68" };
035    
036        private String[] secKeyId = { "A7D16BD4", "E6C2AB68" };
037    
038        private KeyRing keyRing;
039    
040        private static final String PASSWORD = "cop";
041    
042        @Before
043        public void setUp() throws Exception
044        {
045            keyRing =
046                new BouncyCastleKeyRing( getClass().getResourceAsStream( "/secring.gpg" ),
047                                         getClass().getResourceAsStream( "/pubring.gpg" ), PASSWORD.toCharArray() );
048        }
049    
050        @Test
051        public void testPublicKeys() throws OpenPgpException, IOException
052        {
053            for (String keyId : pubKeyId)
054            {
055                assertNotNull("Unable to find key " + keyId, keyRing.getPublicKey(keyId));
056            }
057        }
058    
059        @Test
060        public void testSecretKeys() throws OpenPgpException, IOException
061        {
062            for (String keyId : secKeyId)
063            {
064                assertNotNull("Unable to find key " + keyId, keyRing.getSecretKey(keyId));
065            }
066        }
067    }