DHParameter
using Org.BouncyCastle.Math;
using System;
namespace Org.BouncyCastle.Asn1.Pkcs
{
public class DHParameter : Asn1Encodable
{
private readonly DerInteger m_p;
private readonly DerInteger m_g;
private readonly DerInteger m_l;
public BigInteger P => m_p.PositiveValue;
public BigInteger G => m_g.PositiveValue;
public BigInteger L => m_l?.PositiveValue;
public static DHParameter GetInstance(object obj)
{
if (obj == null)
return null;
DHParameter dHParameter = obj as DHParameter;
if (dHParameter != null)
return dHParameter;
return new DHParameter(Asn1Sequence.GetInstance(obj));
}
public static DHParameter GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return new DHParameter(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
}
public static DHParameter GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return new DHParameter(Asn1Sequence.GetTagged(taggedObject, declaredExplicit));
}
public DHParameter(BigInteger p, BigInteger g, int l)
{
m_p = new DerInteger(p);
m_g = new DerInteger(g);
if (l != 0)
m_l = new DerInteger(l);
}
[Obsolete("Use 'GetInstance' instead")]
public DHParameter(Asn1Sequence seq)
{
int count = seq.Count;
int sequencePosition = 0;
if (count < 2 || count > 3)
throw new ArgumentException("Bad sequence size: " + count.ToString(), "seq");
m_p = DerInteger.GetInstance(seq[sequencePosition++]);
m_g = DerInteger.GetInstance(seq[sequencePosition++]);
m_l = Asn1Utilities.ReadOptional(seq, ref sequencePosition, DerInteger.GetOptional);
if (sequencePosition != count)
throw new ArgumentException("Unexpected elements in sequence", "seq");
}
public override Asn1Object ToAsn1Object()
{
if (m_l != null)
return new DerSequence(m_p, m_g, m_l);
return new DerSequence(m_p, m_g);
}
}
}