2018-07-16 16:26:05 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Paul Schaub.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2018-07-18 18:23:06 +02:00
|
|
|
package org.pgpainless;
|
2018-07-16 16:26:05 +02:00
|
|
|
|
|
|
|
import static junit.framework.TestCase.assertTrue;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.security.InvalidAlgorithmParameterException;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
import java.security.NoSuchProviderException;
|
|
|
|
import java.security.Security;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
|
|
|
import org.bouncycastle.openpgp.PGPException;
|
|
|
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
|
|
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
|
|
|
import org.junit.Test;
|
2018-07-18 18:23:06 +02:00
|
|
|
import org.pgpainless.key.collection.PGPKeyRing;
|
|
|
|
import org.pgpainless.util.BCUtil;
|
|
|
|
import org.pgpainless.util.KeyRingSubKeyFix;
|
2018-07-16 16:26:05 +02:00
|
|
|
|
|
|
|
public class KeyRingSubKeyFixTest {
|
|
|
|
|
|
|
|
static {
|
|
|
|
Security.addProvider(new BouncyCastleProvider());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void test()
|
|
|
|
throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException,
|
|
|
|
IOException {
|
|
|
|
PGPKeyRing ring = PGPainless.generateKeyRing().simpleEcKeyRing("hallo@welt.de");
|
|
|
|
PGPSecretKeyRing secretKeys = ring.getSecretKeys();
|
|
|
|
PGPPublicKeyRing publicKeys = ring.getPublicKeys();
|
|
|
|
|
|
|
|
PGPSecretKeyRing fixed = KeyRingSubKeyFix.repairSubkeyPackets(secretKeys, null, null);
|
|
|
|
|
2018-07-16 17:16:16 +02:00
|
|
|
assertTrue(Arrays.equals(secretKeys.getEncoded(), fixed.getEncoded()));
|
2018-07-16 16:26:05 +02:00
|
|
|
|
2018-07-16 17:16:16 +02:00
|
|
|
PGPPublicKeyRing fixedPub = BCUtil.publicKeyRingFromSecretKeyRing(fixed);
|
2018-07-16 16:26:05 +02:00
|
|
|
|
2018-07-16 17:16:16 +02:00
|
|
|
assertTrue(Arrays.equals(publicKeys.getEncoded(), fixedPub.getEncoded()));
|
2018-07-16 16:26:05 +02:00
|
|
|
}
|
|
|
|
}
|