From 3eb93b423abeefbdc03f0ecc38751d76428ba23e Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Tue, 4 Jun 2019 16:55:26 +0700 Subject: Refactoring --- crypto/src/asn1/isismtt/x509/AdmissionSyntax.cs | 11 +++---- crypto/src/asn1/isismtt/x509/Admissions.cs | 20 +++--------- crypto/src/asn1/isismtt/x509/NamingAuthority.cs | 18 +++++------ crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs | 36 +++++++++++----------- crypto/src/asn1/isismtt/x509/ProfessionInfo.cs | 37 +++++++++-------------- 5 files changed, 49 insertions(+), 73 deletions(-) (limited to 'crypto/src/asn1/isismtt') diff --git a/crypto/src/asn1/isismtt/x509/AdmissionSyntax.cs b/crypto/src/asn1/isismtt/x509/AdmissionSyntax.cs index 4b6264ae0..a45075ee4 100644 --- a/crypto/src/asn1/isismtt/x509/AdmissionSyntax.cs +++ b/crypto/src/asn1/isismtt/x509/AdmissionSyntax.cs @@ -243,13 +243,10 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector vec = new Asn1EncodableVector(); - if (admissionAuthority != null) - { - vec.Add(admissionAuthority); - } - vec.Add(contentsOfAdmissions); - return new DerSequence(vec); + Asn1EncodableVector v = new Asn1EncodableVector(); + v.AddOptional(admissionAuthority); + v.Add(contentsOfAdmissions); + return new DerSequence(v); } /** diff --git a/crypto/src/asn1/isismtt/x509/Admissions.cs b/crypto/src/asn1/isismtt/x509/Admissions.cs index e914db0b5..2aa6764bb 100644 --- a/crypto/src/asn1/isismtt/x509/Admissions.cs +++ b/crypto/src/asn1/isismtt/x509/Admissions.cs @@ -167,21 +167,11 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector vec = new Asn1EncodableVector(); - - if (admissionAuthority != null) - { - vec.Add(new DerTaggedObject(true, 0, admissionAuthority)); - } - - if (namingAuthority != null) - { - vec.Add(new DerTaggedObject(true, 1, namingAuthority)); - } - - vec.Add(professionInfos); - - return new DerSequence(vec); + Asn1EncodableVector v = new Asn1EncodableVector(); + v.AddOptionalTagged(true, 0, admissionAuthority); + v.AddOptionalTagged(true, 1, namingAuthority); + v.Add(professionInfos); + return new DerSequence(v); } } } diff --git a/crypto/src/asn1/isismtt/x509/NamingAuthority.cs b/crypto/src/asn1/isismtt/x509/NamingAuthority.cs index 35539f488..543dcecc7 100644 --- a/crypto/src/asn1/isismtt/x509/NamingAuthority.cs +++ b/crypto/src/asn1/isismtt/x509/NamingAuthority.cs @@ -196,20 +196,16 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector vec = new Asn1EncodableVector(); - if (namingAuthorityID != null) - { - vec.Add(namingAuthorityID); - } + Asn1EncodableVector v = new Asn1EncodableVector(); + v.AddOptional(namingAuthorityID); + if (namingAuthorityUrl != null) { - vec.Add(new DerIA5String(namingAuthorityUrl, true)); + v.Add(new DerIA5String(namingAuthorityUrl, true)); } - if (namingAuthorityText != null) - { - vec.Add(namingAuthorityText); - } - return new DerSequence(vec); + + v.AddOptional(namingAuthorityText); + return new DerSequence(v); } } } diff --git a/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs b/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs index f42364699..60d3a88e8 100644 --- a/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs +++ b/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs @@ -209,25 +209,25 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector vec = new Asn1EncodableVector(); - if (country != null) - { - vec.Add(new DerTaggedObject(true, 1, new DerPrintableString(country, true))); - } - if (typeOfSubstitution != null) - { - vec.Add(new DerTaggedObject(true, 2, typeOfSubstitution)); - } - if (thirdPerson != null) - { - vec.Add(new DerTaggedObject(true, 3, thirdPerson)); - } - else - { - vec.Add(new DerTaggedObject(true, 3, certRef)); - } + Asn1EncodableVector v = new Asn1EncodableVector(); + + if (country != null) + { + v.Add(new DerTaggedObject(true, 1, new DerPrintableString(country, true))); + } + + v.AddOptionalTagged(true, 2, typeOfSubstitution); + + if (thirdPerson != null) + { + v.Add(new DerTaggedObject(true, 3, thirdPerson)); + } + else + { + v.Add(new DerTaggedObject(true, 3, certRef)); + } - return new DerSequence(vec); + return new DerSequence(v); } } } diff --git a/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs b/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs index 671a465af..b65757c09 100644 --- a/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs +++ b/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs @@ -302,28 +302,21 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 * * @return an Asn1Object */ - public override Asn1Object ToAsn1Object() - { - Asn1EncodableVector vec = new Asn1EncodableVector(); - if (namingAuthority != null) - { - vec.Add(new DerTaggedObject(true, 0, namingAuthority)); - } - vec.Add(professionItems); - if (professionOids != null) - { - vec.Add(professionOids); - } - if (registrationNumber != null) - { - vec.Add(new DerPrintableString(registrationNumber, true)); - } - if (addProfessionInfo != null) - { - vec.Add(addProfessionInfo); - } - return new DerSequence(vec); - } + public override Asn1Object ToAsn1Object() + { + Asn1EncodableVector v = new Asn1EncodableVector(); + v.AddOptionalTagged(true, 0, namingAuthority); + v.Add(professionItems); + v.AddOptional(professionOids); + + if (registrationNumber != null) + { + v.Add(new DerPrintableString(registrationNumber, true)); + } + + v.AddOptional(addProfessionInfo); + return new DerSequence(v); + } /** * @return Returns the addProfessionInfo. -- cgit 1.4.1