diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-27 21:11:59 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-27 21:11:59 +0700 |
commit | 35cfd51633bbbbc92c2c17c76646e9a9dc945b11 (patch) | |
tree | 563cda15bf08c63de832198be2b9e0263bae5e60 /crypto/src/asn1/isismtt | |
parent | Split up fast/slow tests (diff) | |
download | BouncyCastle.NET-ed25519-35cfd51633bbbbc92c2c17c76646e9a9dc945b11.tar.xz |
Generics migration in Asn1
Diffstat (limited to 'crypto/src/asn1/isismtt')
-rw-r--r-- | crypto/src/asn1/isismtt/x509/Admissions.cs | 59 | ||||
-rw-r--r-- | crypto/src/asn1/isismtt/x509/NamingAuthority.cs | 39 | ||||
-rw-r--r-- | crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs | 55 | ||||
-rw-r--r-- | crypto/src/asn1/isismtt/x509/ProfessionInfo.cs | 54 | ||||
-rw-r--r-- | crypto/src/asn1/isismtt/x509/Restriction.cs | 9 |
5 files changed, 91 insertions, 125 deletions
diff --git a/crypto/src/asn1/isismtt/x509/Admissions.cs b/crypto/src/asn1/isismtt/x509/Admissions.cs index 2aa6764bb..42ebceb1c 100644 --- a/crypto/src/asn1/isismtt/x509/Admissions.cs +++ b/crypto/src/asn1/isismtt/x509/Admissions.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Utilities; @@ -30,18 +29,13 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 private readonly NamingAuthority namingAuthority; private readonly Asn1Sequence professionInfos; - public static Admissions GetInstance( - object obj) + public static Admissions GetInstance(object obj) { if (obj == null || obj is Admissions) - { - return (Admissions) obj; - } + return (Admissions)obj; - if (obj is Asn1Sequence) - { - return new Admissions((Asn1Sequence) obj); - } + if (obj is Asn1Sequence seq) + return new Admissions(seq); throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj"); } @@ -62,44 +56,43 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 * * @param seq The ASN.1 sequence. */ - private Admissions( - Asn1Sequence seq) + private Admissions(Asn1Sequence seq) { if (seq.Count > 3) throw new ArgumentException("Bad sequence size: " + seq.Count); - IEnumerator e = seq.GetEnumerator(); + var e = seq.GetEnumerator(); e.MoveNext(); - Asn1Encodable o = (Asn1Encodable) e.Current; - if (o is Asn1TaggedObject) + Asn1Encodable o = e.Current; + if (o is Asn1TaggedObject tagged1) { - switch (((Asn1TaggedObject)o).TagNo) + switch (tagged1.TagNo) { - case 0: - admissionAuthority = GeneralName.GetInstance((Asn1TaggedObject)o, true); - break; - case 1: - namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true); - break; - default: - throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo); + case 0: + admissionAuthority = GeneralName.GetInstance((Asn1TaggedObject)o, true); + break; + case 1: + namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true); + break; + default: + throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo); } e.MoveNext(); - o = (Asn1Encodable) e.Current; + o = e.Current; } - if (o is Asn1TaggedObject) + if (o is Asn1TaggedObject tagged2) { - switch (((Asn1TaggedObject)o).TagNo) + switch (tagged2.TagNo) { - case 1: - namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true); - break; - default: - throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo); + case 1: + namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true); + break; + default: + throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo); } e.MoveNext(); - o = (Asn1Encodable) e.Current; + o = e.Current; } professionInfos = Asn1Sequence.GetInstance(o); if (e.MoveNext()) diff --git a/crypto/src/asn1/isismtt/x509/NamingAuthority.cs b/crypto/src/asn1/isismtt/x509/NamingAuthority.cs index 543dcecc7..78ef25654 100644 --- a/crypto/src/asn1/isismtt/x509/NamingAuthority.cs +++ b/crypto/src/asn1/isismtt/x509/NamingAuthority.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using Org.BouncyCastle.Asn1.X500; using Org.BouncyCastle.Utilities; @@ -37,25 +36,18 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 private readonly string namingAuthorityUrl; private readonly DirectoryString namingAuthorityText; - public static NamingAuthority GetInstance( - object obj) + public static NamingAuthority GetInstance(object obj) { if (obj == null || obj is NamingAuthority) - { return (NamingAuthority) obj; - } - if (obj is Asn1Sequence) - { - return new NamingAuthority((Asn1Sequence) obj); - } + if (obj is Asn1Sequence seq) + return new NamingAuthority(seq); throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj"); } - public static NamingAuthority GetInstance( - Asn1TaggedObject obj, - bool isExplicit) + public static NamingAuthority GetInstance(Asn1TaggedObject obj, bool isExplicit) { return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit)); } @@ -75,24 +67,23 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 * * @param seq The ASN.1 sequence. */ - private NamingAuthority( - Asn1Sequence seq) + private NamingAuthority(Asn1Sequence seq) { if (seq.Count > 3) throw new ArgumentException("Bad sequence size: " + seq.Count); - IEnumerator e = seq.GetEnumerator(); + var e = seq.GetEnumerator(); if (e.MoveNext()) { - Asn1Encodable o = (Asn1Encodable) e.Current; - if (o is DerObjectIdentifier) + Asn1Encodable o = e.Current; + if (o is DerObjectIdentifier oid) { - namingAuthorityID = (DerObjectIdentifier) o; + namingAuthorityID = oid; } - else if (o is DerIA5String) + else if (o is DerIA5String ia5) { - namingAuthorityUrl = DerIA5String.GetInstance(o).GetString(); + namingAuthorityUrl = ia5.GetString(); } else if (o is IAsn1String) { @@ -106,10 +97,10 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 if (e.MoveNext()) { - Asn1Encodable o = (Asn1Encodable) e.Current; - if (o is DerIA5String) + Asn1Encodable o = e.Current; + if (o is DerIA5String ia5) { - namingAuthorityUrl = DerIA5String.GetInstance(o).GetString(); + namingAuthorityUrl = ia5.GetString(); } else if (o is IAsn1String) { @@ -123,7 +114,7 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 if (e.MoveNext()) { - Asn1Encodable o = (Asn1Encodable) e.Current; + Asn1Encodable o = e.Current; if (o is IAsn1String) { namingAuthorityText = DirectoryString.GetInstance(o); diff --git a/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs b/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs index 60d3a88e8..23be2d388 100644 --- a/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs +++ b/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using Org.BouncyCastle.Asn1.X500; using Org.BouncyCastle.Asn1.X509; @@ -49,18 +48,13 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 private readonly GeneralName thirdPerson; private readonly IssuerSerial certRef; - public static ProcurationSyntax GetInstance( - object obj) + public static ProcurationSyntax GetInstance(object obj) { if (obj == null || obj is ProcurationSyntax) - { return (ProcurationSyntax) obj; - } - if (obj is Asn1Sequence) - { - return new ProcurationSyntax((Asn1Sequence) obj); - } + if (obj is Asn1Sequence seq) + return new ProcurationSyntax(seq); throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj"); } @@ -86,38 +80,37 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 * * @param seq The ASN.1 sequence. */ - private ProcurationSyntax( - Asn1Sequence seq) + private ProcurationSyntax(Asn1Sequence seq) { if (seq.Count < 1 || seq.Count > 3) throw new ArgumentException("Bad sequence size: " + seq.Count); - IEnumerator e = seq.GetEnumerator(); + var e = seq.GetEnumerator(); while (e.MoveNext()) { Asn1TaggedObject o = Asn1TaggedObject.GetInstance(e.Current); switch (o.TagNo) { - case 1: - country = DerPrintableString.GetInstance(o, true).GetString(); - break; - case 2: - typeOfSubstitution = DirectoryString.GetInstance(o, true); - break; - case 3: - Asn1Object signingFor = o.GetObject(); - if (signingFor is Asn1TaggedObject) - { - thirdPerson = GeneralName.GetInstance(signingFor); - } - else - { - certRef = IssuerSerial.GetInstance(signingFor); - } - break; - default: - throw new ArgumentException("Bad tag number: " + o.TagNo); + case 1: + country = DerPrintableString.GetInstance(o, true).GetString(); + break; + case 2: + typeOfSubstitution = DirectoryString.GetInstance(o, true); + break; + case 3: + Asn1Object signingFor = o.GetObject(); + if (signingFor is Asn1TaggedObject) + { + thirdPerson = GeneralName.GetInstance(signingFor); + } + else + { + certRef = IssuerSerial.GetInstance(signingFor); + } + break; + default: + throw new ArgumentException("Bad tag number: " + o.TagNo); } } } diff --git a/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs b/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs index b65757c09..daa76730d 100644 --- a/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs +++ b/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using Org.BouncyCastle.Asn1.X500; using Org.BouncyCastle.Utilities; @@ -145,18 +144,13 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 private readonly string registrationNumber; private readonly Asn1OctetString addProfessionInfo; - public static ProfessionInfo GetInstance( - object obj) + public static ProfessionInfo GetInstance(object obj) { if (obj == null || obj is ProfessionInfo) - { return (ProfessionInfo) obj; - } - if (obj is Asn1Sequence) - { - return new ProfessionInfo((Asn1Sequence) obj); - } + if (obj is Asn1Sequence seq) + return new ProfessionInfo(seq); throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj"); } @@ -178,44 +172,42 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 * * @param seq The ASN.1 sequence. */ - private ProfessionInfo( - Asn1Sequence seq) + private ProfessionInfo(Asn1Sequence seq) { if (seq.Count > 5) throw new ArgumentException("Bad sequence size: " + seq.Count); - IEnumerator e = seq.GetEnumerator(); + var e = seq.GetEnumerator(); e.MoveNext(); - Asn1Encodable o = (Asn1Encodable) e.Current; + Asn1Encodable o = e.Current; - if (o is Asn1TaggedObject) + if (o is Asn1TaggedObject ato) { - Asn1TaggedObject ato = (Asn1TaggedObject) o; if (ato.TagNo != 0) throw new ArgumentException("Bad tag number: " + ato.TagNo); namingAuthority = NamingAuthority.GetInstance(ato, true); e.MoveNext(); - o = (Asn1Encodable) e.Current; + o = e.Current; } professionItems = Asn1Sequence.GetInstance(o); if (e.MoveNext()) { - o = (Asn1Encodable) e.Current; - if (o is Asn1Sequence) + o = e.Current; + if (o is Asn1Sequence sequence) { - professionOids = Asn1Sequence.GetInstance(o); + professionOids = sequence; } - else if (o is DerPrintableString) + else if (o is DerPrintableString printable) { - registrationNumber = DerPrintableString.GetInstance(o).GetString(); + registrationNumber = printable.GetString(); } - else if (o is Asn1OctetString) + else if (o is Asn1OctetString octets) { - addProfessionInfo = Asn1OctetString.GetInstance(o); + addProfessionInfo = octets; } else { @@ -225,14 +217,14 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 if (e.MoveNext()) { - o = (Asn1Encodable) e.Current; - if (o is DerPrintableString) + o = e.Current; + if (o is DerPrintableString printable) { - registrationNumber = DerPrintableString.GetInstance(o).GetString(); + registrationNumber = printable.GetString(); } - else if (o is DerOctetString) + else if (o is Asn1OctetString octets) { - addProfessionInfo = (DerOctetString) o; + addProfessionInfo = octets; } else { @@ -242,10 +234,10 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 if (e.MoveNext()) { - o = (Asn1Encodable) e.Current; - if (o is DerOctetString) + o = e.Current; + if (o is Asn1OctetString octets) { - addProfessionInfo = (DerOctetString) o; + addProfessionInfo = octets; } else { diff --git a/crypto/src/asn1/isismtt/x509/Restriction.cs b/crypto/src/asn1/isismtt/x509/Restriction.cs index 75df25201..4334d331d 100644 --- a/crypto/src/asn1/isismtt/x509/Restriction.cs +++ b/crypto/src/asn1/isismtt/x509/Restriction.cs @@ -17,8 +17,7 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 { private readonly DirectoryString restriction; - public static Restriction GetInstance( - object obj) + public static Restriction GetInstance(object obj) { if (obj is Restriction) return (Restriction) obj; @@ -40,8 +39,7 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 * * @param restriction A IAsn1String. */ - private Restriction( - DirectoryString restriction) + private Restriction(DirectoryString restriction) { this.restriction = restriction; } @@ -51,8 +49,7 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 * * @param restriction The description of the restriction. */ - public Restriction( - string restriction) + public Restriction(string restriction) { this.restriction = new DirectoryString(restriction); } |