MPInteger
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Math.EC;
using System;
namespace Org.BouncyCastle.Bcpg
{
public sealed class MPInteger : BcpgObject
{
private readonly BigInteger m_val;
public BigInteger Value => m_val;
public MPInteger(BcpgInputStream bcpgIn)
{
if (bcpgIn == null)
throw new ArgumentNullException("bcpgIn");
byte[] array = new byte[(StreamUtilities.RequireUInt16BE(bcpgIn) + 7) / 8];
bcpgIn.ReadFully(array);
m_val = new BigInteger(1, array);
}
public MPInteger(BigInteger val)
{
if (val == null)
throw new ArgumentNullException("val");
if (val.SignValue < 0)
throw new ArgumentException("Values must be positive", "val");
m_val = val;
}
public override void Encode(BcpgOutputStream bcpgOut)
{
bcpgOut.WriteShort((short)m_val.BitLength);
bcpgOut.Write(m_val.ToByteArrayUnsigned());
}
internal static BigInteger ToMpiBigInteger(ECPoint point)
{
byte[] encoded = point.GetEncoded(false);
return new BigInteger(1, encoded);
}
}
}