From daec40507f75c8bbe80f54e25338d31a2b411e39 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 12 Jun 2024 18:09:06 +0700 Subject: DerInteger constants for small values --- crypto/src/asn1/DerInteger.cs | 7 +++++++ crypto/src/asn1/cms/AuthEnvelopedData.cs | 2 +- crypto/src/asn1/cms/CompressedData.cs | 2 +- crypto/src/asn1/cms/KEKRecipientInfo.cs | 2 +- crypto/src/asn1/cms/KemRecipientInfo.cs | 2 +- crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs | 2 +- crypto/src/asn1/cms/KeyTransRecipientInfo.cs | 4 ++-- crypto/src/asn1/cms/PasswordRecipientInfo.cs | 4 ++-- crypto/src/asn1/cms/RecipientInfo.cs | 2 +- crypto/src/asn1/cms/SignedData.cs | 8 ++++---- crypto/src/asn1/cms/TimeStampedData.cs | 2 +- crypto/src/asn1/crmf/PKIPublicationInfo.cs | 4 ++-- crypto/src/asn1/icao/CscaMasterList.cs | 2 +- crypto/src/asn1/icao/LDSSecurityObject.cs | 4 ++-- crypto/src/asn1/ocsp/ResponseData.cs | 2 +- crypto/src/asn1/ocsp/TBSRequest.cs | 2 +- crypto/src/asn1/pkcs/CertificationRequestInfo.cs | 2 +- crypto/src/asn1/pkcs/EncryptedData.cs | 2 +- crypto/src/asn1/pkcs/Pfx.cs | 2 +- crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs | 2 +- crypto/src/asn1/pkcs/RSASSAPSSparams.cs | 2 +- crypto/src/asn1/sec/ECPrivateKeyStructure.cs | 2 +- crypto/src/asn1/tsp/EvidenceRecord.cs | 4 ++-- crypto/src/asn1/tsp/TSTInfo.cs | 2 +- crypto/src/asn1/tsp/TimeStampReq.cs | 2 +- crypto/src/asn1/x509/AttributeCertificateInfo.cs | 2 +- crypto/src/asn1/x509/TBSCertList.cs | 2 +- crypto/src/asn1/x509/TBSCertificateStructure.cs | 2 +- crypto/src/asn1/x509/V1TBSCertificateGenerator.cs | 2 +- .../src/asn1/x509/V2AttributeCertificateInfoGenerator.cs | 2 +- crypto/src/asn1/x509/V2TBSCertListGenerator.cs | 2 +- crypto/src/asn1/x509/V3TBSCertificateGenerator.cs | 2 +- crypto/src/cms/CMSCompressedDataStreamGenerator.cs | 2 +- crypto/src/cms/CMSSignedDataStreamGenerator.cs | 10 +++++----- crypto/src/crypto/operators/Asn1Signature.cs | 2 +- crypto/src/crypto/util/OpenSshPrivateKeyUtilities.cs | 2 +- crypto/src/openssl/MiscPemGenerator.cs | 2 +- .../utilities/DefaultSignatureAlgorithmFinder.cs | 2 +- crypto/src/pkcs/Pkcs10CertificationRequest.cs | 2 +- crypto/src/pkix/PkixCertPath.cs | 2 +- crypto/src/pqc/crypto/utils/PqcPrivateKeyInfoFactory.cs | 2 +- crypto/src/security/SignerUtilities.cs | 2 +- crypto/src/tls/crypto/impl/RsaUtilities.cs | 2 +- crypto/src/x509/X509Utilities.cs | 2 +- crypto/test/src/asn1/test/GenerationTest.cs | 16 ++++++++-------- crypto/test/src/asn1/test/OctetStringTest.cs | 2 +- crypto/test/src/asn1/test/OtherCertIDUnitTest.cs | 2 +- crypto/test/src/asn1/test/ProcurationSyntaxUnitTest.cs | 2 +- crypto/test/src/asn1/test/TagTest.cs | 2 +- crypto/test/src/tsp/test/GenTimeAccuracyTest.cs | 8 ++++---- 50 files changed, 78 insertions(+), 71 deletions(-) diff --git a/crypto/src/asn1/DerInteger.cs b/crypto/src/asn1/DerInteger.cs index 81d6437c7..d68a71e9d 100644 --- a/crypto/src/asn1/DerInteger.cs +++ b/crypto/src/asn1/DerInteger.cs @@ -23,6 +23,13 @@ namespace Org.BouncyCastle.Asn1 public const string AllowUnsafeProperty = "Org.BouncyCastle.Asn1.AllowUnsafeInteger"; + public static readonly DerInteger Zero = new DerInteger(0); + public static readonly DerInteger One = new DerInteger(1); + public static readonly DerInteger Two = new DerInteger(2); + public static readonly DerInteger Three = new DerInteger(3); + public static readonly DerInteger Four = new DerInteger(4); + public static readonly DerInteger Five = new DerInteger(5); + internal static bool AllowUnsafe() { string allowUnsafeValue = Platform.GetEnvironmentVariable(AllowUnsafeProperty); diff --git a/crypto/src/asn1/cms/AuthEnvelopedData.cs b/crypto/src/asn1/cms/AuthEnvelopedData.cs index bbcde8180..ae0380b64 100644 --- a/crypto/src/asn1/cms/AuthEnvelopedData.cs +++ b/crypto/src/asn1/cms/AuthEnvelopedData.cs @@ -36,7 +36,7 @@ namespace Org.BouncyCastle.Asn1.Cms Asn1Set unauthAttrs) { // "It MUST be set to 0." - this.version = new DerInteger(0); + this.version = DerInteger.Zero; this.originatorInfo = originatorInfo; diff --git a/crypto/src/asn1/cms/CompressedData.cs b/crypto/src/asn1/cms/CompressedData.cs index 4b326247e..5ae71708d 100644 --- a/crypto/src/asn1/cms/CompressedData.cs +++ b/crypto/src/asn1/cms/CompressedData.cs @@ -43,7 +43,7 @@ namespace Org.BouncyCastle.Asn1.Cms AlgorithmIdentifier compressionAlgorithm, ContentInfo encapContentInfo) { - this.version = new DerInteger(0); + this.version = DerInteger.Zero; this.compressionAlgorithm = compressionAlgorithm; this.encapContentInfo = encapContentInfo; } diff --git a/crypto/src/asn1/cms/KEKRecipientInfo.cs b/crypto/src/asn1/cms/KEKRecipientInfo.cs index 76ce9c643..b1b85953e 100644 --- a/crypto/src/asn1/cms/KEKRecipientInfo.cs +++ b/crypto/src/asn1/cms/KEKRecipientInfo.cs @@ -35,7 +35,7 @@ namespace Org.BouncyCastle.Asn1.Cms AlgorithmIdentifier keyEncryptionAlgorithm, Asn1OctetString encryptedKey) { - this.version = new DerInteger(4); + this.version = DerInteger.Four; this.kekID = kekID; this.keyEncryptionAlgorithm = keyEncryptionAlgorithm; this.encryptedKey = encryptedKey; diff --git a/crypto/src/asn1/cms/KemRecipientInfo.cs b/crypto/src/asn1/cms/KemRecipientInfo.cs index c7251fbb1..4f771784a 100644 --- a/crypto/src/asn1/cms/KemRecipientInfo.cs +++ b/crypto/src/asn1/cms/KemRecipientInfo.cs @@ -33,7 +33,7 @@ namespace Org.BouncyCastle.Asn1.Cms return new KemRecipientInfo(Asn1Sequence.GetInstance(taggedObject, declaredExplicit)); } - private static readonly DerInteger V1 = new DerInteger(0); + private static readonly DerInteger V1 = DerInteger.Zero; private readonly DerInteger m_cmsVersion; private readonly RecipientIdentifier m_rid; diff --git a/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs b/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs index 63eebcea3..345a45029 100644 --- a/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs +++ b/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs @@ -37,7 +37,7 @@ namespace Org.BouncyCastle.Asn1.Cms AlgorithmIdentifier keyEncryptionAlgorithm, Asn1Sequence recipientEncryptedKeys) { - this.version = new DerInteger(3); + this.version = DerInteger.Three; this.originator = originator; this.ukm = ukm; this.keyEncryptionAlgorithm = keyEncryptionAlgorithm; diff --git a/crypto/src/asn1/cms/KeyTransRecipientInfo.cs b/crypto/src/asn1/cms/KeyTransRecipientInfo.cs index 6981e87f9..1d9825b02 100644 --- a/crypto/src/asn1/cms/KeyTransRecipientInfo.cs +++ b/crypto/src/asn1/cms/KeyTransRecipientInfo.cs @@ -38,11 +38,11 @@ namespace Org.BouncyCastle.Asn1.Cms { if (rid.ToAsn1Object() is Asn1TaggedObject) { - this.version = new DerInteger(2); + this.version = DerInteger.Two; } else { - this.version = new DerInteger(0); + this.version = DerInteger.Zero; } this.rid = rid; diff --git a/crypto/src/asn1/cms/PasswordRecipientInfo.cs b/crypto/src/asn1/cms/PasswordRecipientInfo.cs index 67ff01cf8..5fac434ca 100644 --- a/crypto/src/asn1/cms/PasswordRecipientInfo.cs +++ b/crypto/src/asn1/cms/PasswordRecipientInfo.cs @@ -34,7 +34,7 @@ namespace Org.BouncyCastle.Asn1.Cms AlgorithmIdentifier keyEncryptionAlgorithm, Asn1OctetString encryptedKey) { - this.version = new DerInteger(0); + this.version = DerInteger.Zero; this.keyEncryptionAlgorithm = keyEncryptionAlgorithm; this.encryptedKey = encryptedKey; } @@ -44,7 +44,7 @@ namespace Org.BouncyCastle.Asn1.Cms AlgorithmIdentifier keyEncryptionAlgorithm, Asn1OctetString encryptedKey) { - this.version = new DerInteger(0); + this.version = DerInteger.Zero; this.keyDerivationAlgorithm = keyDerivationAlgorithm; this.keyEncryptionAlgorithm = keyEncryptionAlgorithm; this.encryptedKey = encryptedKey; diff --git a/crypto/src/asn1/cms/RecipientInfo.cs b/crypto/src/asn1/cms/RecipientInfo.cs index ff93258b6..85bd7e585 100644 --- a/crypto/src/asn1/cms/RecipientInfo.cs +++ b/crypto/src/asn1/cms/RecipientInfo.cs @@ -82,7 +82,7 @@ namespace Org.BouncyCastle.Asn1.Cms case 3: return PasswordRecipientInfo.GetInstance(o, false).Version; case 4: - return new DerInteger(0); // no syntax version for OtherRecipientInfo + return DerInteger.Zero; // no syntax version for OtherRecipientInfo default: throw new InvalidOperationException("unknown tag"); } diff --git a/crypto/src/asn1/cms/SignedData.cs b/crypto/src/asn1/cms/SignedData.cs index 858715ad6..380305c32 100644 --- a/crypto/src/asn1/cms/SignedData.cs +++ b/crypto/src/asn1/cms/SignedData.cs @@ -22,10 +22,10 @@ namespace Org.BouncyCastle.Asn1.Cms return new SignedData(Asn1Sequence.GetInstance(taggedObject, declaredExplicit)); } - private static readonly DerInteger Version1 = new DerInteger(1); - private static readonly DerInteger Version3 = new DerInteger(3); - private static readonly DerInteger Version4 = new DerInteger(4); - private static readonly DerInteger Version5 = new DerInteger(5); + private static readonly DerInteger Version1 = DerInteger.One; + private static readonly DerInteger Version3 = DerInteger.Three; + private static readonly DerInteger Version4 = DerInteger.Four; + private static readonly DerInteger Version5 = DerInteger.Five; private readonly DerInteger version; private readonly Asn1Set digestAlgorithms; diff --git a/crypto/src/asn1/cms/TimeStampedData.cs b/crypto/src/asn1/cms/TimeStampedData.cs index 4d9136ea0..cae290609 100644 --- a/crypto/src/asn1/cms/TimeStampedData.cs +++ b/crypto/src/asn1/cms/TimeStampedData.cs @@ -28,7 +28,7 @@ namespace Org.BouncyCastle.Asn1.Cms public TimeStampedData(DerIA5String dataUri, MetaData metaData, Asn1OctetString content, Evidence temporalEvidence) { - this.version = new DerInteger(1); + this.version = DerInteger.One; this.dataUri = dataUri; this.metaData = metaData; this.content = content; diff --git a/crypto/src/asn1/crmf/PKIPublicationInfo.cs b/crypto/src/asn1/crmf/PKIPublicationInfo.cs index 5cc1df013..3c12dffa5 100644 --- a/crypto/src/asn1/crmf/PKIPublicationInfo.cs +++ b/crypto/src/asn1/crmf/PKIPublicationInfo.cs @@ -19,8 +19,8 @@ namespace Org.BouncyCastle.Asn1.Crmf public class PkiPublicationInfo : Asn1Encodable { - public static readonly DerInteger DontPublish = new DerInteger(0); - public static readonly DerInteger PleasePublish = new DerInteger(1); + public static readonly DerInteger DontPublish = DerInteger.Zero; + public static readonly DerInteger PleasePublish = DerInteger.One; public static PkiPublicationInfo GetInstance(object obj) { diff --git a/crypto/src/asn1/icao/CscaMasterList.cs b/crypto/src/asn1/icao/CscaMasterList.cs index 4c6ea827c..a54432f8f 100644 --- a/crypto/src/asn1/icao/CscaMasterList.cs +++ b/crypto/src/asn1/icao/CscaMasterList.cs @@ -48,7 +48,7 @@ namespace Org.BouncyCastle.Asn1.Icao public CscaMasterList(X509CertificateStructure[] certStructs) { - m_version = new DerInteger(0); + m_version = DerInteger.Zero; m_certList = CopyCertList(certStructs); } diff --git a/crypto/src/asn1/icao/LDSSecurityObject.cs b/crypto/src/asn1/icao/LDSSecurityObject.cs index 9fcb4e5b9..59a3d0550 100644 --- a/crypto/src/asn1/icao/LDSSecurityObject.cs +++ b/crypto/src/asn1/icao/LDSSecurityObject.cs @@ -64,7 +64,7 @@ namespace Org.BouncyCastle.Asn1.Icao public LdsSecurityObject(AlgorithmIdentifier digestAlgorithmIdentifier, DataGroupHash[] datagroupHash) { - m_version = new DerInteger(0); + m_version = DerInteger.Zero; m_hashAlgorithm = digestAlgorithmIdentifier ?? throw new ArgumentNullException(nameof(digestAlgorithmIdentifier)); ; m_datagroupHashValues = datagroupHash ?? throw new ArgumentNullException(nameof(datagroupHash)); m_ldsVersionInfo = null; @@ -75,7 +75,7 @@ namespace Org.BouncyCastle.Asn1.Icao public LdsSecurityObject(AlgorithmIdentifier digestAlgorithmIdentifier, DataGroupHash[] datagroupHash, LdsVersionInfo versionInfo) { - m_version = new DerInteger(1); + m_version = DerInteger.One; m_hashAlgorithm = digestAlgorithmIdentifier ?? throw new ArgumentNullException(nameof(digestAlgorithmIdentifier)); ; m_datagroupHashValues = datagroupHash ?? throw new ArgumentNullException(nameof(datagroupHash)); m_ldsVersionInfo = versionInfo; diff --git a/crypto/src/asn1/ocsp/ResponseData.cs b/crypto/src/asn1/ocsp/ResponseData.cs index 08b80d673..81ea2d0d3 100644 --- a/crypto/src/asn1/ocsp/ResponseData.cs +++ b/crypto/src/asn1/ocsp/ResponseData.cs @@ -21,7 +21,7 @@ namespace Org.BouncyCastle.Asn1.Ocsp return new ResponseData(Asn1Sequence.GetInstance(obj, explicitly)); } - private static readonly DerInteger V1 = new DerInteger(0); + private static readonly DerInteger V1 = DerInteger.Zero; private readonly DerInteger m_version; private readonly bool m_versionPresent; diff --git a/crypto/src/asn1/ocsp/TBSRequest.cs b/crypto/src/asn1/ocsp/TBSRequest.cs index e041a9763..8f44464d1 100644 --- a/crypto/src/asn1/ocsp/TBSRequest.cs +++ b/crypto/src/asn1/ocsp/TBSRequest.cs @@ -21,7 +21,7 @@ namespace Org.BouncyCastle.Asn1.Ocsp return new TbsRequest(Asn1Sequence.GetInstance(obj, explicitly)); } - private static readonly DerInteger V1 = new DerInteger(0); + private static readonly DerInteger V1 = DerInteger.Zero; private readonly DerInteger m_version; private readonly bool m_versionPresent; diff --git a/crypto/src/asn1/pkcs/CertificationRequestInfo.cs b/crypto/src/asn1/pkcs/CertificationRequestInfo.cs index 795757533..196d9f4e5 100644 --- a/crypto/src/asn1/pkcs/CertificationRequestInfo.cs +++ b/crypto/src/asn1/pkcs/CertificationRequestInfo.cs @@ -25,7 +25,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs public class CertificationRequestInfo : Asn1Encodable { - internal DerInteger version = new DerInteger(0); + internal DerInteger version = DerInteger.Zero; internal X509Name subject; internal SubjectPublicKeyInfo subjectPKInfo; internal Asn1Set attributes; diff --git a/crypto/src/asn1/pkcs/EncryptedData.cs b/crypto/src/asn1/pkcs/EncryptedData.cs index fdee60405..f75975d5a 100644 --- a/crypto/src/asn1/pkcs/EncryptedData.cs +++ b/crypto/src/asn1/pkcs/EncryptedData.cs @@ -97,7 +97,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs public override Asn1Object ToAsn1Object() { - return new BerSequence(new DerInteger(0), data); + return new BerSequence(DerInteger.Zero, data); } } } diff --git a/crypto/src/asn1/pkcs/Pfx.cs b/crypto/src/asn1/pkcs/Pfx.cs index c1399e560..67d69a5ae 100644 --- a/crypto/src/asn1/pkcs/Pfx.cs +++ b/crypto/src/asn1/pkcs/Pfx.cs @@ -55,7 +55,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(new DerInteger(3), contentInfo); + Asn1EncodableVector v = new Asn1EncodableVector(DerInteger.Three, contentInfo); v.AddOptional(macData); return new BerSequence(v); } diff --git a/crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs b/crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs index c445df562..0e7911163 100644 --- a/crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs +++ b/crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs @@ -128,7 +128,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs public override Asn1Object ToAsn1Object() { return new DerSequence( - new DerInteger(0), // version + DerInteger.Zero, // version new DerInteger(Modulus), new DerInteger(PublicExponent), new DerInteger(PrivateExponent), diff --git a/crypto/src/asn1/pkcs/RSASSAPSSparams.cs b/crypto/src/asn1/pkcs/RSASSAPSSparams.cs index e5800993f..ead2faa73 100644 --- a/crypto/src/asn1/pkcs/RSASSAPSSparams.cs +++ b/crypto/src/asn1/pkcs/RSASSAPSSparams.cs @@ -17,7 +17,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs public readonly static AlgorithmIdentifier DefaultHashAlgorithm = new AlgorithmIdentifier(OiwObjectIdentifiers.IdSha1, DerNull.Instance); public readonly static AlgorithmIdentifier DefaultMaskGenFunction = new AlgorithmIdentifier(PkcsObjectIdentifiers.IdMgf1, DefaultHashAlgorithm); public readonly static DerInteger DefaultSaltLength = new DerInteger(20); - public readonly static DerInteger DefaultTrailerField = new DerInteger(1); + public readonly static DerInteger DefaultTrailerField = DerInteger.One; public static RsassaPssParameters GetInstance( object obj) diff --git a/crypto/src/asn1/sec/ECPrivateKeyStructure.cs b/crypto/src/asn1/sec/ECPrivateKeyStructure.cs index 89b87bf2b..298a0ba79 100644 --- a/crypto/src/asn1/sec/ECPrivateKeyStructure.cs +++ b/crypto/src/asn1/sec/ECPrivateKeyStructure.cs @@ -56,7 +56,7 @@ namespace Org.BouncyCastle.Asn1.Sec byte[] bytes = BigIntegers.AsUnsignedByteArray((orderBitLength + 7) / 8, key); Asn1EncodableVector v = new Asn1EncodableVector( - new DerInteger(1), + DerInteger.One, new DerOctetString(bytes)); v.AddOptionalTagged(true, 0, parameters); diff --git a/crypto/src/asn1/tsp/EvidenceRecord.cs b/crypto/src/asn1/tsp/EvidenceRecord.cs index 1be8a3998..9957b1050 100644 --- a/crypto/src/asn1/tsp/EvidenceRecord.cs +++ b/crypto/src/asn1/tsp/EvidenceRecord.cs @@ -112,7 +112,7 @@ namespace Org.BouncyCastle.Asn1.Tsp */ public EvidenceRecord(CryptoInfos cryptoInfos, EncryptionInfo encryptionInfo, ArchiveTimeStamp archiveTimeStamp) { - m_version = new DerInteger(1); + m_version = DerInteger.One; m_digestAlgorithms = new DerSequence(archiveTimeStamp.GetDigestAlgorithmIdentifier()); m_cryptoInfos = cryptoInfos; m_encryptionInfo = encryptionInfo; @@ -122,7 +122,7 @@ namespace Org.BouncyCastle.Asn1.Tsp public EvidenceRecord(AlgorithmIdentifier[] digestAlgorithms, CryptoInfos cryptoInfos, EncryptionInfo encryptionInfo, ArchiveTimeStampSequence archiveTimeStampSequence) { - m_version = new DerInteger(1); + m_version = DerInteger.One; m_digestAlgorithms = new DerSequence(digestAlgorithms); m_cryptoInfos = cryptoInfos; m_encryptionInfo = encryptionInfo; diff --git a/crypto/src/asn1/tsp/TSTInfo.cs b/crypto/src/asn1/tsp/TSTInfo.cs index 8aefe6159..80302975f 100644 --- a/crypto/src/asn1/tsp/TSTInfo.cs +++ b/crypto/src/asn1/tsp/TSTInfo.cs @@ -99,7 +99,7 @@ namespace Org.BouncyCastle.Asn1.Tsp Asn1GeneralizedTime genTime, Accuracy accuracy, DerBoolean ordering, DerInteger nonce, GeneralName tsa, X509Extensions extensions) { - m_version = new DerInteger(1); + m_version = DerInteger.One; m_tsaPolicyID = tsaPolicyId; m_messageImprint = messageImprint; m_serialNumber = serialNumber; diff --git a/crypto/src/asn1/tsp/TimeStampReq.cs b/crypto/src/asn1/tsp/TimeStampReq.cs index 6b3afd553..aa9621007 100644 --- a/crypto/src/asn1/tsp/TimeStampReq.cs +++ b/crypto/src/asn1/tsp/TimeStampReq.cs @@ -72,7 +72,7 @@ namespace Org.BouncyCastle.Asn1.Tsp DerBoolean certReq, X509Extensions extensions) { // default - m_version = new DerInteger(1); + m_version = DerInteger.One; m_messageImprint = messageImprint; m_tsaPolicy = tsaPolicy; diff --git a/crypto/src/asn1/x509/AttributeCertificateInfo.cs b/crypto/src/asn1/x509/AttributeCertificateInfo.cs index dde432ee6..d5e65323f 100644 --- a/crypto/src/asn1/x509/AttributeCertificateInfo.cs +++ b/crypto/src/asn1/x509/AttributeCertificateInfo.cs @@ -56,7 +56,7 @@ namespace Org.BouncyCastle.Asn1.X509 } else { - this.version = new DerInteger(0); + this.version = DerInteger.Zero; start = 0; } diff --git a/crypto/src/asn1/x509/TBSCertList.cs b/crypto/src/asn1/x509/TBSCertList.cs index fb8a9907c..8fa1e9822 100644 --- a/crypto/src/asn1/x509/TBSCertList.cs +++ b/crypto/src/asn1/x509/TBSCertList.cs @@ -174,7 +174,7 @@ namespace Org.BouncyCastle.Asn1.X509 } else { - version = new DerInteger(0); + version = DerInteger.Zero; } signature = AlgorithmIdentifier.GetInstance(seq[seqPos++]); diff --git a/crypto/src/asn1/x509/TBSCertificateStructure.cs b/crypto/src/asn1/x509/TBSCertificateStructure.cs index e41224f4a..e1daef3ff 100644 --- a/crypto/src/asn1/x509/TBSCertificateStructure.cs +++ b/crypto/src/asn1/x509/TBSCertificateStructure.cs @@ -69,7 +69,7 @@ namespace Org.BouncyCastle.Asn1.X509 else { seqStart = -1; // field 0 is missing! - version = new DerInteger(0); + version = DerInteger.Zero; } bool isV1 = false; diff --git a/crypto/src/asn1/x509/V1TBSCertificateGenerator.cs b/crypto/src/asn1/x509/V1TBSCertificateGenerator.cs index 7c191b263..5d9bdb72a 100644 --- a/crypto/src/asn1/x509/V1TBSCertificateGenerator.cs +++ b/crypto/src/asn1/x509/V1TBSCertificateGenerator.cs @@ -19,7 +19,7 @@ namespace Org.BouncyCastle.Asn1.X509 */ public class V1TbsCertificateGenerator { - internal DerTaggedObject version = new DerTaggedObject(0, new DerInteger(0)); + internal DerTaggedObject version = new DerTaggedObject(0, DerInteger.Zero); internal DerInteger serialNumber; internal AlgorithmIdentifier signature; internal X509Name issuer; diff --git a/crypto/src/asn1/x509/V2AttributeCertificateInfoGenerator.cs b/crypto/src/asn1/x509/V2AttributeCertificateInfoGenerator.cs index c78c966b0..86d396e30 100644 --- a/crypto/src/asn1/x509/V2AttributeCertificateInfoGenerator.cs +++ b/crypto/src/asn1/x509/V2AttributeCertificateInfoGenerator.cs @@ -36,7 +36,7 @@ namespace Org.BouncyCastle.Asn1.X509 public V2AttributeCertificateInfoGenerator() { - this.version = new DerInteger(1); + this.version = DerInteger.One; attributes = new Asn1EncodableVector(); } diff --git a/crypto/src/asn1/x509/V2TBSCertListGenerator.cs b/crypto/src/asn1/x509/V2TBSCertListGenerator.cs index d744ed664..fb568f21c 100644 --- a/crypto/src/asn1/x509/V2TBSCertListGenerator.cs +++ b/crypto/src/asn1/x509/V2TBSCertListGenerator.cs @@ -29,7 +29,7 @@ namespace Org.BouncyCastle.Asn1.X509 */ public class V2TbsCertListGenerator { - private DerInteger version = new DerInteger(1); + private DerInteger version = DerInteger.One; private AlgorithmIdentifier signature; private X509Name issuer; private Time thisUpdate, nextUpdate; diff --git a/crypto/src/asn1/x509/V3TBSCertificateGenerator.cs b/crypto/src/asn1/x509/V3TBSCertificateGenerator.cs index f58e4a7ab..465f17e57 100644 --- a/crypto/src/asn1/x509/V3TBSCertificateGenerator.cs +++ b/crypto/src/asn1/x509/V3TBSCertificateGenerator.cs @@ -22,7 +22,7 @@ namespace Org.BouncyCastle.Asn1.X509 */ public class V3TbsCertificateGenerator { - internal DerTaggedObject version = new DerTaggedObject(0, new DerInteger(2)); + internal DerTaggedObject version = new DerTaggedObject(0, DerInteger.Two); internal DerInteger serialNumber; internal AlgorithmIdentifier signature; internal X509Name issuer; diff --git a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs index f992a8269..0e320aa9f 100644 --- a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs +++ b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs @@ -75,7 +75,7 @@ namespace Org.BouncyCastle.Cms sGen.GetRawOutputStream(), 0, true); // CMSVersion - cGen.AddObject(new DerInteger(0)); + cGen.AddObject(DerInteger.Zero); // CompressionAlgorithmIdentifier cGen.AddObject(new AlgorithmIdentifier(CmsObjectIdentifiers.ZlibCompress)); diff --git a/crypto/src/cms/CMSSignedDataStreamGenerator.cs b/crypto/src/cms/CMSSignedDataStreamGenerator.cs index 81f6f5068..800093207 100644 --- a/crypto/src/cms/CMSSignedDataStreamGenerator.cs +++ b/crypto/src/cms/CMSSignedDataStreamGenerator.cs @@ -653,7 +653,7 @@ namespace Org.BouncyCastle.Cms if (otherCert) { - return new DerInteger(5); + return DerInteger.Five; } if (_crls != null) @@ -670,20 +670,20 @@ namespace Org.BouncyCastle.Cms if (otherCrl) { - return new DerInteger(5); + return DerInteger.Five; } if (attrCertV2Found) { - return new DerInteger(4); + return DerInteger.Four; } if (attrCertV1Found || !CmsObjectIdentifiers.Data.Equals(contentOid) || CheckForVersion3(_signers)) { - return new DerInteger(3); + return DerInteger.Three; } - return new DerInteger(1); + return DerInteger.One; } private bool CheckForVersion3(IList signerInfos) diff --git a/crypto/src/crypto/operators/Asn1Signature.cs b/crypto/src/crypto/operators/Asn1Signature.cs index cec99dccf..2f5729f3c 100644 --- a/crypto/src/crypto/operators/Asn1Signature.cs +++ b/crypto/src/crypto/operators/Asn1Signature.cs @@ -252,7 +252,7 @@ namespace Org.BouncyCastle.Crypto.Operators hashAlgId, new AlgorithmIdentifier(PkcsObjectIdentifiers.IdMgf1, hashAlgId), new DerInteger(saltSize), - new DerInteger(1)); + DerInteger.One); } internal static DerObjectIdentifier GetAlgorithmOid(string algorithmName) diff --git a/crypto/src/crypto/util/OpenSshPrivateKeyUtilities.cs b/crypto/src/crypto/util/OpenSshPrivateKeyUtilities.cs index aa934b1d6..164cea6e4 100644 --- a/crypto/src/crypto/util/OpenSshPrivateKeyUtilities.cs +++ b/crypto/src/crypto/util/OpenSshPrivateKeyUtilities.cs @@ -41,7 +41,7 @@ namespace Org.BouncyCastle.Crypto.Utilities Asn1EncodableVector vec = new Asn1EncodableVector { - new DerInteger(0), + DerInteger.Zero, new DerInteger(dsaparameters.P), new DerInteger(dsaparameters.Q), new DerInteger(dsaparameters.G) diff --git a/crypto/src/openssl/MiscPemGenerator.cs b/crypto/src/openssl/MiscPemGenerator.cs index 75d1e65b3..9ba7d5fd7 100644 --- a/crypto/src/openssl/MiscPemGenerator.cs +++ b/crypto/src/openssl/MiscPemGenerator.cs @@ -304,7 +304,7 @@ namespace Org.BouncyCastle.OpenSsl BigInteger y = p.G.ModPow(x, p.P); var sequence = new DerSequence( - new DerInteger(0), + DerInteger.Zero, new DerInteger(p.P), new DerInteger(p.Q), new DerInteger(p.G), diff --git a/crypto/src/operators/utilities/DefaultSignatureAlgorithmFinder.cs b/crypto/src/operators/utilities/DefaultSignatureAlgorithmFinder.cs index 0da904328..508894e48 100644 --- a/crypto/src/operators/utilities/DefaultSignatureAlgorithmFinder.cs +++ b/crypto/src/operators/utilities/DefaultSignatureAlgorithmFinder.cs @@ -501,7 +501,7 @@ namespace Org.BouncyCastle.Operators.Utilities hashAlgID, new AlgorithmIdentifier(PkcsObjectIdentifiers.IdMgf1, hashAlgID), new DerInteger(saltSize), - new DerInteger(1)); + DerInteger.One); } protected DefaultSignatureAlgorithmFinder() diff --git a/crypto/src/pkcs/Pkcs10CertificationRequest.cs b/crypto/src/pkcs/Pkcs10CertificationRequest.cs index 0534e0b25..ee24f42aa 100644 --- a/crypto/src/pkcs/Pkcs10CertificationRequest.cs +++ b/crypto/src/pkcs/Pkcs10CertificationRequest.cs @@ -218,7 +218,7 @@ namespace Org.BouncyCastle.Pkcs hashAlgId, new AlgorithmIdentifier(PkcsObjectIdentifiers.IdMgf1, hashAlgId), new DerInteger(saltSize), - new DerInteger(1)); + DerInteger.One); } protected Pkcs10CertificationRequest() diff --git a/crypto/src/pkix/PkixCertPath.cs b/crypto/src/pkix/PkixCertPath.cs index 4aec08f09..88c7bf24b 100644 --- a/crypto/src/pkix/PkixCertPath.cs +++ b/crypto/src/pkix/PkixCertPath.cs @@ -335,7 +335,7 @@ namespace Org.BouncyCastle.Pkix } SignedData sd = new SignedData( - new DerInteger(1), + DerInteger.One, new DerSet(), encInfo, DerSet.FromVector(v), diff --git a/crypto/src/pqc/crypto/utils/PqcPrivateKeyInfoFactory.cs b/crypto/src/pqc/crypto/utils/PqcPrivateKeyInfoFactory.cs index 235478258..cc8882890 100644 --- a/crypto/src/pqc/crypto/utils/PqcPrivateKeyInfoFactory.cs +++ b/crypto/src/pqc/crypto/utils/PqcPrivateKeyInfoFactory.cs @@ -114,7 +114,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Utilities if (privateKey is FalconPrivateKeyParameters falconPrivateKeyParameters) { Asn1EncodableVector v = new Asn1EncodableVector(4); - v.Add(new DerInteger(1)); + v.Add(DerInteger.One); v.Add(new DerOctetString(falconPrivateKeyParameters.GetSpolyLittleF())); v.Add(new DerOctetString(falconPrivateKeyParameters.GetG())); v.Add(new DerOctetString(falconPrivateKeyParameters.GetSpolyBigF())); diff --git a/crypto/src/security/SignerUtilities.cs b/crypto/src/security/SignerUtilities.cs index e2a98343c..980ad52e8 100644 --- a/crypto/src/security/SignerUtilities.cs +++ b/crypto/src/security/SignerUtilities.cs @@ -592,7 +592,7 @@ namespace Org.BouncyCastle.Security int saltLen = DigestUtilities.GetDigest(digestName).GetDigestSize(); return new RsassaPssParameters(hashAlgorithm, maskGenAlgorithm, - new DerInteger(saltLen), new DerInteger(1)); + new DerInteger(saltLen), DerInteger.One); } // TODO[api] Change parameter name to 'oid' diff --git a/crypto/src/tls/crypto/impl/RsaUtilities.cs b/crypto/src/tls/crypto/impl/RsaUtilities.cs index 83782a2ac..fc6d8f8a6 100644 --- a/crypto/src/tls/crypto/impl/RsaUtilities.cs +++ b/crypto/src/tls/crypto/impl/RsaUtilities.cs @@ -38,7 +38,7 @@ namespace Org.BouncyCastle.Tls.Crypto.Impl DerInteger sha384Size = new DerInteger(TlsCryptoUtilities.GetHashOutputSize(CryptoHashAlgorithm.sha384)); DerInteger sha512Size = new DerInteger(TlsCryptoUtilities.GetHashOutputSize(CryptoHashAlgorithm.sha512)); - DerInteger trailerField = new DerInteger(1); + DerInteger trailerField = DerInteger.One; try { diff --git a/crypto/src/x509/X509Utilities.cs b/crypto/src/x509/X509Utilities.cs index cee664370..6f01fc53d 100644 --- a/crypto/src/x509/X509Utilities.cs +++ b/crypto/src/x509/X509Utilities.cs @@ -201,7 +201,7 @@ namespace Org.BouncyCastle.X509 hashAlgId, new AlgorithmIdentifier(PkcsObjectIdentifiers.IdMgf1, hashAlgId), new DerInteger(saltSize), - new DerInteger(1)); + DerInteger.One); } internal static DerBitString CollectDerBitString(IBlockResult result) diff --git a/crypto/test/src/asn1/test/GenerationTest.cs b/crypto/test/src/asn1/test/GenerationTest.cs index 3a0fae8e7..4f4b70c58 100644 --- a/crypto/test/src/asn1/test/GenerationTest.cs +++ b/crypto/test/src/asn1/test/GenerationTest.cs @@ -54,7 +54,7 @@ namespace Org.BouncyCastle.Asn1.Tests DateTime startDate = MakeUtcDateTime(1970, 1, 1, 0, 0, 1); DateTime endDate = MakeUtcDateTime(1970, 1, 1, 0, 0, 12); - gen.SetSerialNumber(new DerInteger(1)); + gen.SetSerialNumber(DerInteger.One); gen.SetStartDate(new Time(startDate)); gen.SetEndDate(new Time(endDate)); @@ -107,7 +107,7 @@ namespace Org.BouncyCastle.Asn1.Tests DateTime startDate = MakeUtcDateTime(1970, 1, 1, 0, 0, 1); DateTime endDate = MakeUtcDateTime(1970, 1, 1, 0, 0, 2); - gen.SetSerialNumber(new DerInteger(2)); + gen.SetSerialNumber(DerInteger.Two); gen.SetStartDate(new Time(startDate)); gen.SetEndDate(new Time(endDate)); @@ -121,7 +121,7 @@ namespace Org.BouncyCastle.Asn1.Tests new AlgorithmIdentifier( OiwObjectIdentifiers.ElGamalAlgorithm, new ElGamalParameter(BigInteger.One, BigInteger.Two)), - new DerInteger(3)); + DerInteger.Three); gen.SetSubjectPublicKeyInfo(info); @@ -167,7 +167,7 @@ namespace Org.BouncyCastle.Asn1.Tests DateTime startDate = MakeUtcDateTime(1970, 1, 1, 0, 0, 1); DateTime endDate = MakeUtcDateTime(1970, 1, 1, 0, 0, 2); - gen.SetSerialNumber(new DerInteger(2)); + gen.SetSerialNumber(DerInteger.Two); gen.SetStartDate(new Time(startDate)); gen.SetEndDate(new Time(endDate)); @@ -179,7 +179,7 @@ namespace Org.BouncyCastle.Asn1.Tests SubjectPublicKeyInfo info = new SubjectPublicKeyInfo( new AlgorithmIdentifier(OiwObjectIdentifiers.ElGamalAlgorithm, new ElGamalParameter(BigInteger.One, BigInteger.Two)), - new DerInteger(3)); + DerInteger.Three); gen.SetSubjectPublicKeyInfo(info); @@ -241,7 +241,7 @@ namespace Org.BouncyCastle.Asn1.Tests gen.SetIssuer(new X509Name("CN=AU,O=Bouncy Castle")); - gen.AddCrlEntry(new DerInteger(1), new Time(MakeUtcDateTime(1970, 1, 1, 0, 0, 1)), ReasonFlags.AACompromise); + gen.AddCrlEntry(DerInteger.One, new Time(MakeUtcDateTime(1970, 1, 1, 0, 0, 1)), ReasonFlags.AACompromise); gen.SetNextUpdate(new Time(MakeUtcDateTime(1970, 1, 1, 0, 0, 2))); @@ -259,7 +259,7 @@ namespace Org.BouncyCastle.Asn1.Tests new AlgorithmIdentifier( OiwObjectIdentifiers.ElGamalAlgorithm, new ElGamalParameter(BigInteger.One, BigInteger.Two)), - new DerInteger(3)); + DerInteger.Three); order.Add(X509Extensions.AuthorityKeyIdentifier); order.Add(X509Extensions.IssuerAlternativeName); @@ -268,7 +268,7 @@ namespace Org.BouncyCastle.Asn1.Tests extensions.Add(X509Extensions.AuthorityKeyIdentifier, new X509Extension(true, new DerOctetString(CreateAuthorityKeyId(info, new X509Name("CN=AU,O=Bouncy Castle,OU=Test 2"), 2)))); extensions.Add(X509Extensions.IssuerAlternativeName, new X509Extension(false, new DerOctetString(GeneralNames.GetInstance(new DerSequence(new GeneralName(new X509Name("CN=AU,O=Bouncy Castle,OU=Test 3"))))))); - extensions.Add(X509Extensions.CrlNumber, new X509Extension(false, new DerOctetString(new DerInteger(1)))); + extensions.Add(X509Extensions.CrlNumber, new X509Extension(false, new DerOctetString(DerInteger.One))); extensions.Add(X509Extensions.IssuingDistributionPoint, new X509Extension(true, new DerOctetString(IssuingDistributionPoint.GetInstance(DerSequence.Empty)))); X509Extensions ex = new X509Extensions(order, extensions); diff --git a/crypto/test/src/asn1/test/OctetStringTest.cs b/crypto/test/src/asn1/test/OctetStringTest.cs index 959d16c32..a0a97756b 100644 --- a/crypto/test/src/asn1/test/OctetStringTest.cs +++ b/crypto/test/src/asn1/test/OctetStringTest.cs @@ -125,7 +125,7 @@ namespace Org.BouncyCastle.Asn1.Tests using (var cGen = new BerSequenceGenerator(sGen.GetRawOutputStream(), 0, true)) { - cGen.AddObject(new DerInteger(0)); + cGen.AddObject(DerInteger.Zero); // // AlgorithmIdentifier diff --git a/crypto/test/src/asn1/test/OtherCertIDUnitTest.cs b/crypto/test/src/asn1/test/OtherCertIDUnitTest.cs index 784df4146..395671c68 100644 --- a/crypto/test/src/asn1/test/OtherCertIDUnitTest.cs +++ b/crypto/test/src/asn1/test/OtherCertIDUnitTest.cs @@ -21,7 +21,7 @@ namespace Org.BouncyCastle.Asn1.Tests AlgorithmIdentifier algId = new AlgorithmIdentifier(new DerObjectIdentifier("1.2.2.3")); byte[] digest = new byte[20]; OtherHash otherHash = new OtherHash(new OtherHashAlgAndValue(algId, digest)); - IssuerSerial issuerSerial = new IssuerSerial(new GeneralNames(new GeneralName(new X509Name("CN=test"))), new DerInteger(1)); + IssuerSerial issuerSerial = new IssuerSerial(new GeneralNames(new GeneralName(new X509Name("CN=test"))), DerInteger.One); OtherCertID certID = new OtherCertID(otherHash); diff --git a/crypto/test/src/asn1/test/ProcurationSyntaxUnitTest.cs b/crypto/test/src/asn1/test/ProcurationSyntaxUnitTest.cs index 4a68cdb9d..eef402c48 100644 --- a/crypto/test/src/asn1/test/ProcurationSyntaxUnitTest.cs +++ b/crypto/test/src/asn1/test/ProcurationSyntaxUnitTest.cs @@ -22,7 +22,7 @@ namespace Org.BouncyCastle.Asn1.Tests string country = "AU"; DirectoryString typeOfSubstitution = new DirectoryString("substitution"); GeneralName thirdPerson = new GeneralName(new X509Name("CN=thirdPerson")); - IssuerSerial certRef = new IssuerSerial(new GeneralNames(new GeneralName(new X509Name("CN=test"))), new DerInteger(1)); + IssuerSerial certRef = new IssuerSerial(new GeneralNames(new GeneralName(new X509Name("CN=test"))), DerInteger.One); ProcurationSyntax procuration = new ProcurationSyntax(country, typeOfSubstitution, thirdPerson); diff --git a/crypto/test/src/asn1/test/TagTest.cs b/crypto/test/src/asn1/test/TagTest.cs index e2f84dfb5..004893d25 100644 --- a/crypto/test/src/asn1/test/TagTest.cs +++ b/crypto/test/src/asn1/test/TagTest.cs @@ -103,7 +103,7 @@ namespace Org.BouncyCastle.Asn1.Tests } } - tagged = new DerTaggedObject(false, 34, new DerTaggedObject(true, 1000, new DerInteger(1))); + tagged = new DerTaggedObject(false, 34, new DerTaggedObject(true, 1000, DerInteger.One)); if (!AreEqual(taggedInteger, tagged.GetEncoded())) { Fail("incorrect encoding for implicit explicit tagged integer"); diff --git a/crypto/test/src/tsp/test/GenTimeAccuracyTest.cs b/crypto/test/src/tsp/test/GenTimeAccuracyTest.cs index 01cc83d53..7f98f8167 100644 --- a/crypto/test/src/tsp/test/GenTimeAccuracyTest.cs +++ b/crypto/test/src/tsp/test/GenTimeAccuracyTest.cs @@ -10,10 +10,10 @@ namespace Org.BouncyCastle.Tsp.Tests [TestFixture] public class GenTimeAccuracyUnitTest { - private static readonly DerInteger ZERO_VALUE = new DerInteger(0); - private static readonly DerInteger ONE_VALUE = new DerInteger(1); - private static readonly DerInteger TWO_VALUE = new DerInteger(2); - private static readonly DerInteger THREE_VALUE = new DerInteger(3); + private static readonly DerInteger ZERO_VALUE = DerInteger.Zero; + private static readonly DerInteger ONE_VALUE = DerInteger.One; + private static readonly DerInteger TWO_VALUE = DerInteger.Two; + private static readonly DerInteger THREE_VALUE = DerInteger.Three; [Test] public void TestOneTwoThree() -- cgit 1.4.1