diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-05-26 22:58:57 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-05-26 22:58:57 +0700 |
commit | 46c46cecd4f62abf854576314751e44b320168ba (patch) | |
tree | 6bafc67dbf0f5480d9814e7764e770faad233f66 /crypto/src/asn1/esf/SignaturePolicyIdentifier.cs | |
parent | Auto-adjust DateTime precision for GeneralizedTime in X.509 (and OCSP) (diff) | |
download | BouncyCastle.NET-ed25519-46c46cecd4f62abf854576314751e44b320168ba.tar.xz |
Refactoring in Asn1.Esf
Diffstat (limited to 'crypto/src/asn1/esf/SignaturePolicyIdentifier.cs')
-rw-r--r-- | crypto/src/asn1/esf/SignaturePolicyIdentifier.cs | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/crypto/src/asn1/esf/SignaturePolicyIdentifier.cs b/crypto/src/asn1/esf/SignaturePolicyIdentifier.cs index 12257f2f0..eb6c0654c 100644 --- a/crypto/src/asn1/esf/SignaturePolicyIdentifier.cs +++ b/crypto/src/asn1/esf/SignaturePolicyIdentifier.cs @@ -17,50 +17,39 @@ namespace Org.BouncyCastle.Asn1.Esf public class SignaturePolicyIdentifier : Asn1Encodable, IAsn1Choice { - private readonly SignaturePolicyId sigPolicy; - - public static SignaturePolicyIdentifier GetInstance( - object obj) + public static SignaturePolicyIdentifier GetInstance(object obj) { - if (obj == null || obj is SignaturePolicyIdentifier) - return (SignaturePolicyIdentifier) obj; + if (obj == null) + return null; - if (obj is SignaturePolicyId) - return new SignaturePolicyIdentifier((SignaturePolicyId) obj); + if (obj is SignaturePolicyIdentifier signaturePolicyIdentifier) + return signaturePolicyIdentifier; - if (obj is Asn1Null) - return new SignaturePolicyIdentifier(); + if (obj is Asn1Null) + return new SignaturePolicyIdentifier(); - throw new ArgumentException( - "Unknown object in 'SignaturePolicyIdentifier' factory: " - + Platform.GetTypeName(obj), - "obj"); + return new SignaturePolicyIdentifier(SignaturePolicyId.GetInstance(obj)); } - public SignaturePolicyIdentifier() - { - this.sigPolicy = null; - } + public static SignaturePolicyIdentifier GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) + { + return Asn1Utilities.GetInstanceFromChoice(taggedObject, declaredExplicit, GetInstance); + } - public SignaturePolicyIdentifier( - SignaturePolicyId signaturePolicyId) - { - if (signaturePolicyId == null) - throw new ArgumentNullException("signaturePolicyId"); + private readonly SignaturePolicyId m_sigPolicy; - this.sigPolicy = signaturePolicyId; - } - - public SignaturePolicyId SignaturePolicyId + public SignaturePolicyIdentifier() { - get { return sigPolicy; } + m_sigPolicy = null; } - public override Asn1Object ToAsn1Object() + public SignaturePolicyIdentifier(SignaturePolicyId signaturePolicyId) { - return sigPolicy == null - ? DerNull.Instance - : sigPolicy.ToAsn1Object(); - } + m_sigPolicy = signaturePolicyId ?? throw new ArgumentNullException(nameof(signaturePolicyId)); + } + + public SignaturePolicyId SignaturePolicyId => m_sigPolicy; + + public override Asn1Object ToAsn1Object() => m_sigPolicy?.ToAsn1Object() ?? DerNull.Instance; } } |