diff options
Diffstat (limited to 'crypto/src/asn1/isismtt/x509/MonetaryLimit.cs')
-rw-r--r-- | crypto/src/asn1/isismtt/x509/MonetaryLimit.cs | 87 |
1 files changed, 35 insertions, 52 deletions
diff --git a/crypto/src/asn1/isismtt/x509/MonetaryLimit.cs b/crypto/src/asn1/isismtt/x509/MonetaryLimit.cs index b792fffda..42a4a3164 100644 --- a/crypto/src/asn1/isismtt/x509/MonetaryLimit.cs +++ b/crypto/src/asn1/isismtt/x509/MonetaryLimit.cs @@ -1,11 +1,10 @@ using System; using Org.BouncyCastle.Math; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.IsisMtt.X509 { - /** + /** * Monetary limit for transactions. The QcEuMonetaryLimit QC statement MUST be * used in new certificates in place of the extension/attribute MonetaryLimit * since January 1, 2004. For the sake of backward compatibility with @@ -29,41 +28,40 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 * <p/> * value = amount�10*exponent */ - public class MonetaryLimit + public class MonetaryLimit : Asn1Encodable { - private readonly DerPrintableString currency; - private readonly DerInteger amount; - private readonly DerInteger exponent; + public static MonetaryLimit GetInstance(object obj) + { + if (obj == null) + return null; + if (obj is MonetaryLimit monetaryLimit) + return monetaryLimit; + return new MonetaryLimit(Asn1Sequence.GetInstance(obj)); + } - public static MonetaryLimit GetInstance( - object obj) - { - if (obj == null || obj is MonetaryLimit) - { - return (MonetaryLimit) obj; - } + public static MonetaryLimit GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) => + new MonetaryLimit(Asn1Sequence.GetInstance(taggedObject, declaredExplicit)); - if (obj is Asn1Sequence) - { - return new MonetaryLimit(Asn1Sequence.GetInstance(obj)); - } + public static MonetaryLimit GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) => + new MonetaryLimit(Asn1Sequence.GetTagged(taggedObject, declaredExplicit)); - throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj"); - } + private readonly DerPrintableString m_currency; + private readonly DerInteger m_amount; + private readonly DerInteger m_exponent; - private MonetaryLimit( - Asn1Sequence seq) + private MonetaryLimit(Asn1Sequence seq) { - if (seq.Count != 3) - throw new ArgumentException("Bad sequence size: " + seq.Count); + int count = seq.Count; + if (count != 3) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); - currency = DerPrintableString.GetInstance(seq[0]); - amount = DerInteger.GetInstance(seq[1]); - exponent = DerInteger.GetInstance(seq[2]); + m_currency = DerPrintableString.GetInstance(seq[0]); + m_amount = DerInteger.GetInstance(seq[1]); + m_exponent = DerInteger.GetInstance(seq[2]); } - /** + /** * Constructor from a given details. * <p/> * <p/> @@ -73,30 +71,18 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 * @param amount The amount * @param exponent The exponent */ - public MonetaryLimit( - string currency, - int amount, - int exponent) - { - this.currency = new DerPrintableString(currency, true); - this.amount = new DerInteger(amount); - this.exponent = new DerInteger(exponent); - } + public MonetaryLimit(string currency, int amount, int exponent) + { + m_currency = new DerPrintableString(currency, true); + m_amount = new DerInteger(amount); + m_exponent = new DerInteger(exponent); + } - public virtual string Currency - { - get { return currency.GetString(); } - } + public virtual string Currency => m_currency.GetString(); - public virtual BigInteger Amount - { - get { return amount.Value; } - } + public virtual BigInteger Amount => m_amount.Value; - public virtual BigInteger Exponent - { - get { return exponent.Value; } - } + public virtual BigInteger Exponent => m_exponent.Value; /** * Produce an object suitable for an Asn1OutputStream. @@ -114,9 +100,6 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 * * @return an Asn1Object */ - public override Asn1Object ToAsn1Object() - { - return new DerSequence(currency, amount, exponent); - } + public override Asn1Object ToAsn1Object() => new DerSequence(m_currency, m_amount, m_exponent); } } |