<PackageReference Include="BouncyCastle.Cryptography" Version="2.7.0-beta.98" />

OtherHash

using Org.BouncyCastle.Asn1.Oiw; using Org.BouncyCastle.Asn1.X509; using System; namespace Org.BouncyCastle.Asn1.Esf { public class OtherHash : Asn1Encodable, IAsn1Choice { private readonly Asn1OctetString m_sha1Hash; private readonly OtherHashAlgAndValue m_otherHash; public AlgorithmIdentifier HashAlgorithm => m_otherHash?.HashAlgorithm ?? new AlgorithmIdentifier(OiwObjectIdentifiers.IdSha1); public static OtherHash GetInstance(object obj) { return Asn1Utilities.GetInstanceChoice(obj, GetOptional); } public static OtherHash GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) { return Asn1Utilities.GetInstanceChoice(taggedObject, declaredExplicit, GetInstance); } public static OtherHash GetOptional(Asn1Encodable element) { if (element == null) throw new ArgumentNullException("element"); OtherHash otherHash = element as OtherHash; if (otherHash != null) return otherHash; Asn1OctetString optional = Asn1OctetString.GetOptional(element); if (optional != null) return new OtherHash(optional); OtherHashAlgAndValue optional2 = OtherHashAlgAndValue.GetOptional(element); if (optional2 != null) return new OtherHash(optional2); return null; } public static OtherHash GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) { return Asn1Utilities.GetTaggedChoice(taggedObject, declaredExplicit, GetInstance); } public OtherHash(byte[] sha1Hash) { m_sha1Hash = DerOctetString.FromContents(sha1Hash); } public OtherHash(Asn1OctetString sha1Hash) { if (sha1Hash == null) throw new ArgumentNullException("sha1Hash"); m_sha1Hash = sha1Hash; } public OtherHash(OtherHashAlgAndValue otherHash) { if (otherHash == null) throw new ArgumentNullException("otherHash"); m_otherHash = otherHash; } public byte[] GetHashValue() { return m_otherHash?.GetHashValue() ?? m_sha1Hash.GetOctets(); } public override Asn1Object ToAsn1Object() { return m_otherHash?.ToAsn1Object() ?? m_sha1Hash; } } }