diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-01-17 20:32:13 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-01-17 20:32:13 +0700 |
commit | 2e1dc7df1b47554ed229b65b9574973b43541a10 (patch) | |
tree | fd8b51ede5fe64ef823d8eb60c5db17e40f31544 /crypto/src/asn1/cms/SignedDataParser.cs | |
parent | FIx fetching of DateOfCertGen extension (diff) | |
download | BouncyCastle.NET-ed25519-2e1dc7df1b47554ed229b65b9574973b43541a10.tar.xz |
Refactoring in Asn1
Diffstat (limited to 'crypto/src/asn1/cms/SignedDataParser.cs')
-rw-r--r-- | crypto/src/asn1/cms/SignedDataParser.cs | 182 |
1 files changed, 91 insertions, 91 deletions
diff --git a/crypto/src/asn1/cms/SignedDataParser.cs b/crypto/src/asn1/cms/SignedDataParser.cs index 64114f292..3afbe09f4 100644 --- a/crypto/src/asn1/cms/SignedDataParser.cs +++ b/crypto/src/asn1/cms/SignedDataParser.cs @@ -5,7 +5,7 @@ using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.Cms { - /** + /** * <pre> * SignedData ::= SEQUENCE { * version CMSVersion, @@ -17,102 +17,102 @@ namespace Org.BouncyCastle.Asn1.Cms * } * </pre> */ - public class SignedDataParser - { - private Asn1SequenceParser _seq; - private DerInteger _version; - private object _nextObject; - private bool _certsCalled; - private bool _crlsCalled; - - public static SignedDataParser GetInstance( - object o) - { - if (o is Asn1Sequence) - return new SignedDataParser(((Asn1Sequence)o).Parser); - - if (o is Asn1SequenceParser) - return new SignedDataParser((Asn1SequenceParser)o); + public class SignedDataParser + { + private Asn1SequenceParser _seq; + private DerInteger _version; + private object _nextObject; + private bool _certsCalled; + private bool _crlsCalled; + + public static SignedDataParser GetInstance( + object o) + { + if (o is Asn1Sequence) + return new SignedDataParser(((Asn1Sequence)o).Parser); + + if (o is Asn1SequenceParser) + return new SignedDataParser((Asn1SequenceParser)o); throw new IOException("unknown object encountered: " + Platform.GetTypeName(o)); - } - - public SignedDataParser( - Asn1SequenceParser seq) - { - this._seq = seq; - this._version = (DerInteger)seq.ReadObject(); - } - - public DerInteger Version - { - get { return _version; } - } - - public Asn1SetParser GetDigestAlgorithms() - { - return (Asn1SetParser)_seq.ReadObject(); - } - - public ContentInfoParser GetEncapContentInfo() - { - return new ContentInfoParser((Asn1SequenceParser)_seq.ReadObject()); - } - - public Asn1SetParser GetCertificates() - { - _certsCalled = true; - _nextObject = _seq.ReadObject(); - - if (_nextObject is Asn1TaggedObjectParser o) - { - if (o.HasContextTag(0)) - { - Asn1SetParser certs = (Asn1SetParser)o.ParseBaseUniversal(false, Asn1Tags.SetOf); - _nextObject = null; - return certs; - } - } - - return null; - } - - public Asn1SetParser GetCrls() - { - if (!_certsCalled) - throw new IOException("GetCerts() has not been called."); - - _crlsCalled = true; - - if (_nextObject == null) - { - _nextObject = _seq.ReadObject(); - } - - if (_nextObject is Asn1TaggedObjectParser o) - { - if (o.HasContextTag(1)) - { - Asn1SetParser crls = (Asn1SetParser)o.ParseBaseUniversal(false, Asn1Tags.SetOf); - _nextObject = null; - return crls; - } - } + } + + public SignedDataParser( + Asn1SequenceParser seq) + { + this._seq = seq; + this._version = (DerInteger)seq.ReadObject(); + } + + public DerInteger Version + { + get { return _version; } + } + + public Asn1SetParser GetDigestAlgorithms() + { + return (Asn1SetParser)_seq.ReadObject(); + } + + public ContentInfoParser GetEncapContentInfo() + { + return new ContentInfoParser((Asn1SequenceParser)_seq.ReadObject()); + } + + public Asn1SetParser GetCertificates() + { + _certsCalled = true; + _nextObject = _seq.ReadObject(); + + if (_nextObject is Asn1TaggedObjectParser o) + { + if (o.HasContextTag(0)) + { + Asn1SetParser certs = (Asn1SetParser)o.ParseBaseUniversal(false, Asn1Tags.SetOf); + _nextObject = null; + return certs; + } + } return null; } - public Asn1SetParser GetSignerInfos() - { - if (!_certsCalled || !_crlsCalled) - throw new IOException("GetCerts() and/or GetCrls() has not been called."); + public Asn1SetParser GetCrls() + { + if (!_certsCalled) + throw new IOException("GetCerts() has not been called."); + + _crlsCalled = true; + + if (_nextObject == null) + { + _nextObject = _seq.ReadObject(); + } - if (_nextObject == null) - { - _nextObject = _seq.ReadObject(); - } + if (_nextObject is Asn1TaggedObjectParser o) + { + if (o.HasContextTag(1)) + { + Asn1SetParser crls = (Asn1SetParser)o.ParseBaseUniversal(false, Asn1Tags.SetOf); + _nextObject = null; + return crls; + } + } - return (Asn1SetParser)_nextObject; - } - } + return null; + } + + public Asn1SetParser GetSignerInfos() + { + if (!_certsCalled || !_crlsCalled) + throw new IOException("GetCerts() and/or GetCrls() has not been called."); + + if (_nextObject == null) + { + _nextObject = _seq.ReadObject(); + } + + return (Asn1SetParser)_nextObject; + } + } } |