diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-07-01 21:32:14 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-07-01 21:32:14 +0700 |
commit | 3c9d8a7198b04fa80f034c372fba4eea65c31e3b (patch) | |
tree | e1ee1e6c0a747dc4025acb490fd3cf9f2cde9b12 /crypto/src/asn1/x509/qualified/MonetaryValue.cs | |
parent | Asn1Sequence subclass static methods (diff) | |
download | BouncyCastle.NET-ed25519-3c9d8a7198b04fa80f034c372fba4eea65c31e3b.tar.xz |
Refactoring in Asn1.X509.Qualified
Diffstat (limited to 'crypto/src/asn1/x509/qualified/MonetaryValue.cs')
-rw-r--r-- | crypto/src/asn1/x509/qualified/MonetaryValue.cs | 77 |
1 files changed, 30 insertions, 47 deletions
diff --git a/crypto/src/asn1/x509/qualified/MonetaryValue.cs b/crypto/src/asn1/x509/qualified/MonetaryValue.cs index be4cd1142..b79d5d50a 100644 --- a/crypto/src/asn1/x509/qualified/MonetaryValue.cs +++ b/crypto/src/asn1/x509/qualified/MonetaryValue.cs @@ -1,7 +1,6 @@ using System; using Org.BouncyCastle.Math; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.X509.Qualified { @@ -18,65 +17,49 @@ namespace Org.BouncyCastle.Asn1.X509.Qualified public class MonetaryValue : Asn1Encodable { - internal Iso4217CurrencyCode currency; - internal DerInteger amount; - internal DerInteger exponent; - - public static MonetaryValue GetInstance( - object obj) + public static MonetaryValue GetInstance(object obj) { - if (obj == null || obj is MonetaryValue) - { - return (MonetaryValue) obj; - } + if (obj == null) + return null; + if (obj is MonetaryValue monetaryValue) + return monetaryValue; + return new MonetaryValue(Asn1Sequence.GetInstance(obj)); + } + + public static MonetaryValue GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) => + new MonetaryValue(Asn1Sequence.GetInstance(taggedObject, declaredExplicit)); - if (obj is Asn1Sequence) - { - return new MonetaryValue(Asn1Sequence.GetInstance(obj)); - } + public static MonetaryValue GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) => + new MonetaryValue(Asn1Sequence.GetTagged(taggedObject, declaredExplicit)); - throw new ArgumentException("unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj"); - } + private readonly Iso4217CurrencyCode m_currency; + private readonly DerInteger m_amount; + private readonly DerInteger m_exponent; - private MonetaryValue( - Asn1Sequence seq) + private MonetaryValue(Asn1Sequence seq) { - if (seq.Count != 3) - throw new ArgumentException("Bad sequence size: " + seq.Count, "seq"); + int count = seq.Count; + if (count != 3) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); - currency = Iso4217CurrencyCode.GetInstance(seq[0]); - amount = DerInteger.GetInstance(seq[1]); - exponent = DerInteger.GetInstance(seq[2]); + m_currency = Iso4217CurrencyCode.GetInstance(seq[0]); + m_amount = DerInteger.GetInstance(seq[1]); + m_exponent = DerInteger.GetInstance(seq[2]); } - public MonetaryValue( - Iso4217CurrencyCode currency, - int amount, - int exponent) + public MonetaryValue(Iso4217CurrencyCode currency, int amount, int exponent) { - this.currency = currency; - this.amount = new DerInteger(amount); - this.exponent = new DerInteger(exponent); + m_currency = currency ?? throw new ArgumentNullException(nameof(currency)); + m_amount = new DerInteger(amount); + m_exponent = new DerInteger(exponent); } - public Iso4217CurrencyCode Currency - { - get { return currency; } - } + public Iso4217CurrencyCode Currency => m_currency; - public BigInteger Amount - { - get { return amount.Value; } - } + public BigInteger Amount => m_amount.Value; - public BigInteger Exponent - { - get { return exponent.Value; } - } + public BigInteger Exponent => m_exponent.Value; - public override Asn1Object ToAsn1Object() - { - return new DerSequence(currency, amount, exponent); - } + public override Asn1Object ToAsn1Object() => new DerSequence(m_currency, m_amount, m_exponent); } } |