diff options
Diffstat (limited to 'crypto/src/asn1/cms/OriginatorPublicKey.cs')
-rw-r--r-- | crypto/src/asn1/cms/OriginatorPublicKey.cs | 77 |
1 files changed, 24 insertions, 53 deletions
diff --git a/crypto/src/asn1/cms/OriginatorPublicKey.cs b/crypto/src/asn1/cms/OriginatorPublicKey.cs index 83db619ea..8c7c6b50f 100644 --- a/crypto/src/asn1/cms/OriginatorPublicKey.cs +++ b/crypto/src/asn1/cms/OriginatorPublicKey.cs @@ -1,73 +1,47 @@ -using System; - using Org.BouncyCastle.Asn1.X509; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.Cms { public class OriginatorPublicKey : Asn1Encodable { - private readonly AlgorithmIdentifier mAlgorithm; - private readonly DerBitString mPublicKey; - - public OriginatorPublicKey( - AlgorithmIdentifier algorithm, - byte[] publicKey) + public static OriginatorPublicKey GetInstance(object obj) { - this.mAlgorithm = algorithm; - this.mPublicKey = new DerBitString(publicKey); + if (obj == null) + return null; + if (obj is OriginatorPublicKey originatorPublicKey) + return originatorPublicKey; + return new OriginatorPublicKey(Asn1Sequence.GetInstance(obj)); } - private OriginatorPublicKey(Asn1Sequence seq) + public static OriginatorPublicKey GetInstance(Asn1TaggedObject obj, bool explicitly) { - this.mAlgorithm = AlgorithmIdentifier.GetInstance(seq[0]); - this.mPublicKey = DerBitString.GetInstance(seq[1]); + return GetInstance(Asn1Sequence.GetInstance(obj, explicitly)); } - /** - * return an OriginatorPublicKey object from a tagged object. - * - * @param obj the tagged object holding the object we want. - * @param explicitly true if the object is meant to be explicitly - * tagged false otherwise. - * @exception ArgumentException if the object held by the - * tagged object cannot be converted. - */ - public static OriginatorPublicKey GetInstance( - Asn1TaggedObject obj, - bool explicitly) + private readonly AlgorithmIdentifier m_algorithm; + private readonly DerBitString m_publicKey; + + public OriginatorPublicKey(AlgorithmIdentifier algorithm, byte[] publicKey) + : this(algorithm, new DerBitString(publicKey)) { - return GetInstance(Asn1Sequence.GetInstance(obj, explicitly)); } - /** - * return an OriginatorPublicKey object from the given object. - * - * @param obj the object we want converted. - * @exception ArgumentException if the object cannot be converted. - */ - public static OriginatorPublicKey GetInstance( - object obj) + public OriginatorPublicKey(AlgorithmIdentifier algorithm, DerBitString publicKey) { - if (obj == null || obj is OriginatorPublicKey) - return (OriginatorPublicKey)obj; - - if (obj is Asn1Sequence) - return new OriginatorPublicKey(Asn1Sequence.GetInstance(obj)); + m_algorithm = algorithm; + m_publicKey = publicKey; + } - throw new ArgumentException("Invalid OriginatorPublicKey: " + Platform.GetTypeName(obj)); + private OriginatorPublicKey(Asn1Sequence seq) + { + m_algorithm = AlgorithmIdentifier.GetInstance(seq[0]); + m_publicKey = DerBitString.GetInstance(seq[1]); } - public AlgorithmIdentifier Algorithm - { - get { return mAlgorithm; } - } + public AlgorithmIdentifier Algorithm => m_algorithm; - public DerBitString PublicKey - { - get { return mPublicKey; } - } + public DerBitString PublicKey => m_publicKey; /** * Produce an object suitable for an Asn1OutputStream. @@ -78,9 +52,6 @@ namespace Org.BouncyCastle.Asn1.Cms * } * </pre> */ - public override Asn1Object ToAsn1Object() - { - return new DerSequence(mAlgorithm, mPublicKey); - } + public override Asn1Object ToAsn1Object() => new DerSequence(m_algorithm, m_publicKey); } } |