package com.codahale.gpgj;

import org.bouncycastle.asn1.nist.NISTNamedCurves;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import org.bouncycastle.crypto.generators.ECKeyPairGenerator;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.crypto.params.ECKeyGenerationParameters;

import java.security.SecureRandom;

/**
 * An abstract base class for ECC key generators.
 *
 * @deprecated Not supported in GnuPG or BouncyCastle yet.
 */
@Deprecated
abstract class AbstractEcKeyGenerator {
    protected static final ECDomainParameters P256;
    protected static final ECDomainParameters P384;
    protected static final ECDomainParameters P521;

    static {
        final X9ECParameters p256 = NISTNamedCurves.getByName("P-256");
        P256 = new ECDomainParameters(p256.getCurve(), p256.getG(), p256.getN(), p256.getH(), p256.getSeed());

        final X9ECParameters p384 = NISTNamedCurves.getByName("P-384");
        P384 = new ECDomainParameters(p384.getCurve(), p384.getG(), p384.getN(), p384.getH(), p384.getSeed());

        final X9ECParameters p521 = NISTNamedCurves.getByName("P-521");
        P521 = new ECDomainParameters(p521.getCurve(), p521.getG(), p521.getN(), p521.getH(), p521.getSeed());
    }

    private final ECDomainParameters parameters;

    protected AbstractEcKeyGenerator(ECDomainParameters parameters) {
        this.parameters = parameters;
    }

    public AsymmetricCipherKeyPair generate(SecureRandom random) {
        final ECKeyPairGenerator generator = new ECKeyPairGenerator();
        generator.init(new ECKeyGenerationParameters(parameters, random));
        return generator.generateKeyPair();
    }
}

@@ -620,16 +620,62 @@
 ers P256
+ = convert(NISTNamedCurves.getByName(%22P-256%22))
 ;%0A    pr
@@ -718,16 +718,62 @@
 ers P384
+ = convert(NISTNamedCurves.getByName(%22P-384%22))
 ;%0A    pr
@@ -820,60 +820,19 @@
 P521
-;%0A%0A    static %7B%0A        final X9ECParameters p256 = 
+ = convert(
 NIST
@@ -860,33 +860,35 @@
 (%22P-
-256%22
+521%22)
 );%0A
+%0A
     
-    P256 = new
+private static
  ECD
@@ -906,154 +906,41 @@
 ters
-(p256.getCurve(), p256.getG(), p256.getN(), p256.getH(), p256.getSeed());%0A%0A        final X9ECParameters p384 = NISTNamedCurves.getByName(%22P-384%22);
+ convert(X9ECParameters params) %7B
 %0A   
@@ -944,22 +944,22 @@
         
-P384 =
+return
  new ECD
@@ -975,19 +975,21 @@
 meters(p
-384
+arams
 .getCurv
@@ -990,27 +990,29 @@
 etCurve(), p
-384
+arams
 .getG(), p38
@@ -1013,19 +1013,21 @@
 ), p
-384
+arams
 .getN(),
  p38
@@ -1026,197 +1026,53 @@
 N(),
- p384.getH(), p384.getSeed());%0A%0A        final X9ECParameters p521 = NISTNamedCurves.getByName(%22P-521%22);%0A        P521 = new ECDomainParameters(p521.getCurve(), p521.getG(), p521.getN(), p521
+%0A                                      params
 .get
@@ -1077,19 +1077,21 @@
 etH(), p
-521
+arams
 .getSeed

Simplify AbstractEcKeyGenerator.