package org.bouncycastle.jcajce.provider.asymmetric.elgamal;
import java.io.IOException;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidParameterSpecException;
import javax.crypto.spec.DHParameterSpec;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.oiw.ElGamalParameter;
import org.bouncycastle.jcajce.provider.symmetric.util.BaseAlgorithmParameters;
import org.bouncycastle.jce.spec.ElGamalParameterSpec;
public class
extends BaseAlgorithmParameters
{
ElGamalParameterSpec ;
protected byte[] ()
{
ElGamalParameter elP = new ElGamalParameter(currentSpec.getP(), currentSpec.getG());
try
{
return elP.getEncoded(ASN1Encoding.DER);
}
catch (IOException e)
{
throw new RuntimeException("Error encoding ElGamalParameters");
}
}
protected byte[] (
String format)
{
if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))
{
return engineGetEncoded();
}
return null;
}
protected AlgorithmParameterSpec (
Class paramSpec)
throws InvalidParameterSpecException
{
if (paramSpec == ElGamalParameterSpec.class || paramSpec == AlgorithmParameterSpec.class)
{
return currentSpec;
}
else if (paramSpec == DHParameterSpec.class)
{
return new DHParameterSpec(currentSpec.getP(), currentSpec.getG());
}
throw new InvalidParameterSpecException("unknown parameter spec passed to ElGamal parameters object.");
}
protected void (
AlgorithmParameterSpec paramSpec)
throws InvalidParameterSpecException
{
if (!(paramSpec instanceof ElGamalParameterSpec) && !(paramSpec instanceof DHParameterSpec))
{
throw new InvalidParameterSpecException("DHParameterSpec required to initialise a ElGamal algorithm parameters object");
}
if (paramSpec instanceof ElGamalParameterSpec)
{
this.currentSpec = (ElGamalParameterSpec)paramSpec;
}
else
{
DHParameterSpec s = (DHParameterSpec)paramSpec;
this.currentSpec = new ElGamalParameterSpec(s.getP(), s.getG());
}
}
protected void (
byte[] params)
throws IOException
{
try
{
ElGamalParameter elP = ElGamalParameter.getInstance(ASN1Primitive.fromByteArray(params));
currentSpec = new ElGamalParameterSpec(elP.getP(), elP.getG());
}
catch (ClassCastException e)
{
throw new IOException("Not a valid ElGamal Parameter encoding.");
}
catch (ArrayIndexOutOfBoundsException e)
{
throw new IOException("Not a valid ElGamal Parameter encoding.");
}
}
protected void (
byte[] params,
String format)
throws IOException
{
if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))
{
engineInit(params);
}
else
{
throw new IOException("Unknown parameter format " + format);
}
}
protected String ()
{
return "ElGamal Parameters";
}
}