diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-01-30 18:54:08 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-01-30 18:54:08 +0700 |
commit | f82c115316bcbf98fae46cb6fd90a8e5a57fdef2 (patch) | |
tree | 83210fc79b5e0bdf0716f6e32e76b2db26cc30a3 | |
parent | Change method names (diff) | |
download | BouncyCastle.NET-ed25519-f82c115316bcbf98fae46cb6fd90a8e5a57fdef2.tar.xz |
Misc. cleanup after bc-fips-csharp updates
22 files changed, 144 insertions, 222 deletions
diff --git a/crypto/src/asn1/misc/MiscObjectIdentifiers.cs b/crypto/src/asn1/misc/MiscObjectIdentifiers.cs index 693c0eaba..ebf107dd6 100644 --- a/crypto/src/asn1/misc/MiscObjectIdentifiers.cs +++ b/crypto/src/asn1/misc/MiscObjectIdentifiers.cs @@ -50,7 +50,7 @@ namespace Org.BouncyCastle.Asn1.Misc public static readonly DerObjectIdentifier Entrust = new DerObjectIdentifier("1.2.840.113533.7"); public static readonly DerObjectIdentifier EntrustVersionExtension = Entrust.Branch("65.0"); - public static readonly DerObjectIdentifier cast5CBC = new DerObjectIdentifier(Entrust+ ".66.10"); + public static readonly DerObjectIdentifier cast5CBC = Entrust.Branch("66.10"); // // HMAC-SHA1 hMAC-SHA1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) diff --git a/crypto/src/asn1/x509/DistributionPoint.cs b/crypto/src/asn1/x509/DistributionPoint.cs index f35586016..077c9321e 100644 --- a/crypto/src/asn1/x509/DistributionPoint.cs +++ b/crypto/src/asn1/x509/DistributionPoint.cs @@ -1,8 +1,5 @@ -using System; using System.Text; -using Org.BouncyCastle.Utilities; - namespace Org.BouncyCastle.Asn1.X509 { /** @@ -18,35 +15,25 @@ namespace Org.BouncyCastle.Asn1.X509 public class DistributionPoint : Asn1Encodable { - internal readonly DistributionPointName distributionPoint; - internal readonly ReasonFlags reasons; - internal readonly GeneralNames cRLIssuer; - - public static DistributionPoint GetInstance( - Asn1TaggedObject obj, - bool explicitly) + public static DistributionPoint GetInstance(object obj) { - return GetInstance(Asn1Sequence.GetInstance(obj, explicitly)); + if (obj == null) + return null; + if (obj is DistributionPoint distributionPoint) + return distributionPoint; + return new DistributionPoint(Asn1Sequence.GetInstance(obj)); } - public static DistributionPoint GetInstance( - object obj) + public static DistributionPoint GetInstance(Asn1TaggedObject obj, bool explicitly) { - if(obj == null || obj is DistributionPoint) - { - return (DistributionPoint) obj; - } - - if(obj is Asn1Sequence) - { - return new DistributionPoint((Asn1Sequence) obj); - } - - throw new ArgumentException("Invalid DistributionPoint: " + Platform.GetTypeName(obj)); + return GetInstance(Asn1Sequence.GetInstance(obj, explicitly)); } - private DistributionPoint( - Asn1Sequence seq) + private readonly DistributionPointName m_distributionPoint; + private readonly ReasonFlags m_reasons; + private readonly GeneralNames m_crlIssuer; + + private DistributionPoint(Asn1Sequence seq) { for (int i = 0; i != seq.Count; i++) { @@ -55,52 +42,41 @@ namespace Org.BouncyCastle.Asn1.X509 switch (t.TagNo) { case 0: - distributionPoint = DistributionPointName.GetInstance(t, true); + m_distributionPoint = DistributionPointName.GetInstance(t, true); break; case 1: - reasons = new ReasonFlags(DerBitString.GetInstance(t, false)); + m_reasons = new ReasonFlags(DerBitString.GetInstance(t, false)); break; case 2: - cRLIssuer = GeneralNames.GetInstance(t, false); + m_crlIssuer = GeneralNames.GetInstance(t, false); break; } } } - public DistributionPoint( - DistributionPointName distributionPointName, - ReasonFlags reasons, - GeneralNames crlIssuer) + public DistributionPoint(DistributionPointName distributionPointName, ReasonFlags reasons, + GeneralNames crlIssuer) { - this.distributionPoint = distributionPointName; - this.reasons = reasons; - this.cRLIssuer = crlIssuer; + m_distributionPoint = distributionPointName; + m_reasons = reasons; + m_crlIssuer = crlIssuer; } - public DistributionPointName DistributionPointName - { - get { return distributionPoint; } - } + public DistributionPointName DistributionPointName => m_distributionPoint; - public ReasonFlags Reasons - { - get { return reasons; } - } + public ReasonFlags Reasons => m_reasons; - public GeneralNames CrlIssuer - { - get { return cRLIssuer; } - } + public GeneralNames CrlIssuer => m_crlIssuer; public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); // As this is a CHOICE it must be explicitly tagged - v.AddOptionalTagged(true, 0, distributionPoint); + v.AddOptionalTagged(true, 0, m_distributionPoint); - v.AddOptionalTagged(false, 1, reasons); - v.AddOptionalTagged(false, 2, cRLIssuer); + v.AddOptionalTagged(false, 1, m_reasons); + v.AddOptionalTagged(false, 2, m_crlIssuer); return new DerSequence(v); } @@ -108,17 +84,17 @@ namespace Org.BouncyCastle.Asn1.X509 { StringBuilder buf = new StringBuilder(); buf.AppendLine("DistributionPoint: ["); - if (distributionPoint != null) + if (m_distributionPoint != null) { - AppendObject(buf, "distributionPoint", distributionPoint.ToString()); + AppendObject(buf, "distributionPoint", m_distributionPoint.ToString()); } - if (reasons != null) + if (m_reasons != null) { - AppendObject(buf, "reasons", reasons.ToString()); + AppendObject(buf, "reasons", m_reasons.ToString()); } - if (cRLIssuer != null) + if (m_crlIssuer != null) { - AppendObject(buf, "cRLIssuer", cRLIssuer.ToString()); + AppendObject(buf, "cRLIssuer", m_crlIssuer.ToString()); } buf.AppendLine("]"); return buf.ToString(); diff --git a/crypto/src/asn1/x509/DistributionPointName.cs b/crypto/src/asn1/x509/DistributionPointName.cs index bca54fa06..bdb7219be 100644 --- a/crypto/src/asn1/x509/DistributionPointName.cs +++ b/crypto/src/asn1/x509/DistributionPointName.cs @@ -1,8 +1,5 @@ -using System; using System.Text; -using Org.BouncyCastle.Utilities; - namespace Org.BouncyCastle.Asn1.X509 { /** @@ -17,90 +14,71 @@ namespace Org.BouncyCastle.Asn1.X509 public class DistributionPointName : Asn1Encodable, IAsn1Choice { - internal readonly Asn1Encodable name; - internal readonly int type; - - public const int FullName = 0; - public const int NameRelativeToCrlIssuer = 1; + public const int FullName = 0; + public const int NameRelativeToCrlIssuer = 1; - public static DistributionPointName GetInstance( - Asn1TaggedObject obj, - bool explicitly) + public static DistributionPointName GetInstance(object obj) { - return GetInstance(Asn1TaggedObject.GetInstance(obj, true)); - } - - public static DistributionPointName GetInstance( - object obj) - { - if (obj == null || obj is DistributionPointName) - { - return (DistributionPointName) obj; - } - - if (obj is Asn1TaggedObject) - { - return new DistributionPointName((Asn1TaggedObject) obj); - } - - throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj"); + if (obj == null) + return null; + if (obj is DistributionPointName distributionPointName) + return distributionPointName; + return new DistributionPointName(Asn1TaggedObject.GetInstance(obj)); } - public DistributionPointName( - int type, - Asn1Encodable name) + public static DistributionPointName GetInstance(Asn1TaggedObject obj, bool explicitly) { - this.type = type; - this.name = name; + return GetInstance(Asn1TaggedObject.GetInstance(obj, true)); } - public DistributionPointName( - GeneralNames name) - : this(FullName, name) - { - } + private readonly Asn1Encodable m_name; + private readonly int m_type; - public int PointType + public DistributionPointName(GeneralNames name) + : this(FullName, name) { - get { return type; } } - public Asn1Encodable Name + public DistributionPointName(int type, Asn1Encodable name) { - get { return name; } + m_type = type; + m_name = name; } - public DistributionPointName( - Asn1TaggedObject obj) + public int PointType => m_type; + + public Asn1Encodable Name => m_name; + + public DistributionPointName(Asn1TaggedObject obj) { - this.type = obj.TagNo; + m_type = obj.TagNo; - if (type == FullName) + if (m_type == FullName) { - this.name = GeneralNames.GetInstance(obj, false); + m_name = GeneralNames.GetInstance(obj, false); } else { - this.name = Asn1Set.GetInstance(obj, false); + m_name = Asn1Set.GetInstance(obj, false); } } public override Asn1Object ToAsn1Object() { - return new DerTaggedObject(false, type, name); + return new DerTaggedObject(false, m_type, m_name); } public override string ToString() { StringBuilder buf = new StringBuilder(); buf.AppendLine("DistributionPointName: ["); - if (type == FullName) + if (m_type == FullName) { - AppendObject(buf, "fullName", name.ToString()); + AppendObject(buf, "fullName", m_name.ToString()); } else { - AppendObject(buf, "nameRelativeToCRLIssuer", name.ToString()); + AppendObject(buf, "nameRelativeToCRLIssuer", m_name.ToString()); } buf.AppendLine("]"); return buf.ToString(); diff --git a/crypto/src/asn1/x509/GeneralNames.cs b/crypto/src/asn1/x509/GeneralNames.cs index acf263f84..3937b3279 100644 --- a/crypto/src/asn1/x509/GeneralNames.cs +++ b/crypto/src/asn1/x509/GeneralNames.cs @@ -1,24 +1,16 @@ -using System; using System.Text; -using Org.BouncyCastle.Utilities; - namespace Org.BouncyCastle.Asn1.X509 { public class GeneralNames : Asn1Encodable { - private static GeneralName[] Copy(GeneralName[] names) - { - return (GeneralName[])names.Clone(); - } - public static GeneralNames GetInstance(object obj) { - if (obj is GeneralNames) - return (GeneralNames)obj; if (obj == null) return null; + if (obj is GeneralNames generalNames) + return generalNames; return new GeneralNames(Asn1Sequence.GetInstance(obj)); } @@ -32,36 +24,33 @@ namespace Org.BouncyCastle.Asn1.X509 return GetInstance(X509Extensions.GetExtensionParsedValue(extensions, extOid)); } - private readonly GeneralName[] names; + private static GeneralName[] Copy(GeneralName[] names) + { + return (GeneralName[])names.Clone(); + } + + private readonly GeneralName[] m_names; /// <summary>Construct a GeneralNames object containing one GeneralName.</summary> /// <param name="name">The name to be contained.</param> - public GeneralNames( - GeneralName name) + public GeneralNames(GeneralName name) { - names = new GeneralName[]{ name }; + m_names = new GeneralName[]{ name }; } - public GeneralNames( - GeneralName[] names) + public GeneralNames(GeneralName[] names) { - this.names = Copy(names); + m_names = Copy(names); } - private GeneralNames( - Asn1Sequence seq) + private GeneralNames(Asn1Sequence seq) { - this.names = new GeneralName[seq.Count]; - - for (int i = 0; i != seq.Count; i++) - { - names[i] = GeneralName.GetInstance(seq[i]); - } + m_names = seq.MapElements(GeneralName.GetInstance); } public GeneralName[] GetNames() { - return Copy(names); + return Copy(m_names); } /** @@ -72,14 +61,14 @@ namespace Org.BouncyCastle.Asn1.X509 */ public override Asn1Object ToAsn1Object() { - return new DerSequence(names); + return new DerSequence(m_names); } public override string ToString() { StringBuilder buf = new StringBuilder(); buf.AppendLine("GeneralNames:"); - foreach (GeneralName name in names) + foreach (GeneralName name in m_names) { buf.Append(" ") .Append(name) diff --git a/crypto/src/asn1/x509/IssuingDistributionPoint.cs b/crypto/src/asn1/x509/IssuingDistributionPoint.cs index a05efffa4..0287fd8f5 100644 --- a/crypto/src/asn1/x509/IssuingDistributionPoint.cs +++ b/crypto/src/asn1/x509/IssuingDistributionPoint.cs @@ -1,8 +1,6 @@ using System; using System.Text; -using Org.BouncyCastle.Utilities; - namespace Org.BouncyCastle.Asn1.X509 { /** @@ -28,27 +26,18 @@ namespace Org.BouncyCastle.Asn1.X509 private readonly Asn1Sequence seq; - public static IssuingDistributionPoint GetInstance( - Asn1TaggedObject obj, - bool explicitly) + public static IssuingDistributionPoint GetInstance(Asn1TaggedObject obj, bool explicitly) { return GetInstance(Asn1Sequence.GetInstance(obj, explicitly)); } - public static IssuingDistributionPoint GetInstance( - object obj) + public static IssuingDistributionPoint GetInstance(object obj) { - if (obj == null || obj is IssuingDistributionPoint) - { - return (IssuingDistributionPoint) obj; - } - - if (obj is Asn1Sequence) - { - return new IssuingDistributionPoint((Asn1Sequence) obj); - } - - throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj"); + if (obj == null) + return null; + if (obj is IssuingDistributionPoint issuingDistributionPoint) + return issuingDistributionPoint; + return new IssuingDistributionPoint(Asn1Sequence.GetInstance(obj)); } /** @@ -113,8 +102,7 @@ namespace Org.BouncyCastle.Asn1.X509 /** * Constructor from Asn1Sequence */ - private IssuingDistributionPoint( - Asn1Sequence seq) + private IssuingDistributionPoint(Asn1Sequence seq) { this.seq = seq; @@ -124,27 +112,27 @@ namespace Org.BouncyCastle.Asn1.X509 switch (o.TagNo) { - case 0: - // CHOICE so explicit - _distributionPoint = DistributionPointName.GetInstance(o, true); - break; - case 1: - _onlyContainsUserCerts = DerBoolean.GetInstance(o, false).IsTrue; - break; - case 2: - _onlyContainsCACerts = DerBoolean.GetInstance(o, false).IsTrue; - break; - case 3: - _onlySomeReasons = new ReasonFlags(ReasonFlags.GetInstance(o, false)); - break; - case 4: - _indirectCRL = DerBoolean.GetInstance(o, false).IsTrue; - break; - case 5: - _onlyContainsAttributeCerts = DerBoolean.GetInstance(o, false).IsTrue; - break; - default: - throw new ArgumentException("unknown tag in IssuingDistributionPoint"); + case 0: + // CHOICE so explicit + _distributionPoint = DistributionPointName.GetInstance(o, true); + break; + case 1: + _onlyContainsUserCerts = DerBoolean.GetInstance(o, false).IsTrue; + break; + case 2: + _onlyContainsCACerts = DerBoolean.GetInstance(o, false).IsTrue; + break; + case 3: + _onlySomeReasons = new ReasonFlags(ReasonFlags.GetInstance(o, false)); + break; + case 4: + _indirectCRL = DerBoolean.GetInstance(o, false).IsTrue; + break; + case 5: + _onlyContainsAttributeCerts = DerBoolean.GetInstance(o, false).IsTrue; + break; + default: + throw new ArgumentException("unknown tag in IssuingDistributionPoint"); } } } diff --git a/crypto/src/crypto/IBlockResult.cs b/crypto/src/crypto/IBlockResult.cs index f3b73e59f..2a62e26de 100644 --- a/crypto/src/crypto/IBlockResult.cs +++ b/crypto/src/crypto/IBlockResult.cs @@ -31,6 +31,7 @@ namespace Org.BouncyCastle.Crypto int Collect(Span<byte> output); #endif + /// <summary>Return an upper limit for the size of the result.</summary> int GetMaxResultLength(); } } diff --git a/crypto/src/crypto/engines/AesEngine.cs b/crypto/src/crypto/engines/AesEngine.cs index 914550d6d..3977cb893 100644 --- a/crypto/src/crypto/engines/AesEngine.cs +++ b/crypto/src/crypto/engines/AesEngine.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Crypto.Utilities; @@ -37,7 +36,7 @@ namespace Org.BouncyCastle.Crypto.Engines // The S box private static readonly byte[] S = { - 99, 124, 119, 123, 242, 107, 111, 197, + 99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118, 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192, diff --git a/crypto/src/crypto/engines/Salsa20Engine.cs b/crypto/src/crypto/engines/Salsa20Engine.cs index 7c2c1e1f9..2e8f8e50a 100644 --- a/crypto/src/crypto/engines/Salsa20Engine.cs +++ b/crypto/src/crypto/engines/Salsa20Engine.cs @@ -27,7 +27,7 @@ namespace Org.BouncyCastle.Crypto.Engines private readonly static uint[] TAU_SIGMA = Pack.LE_To_UInt32(Strings.ToAsciiByteArray("expand 16-byte k" + "expand 32-byte k"), 0, 8); - internal void PackTauOrSigma(int keyLength, uint[] state, int stateOffset) + internal static void PackTauOrSigma(int keyLength, uint[] state, int stateOffset) { int tsOff = (keyLength - 16) / 4; state[stateOffset] = TAU_SIGMA[tsOff]; diff --git a/crypto/src/crypto/macs/Poly1305.cs b/crypto/src/crypto/macs/Poly1305.cs index d02216309..adf4975ba 100644 --- a/crypto/src/crypto/macs/Poly1305.cs +++ b/crypto/src/crypto/macs/Poly1305.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; #endif +using Org.BouncyCastle.Crypto.Generators; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Crypto.Utilities; @@ -22,7 +23,7 @@ namespace Org.BouncyCastle.Crypto.Macs /// href="https://github.com/floodyberry/poly1305-donna">poly1305-donna-unrolled</a> C implementation /// by Andrew M (@floodyberry). /// </remarks> - /// <seealso cref="Org.BouncyCastle.Crypto.Generators.Poly1305KeyGenerator"/> + /// <seealso cref="Poly1305KeyGenerator"/> public class Poly1305 : IMac { diff --git a/crypto/src/crypto/modes/CfbBlockCipher.cs b/crypto/src/crypto/modes/CfbBlockCipher.cs index 7bce9843f..cdb17dd3c 100644 --- a/crypto/src/crypto/modes/CfbBlockCipher.cs +++ b/crypto/src/crypto/modes/CfbBlockCipher.cs @@ -61,9 +61,8 @@ namespace Org.BouncyCastle.Crypto.Modes ICipherParameters parameters) { this.encrypting = forEncryption; - if (parameters is ParametersWithIV) + if (parameters is ParametersWithIV ivParam) { - ParametersWithIV ivParam = (ParametersWithIV) parameters; byte[] iv = ivParam.GetIV(); int diff = IV.Length - iv.Length; Array.Copy(iv, 0, IV, diff, iv.Length); diff --git a/crypto/src/crypto/modes/EcbBlockCipher.cs b/crypto/src/crypto/modes/EcbBlockCipher.cs index 96f9811dd..b41452622 100644 --- a/crypto/src/crypto/modes/EcbBlockCipher.cs +++ b/crypto/src/crypto/modes/EcbBlockCipher.cs @@ -17,10 +17,7 @@ namespace Org.BouncyCastle.Crypto.Modes public EcbBlockCipher(IBlockCipher cipher) { - if (cipher == null) - throw new ArgumentNullException(nameof(cipher)); - - m_cipher = cipher; + m_cipher = cipher ?? throw new ArgumentNullException(nameof(cipher)); } public bool IsPartialBlockOkay => false; diff --git a/crypto/src/crypto/modes/OpenPgpCfbBlockCipher.cs b/crypto/src/crypto/modes/OpenPgpCfbBlockCipher.cs index 4e6e0ffaa..dff5af1c6 100644 --- a/crypto/src/crypto/modes/OpenPgpCfbBlockCipher.cs +++ b/crypto/src/crypto/modes/OpenPgpCfbBlockCipher.cs @@ -161,7 +161,6 @@ namespace Org.BouncyCastle.Crypto.Modes return (byte)(FRE[blockOff] ^ data); } - #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER private int EncryptBlock(ReadOnlySpan<byte> input, Span<byte> output) { diff --git a/crypto/src/crypto/modes/SicBlockCipher.cs b/crypto/src/crypto/modes/SicBlockCipher.cs index fee8bb028..ee204c18c 100644 --- a/crypto/src/crypto/modes/SicBlockCipher.cs +++ b/crypto/src/crypto/modes/SicBlockCipher.cs @@ -1,7 +1,6 @@ using System; using Org.BouncyCastle.Crypto.Parameters; -using Org.BouncyCastle.Math; using Org.BouncyCastle.Utilities; @@ -45,8 +44,7 @@ namespace Org.BouncyCastle.Crypto.Modes bool forEncryption, //ignored by this CTR mode ICipherParameters parameters) { - ParametersWithIV ivParam = parameters as ParametersWithIV; - if (ivParam == null) + if (!(parameters is ParametersWithIV ivParam)) throw new ArgumentException("CTR/SIC mode requires ParametersWithIV", "parameters"); this.IV = Arrays.Clone(ivParam.GetIV()); @@ -58,13 +56,13 @@ namespace Org.BouncyCastle.Crypto.Modes if (blockSize - IV.Length > maxCounterSize) throw new ArgumentException("CTR/SIC mode requires IV of at least: " + (blockSize - maxCounterSize) + " bytes."); + Reset(); + // if null it's an IV changed only. if (ivParam.Parameters != null) { cipher.Init(true, ivParam.Parameters); } - - Reset(); } public virtual string AlgorithmName diff --git a/crypto/src/crypto/prng/CryptoApiRandomGenerator.cs b/crypto/src/crypto/prng/CryptoApiRandomGenerator.cs index dcd3baa1c..bafb4fd5e 100644 --- a/crypto/src/crypto/prng/CryptoApiRandomGenerator.cs +++ b/crypto/src/crypto/prng/CryptoApiRandomGenerator.cs @@ -52,8 +52,8 @@ namespace Org.BouncyCastle.Crypto.Prng m_randomNumberGenerator.GetBytes(bytes, start, len); #else if (start < 0) - throw new ArgumentException("Start offset cannot be negative", "start"); - if (bytes.Length < (start + len)) + throw new ArgumentException("Start offset cannot be negative", nameof(start)); + if (start > bytes.Length - len) throw new ArgumentException("Byte array too small for requested offset and length"); if (bytes.Length == len && start == 0) @@ -62,9 +62,9 @@ namespace Org.BouncyCastle.Crypto.Prng } else { - byte[] tmpBuf = new byte[len]; - NextBytes(tmpBuf); - Array.Copy(tmpBuf, 0, bytes, start, len); + byte[] tmp = new byte[len]; + NextBytes(tmp); + tmp.CopyTo(bytes, start); } #endif } diff --git a/crypto/src/crypto/signers/DsaDigestSigner.cs b/crypto/src/crypto/signers/DsaDigestSigner.cs index f546785bd..608e55304 100644 --- a/crypto/src/crypto/signers/DsaDigestSigner.cs +++ b/crypto/src/crypto/signers/DsaDigestSigner.cs @@ -78,7 +78,7 @@ namespace Org.BouncyCastle.Crypto.Signers public virtual byte[] GenerateSignature() { if (!forSigning) - throw new InvalidOperationException("DSADigestSigner not initialised for signature generation."); + throw new InvalidOperationException("DsaDigestSigner not initialized for signature generation."); byte[] hash = new byte[digest.GetDigestSize()]; digest.DoFinal(hash, 0); @@ -98,7 +98,7 @@ namespace Org.BouncyCastle.Crypto.Signers public virtual bool VerifySignature(byte[] signature) { if (forSigning) - throw new InvalidOperationException("DSADigestSigner not initialised for verification"); + throw new InvalidOperationException("DsaDigestSigner not initialized for verification"); byte[] hash = new byte[digest.GetDigestSize()]; digest.DoFinal(hash, 0); diff --git a/crypto/src/crypto/signers/DsaSigner.cs b/crypto/src/crypto/signers/DsaSigner.cs index d0a2c29e4..a45c05c33 100644 --- a/crypto/src/crypto/signers/DsaSigner.cs +++ b/crypto/src/crypto/signers/DsaSigner.cs @@ -54,17 +54,17 @@ namespace Org.BouncyCastle.Crypto.Signers parameters = rParam.Parameters; } - if (!(parameters is DsaPrivateKeyParameters)) + if (!(parameters is DsaPrivateKeyParameters dsaPrivateKeyParameters)) throw new InvalidKeyException("DSA private key required for signing"); - this.key = (DsaPrivateKeyParameters)parameters; + this.key = dsaPrivateKeyParameters; } else { - if (!(parameters is DsaPublicKeyParameters)) + if (!(parameters is DsaPublicKeyParameters dsaPublicKeyParameters)) throw new InvalidKeyException("DSA public key required for verification"); - this.key = (DsaPublicKeyParameters)parameters; + this.key = dsaPublicKeyParameters; } this.random = InitSecureRandom(forSigning && !kCalculator.IsDeterministic, providedRandom); diff --git a/crypto/src/crypto/signers/ECDsaSigner.cs b/crypto/src/crypto/signers/ECDsaSigner.cs index b27182a9e..32225ec82 100644 --- a/crypto/src/crypto/signers/ECDsaSigner.cs +++ b/crypto/src/crypto/signers/ECDsaSigner.cs @@ -57,17 +57,17 @@ namespace Org.BouncyCastle.Crypto.Signers parameters = rParam.Parameters; } - if (!(parameters is ECPrivateKeyParameters)) + if (!(parameters is ECPrivateKeyParameters ecPrivateKeyParameters)) throw new InvalidKeyException("EC private key required for signing"); - this.key = (ECPrivateKeyParameters)parameters; + this.key = ecPrivateKeyParameters; } else { - if (!(parameters is ECPublicKeyParameters)) + if (!(parameters is ECPublicKeyParameters ecPublicKeyParameters)) throw new InvalidKeyException("EC public key required for verification"); - this.key = (ECPublicKeyParameters)parameters; + this.key = ecPublicKeyParameters; } this.random = InitSecureRandom(forSigning && !kCalculator.IsDeterministic, providedRandom); diff --git a/crypto/src/crypto/signers/StandardDsaEncoding.cs b/crypto/src/crypto/signers/StandardDsaEncoding.cs index 77cd6124d..8fa195982 100644 --- a/crypto/src/crypto/signers/StandardDsaEncoding.cs +++ b/crypto/src/crypto/signers/StandardDsaEncoding.cs @@ -24,7 +24,7 @@ namespace Org.BouncyCastle.Crypto.Signers return new BigInteger[]{ r, s }; } - throw new ArgumentException("Malformed signature", "encoding"); + throw new ArgumentException("Malformed signature", nameof(encoding)); } public virtual byte[] Encode(BigInteger n, BigInteger r, BigInteger s) @@ -55,7 +55,7 @@ namespace Org.BouncyCastle.Crypto.Signers protected virtual BigInteger CheckValue(BigInteger n, BigInteger x) { if (x.SignValue < 0 || (null != n && x.CompareTo(n) >= 0)) - throw new ArgumentException("Value out of range", "x"); + throw new ArgumentException("Value out of range", nameof(x)); return x; } diff --git a/crypto/src/math/ec/LongArray.cs b/crypto/src/math/ec/LongArray.cs index aa36de215..3475e9ecc 100644 --- a/crypto/src/math/ec/LongArray.cs +++ b/crypto/src/math/ec/LongArray.cs @@ -1,5 +1,6 @@ using System; using System.Text; + using Org.BouncyCastle.Math.Raw; using Org.BouncyCastle.Utilities; diff --git a/crypto/src/security/SecureRandom.cs b/crypto/src/security/SecureRandom.cs index 521e7db0e..a9c062b4e 100644 --- a/crypto/src/security/SecureRandom.cs +++ b/crypto/src/security/SecureRandom.cs @@ -254,7 +254,7 @@ namespace Org.BouncyCastle.Security ? stackalloc byte[seedLength] : new byte[seedLength]; #else - byte[] seed = new byte[seedLength]; + byte[] seed = new byte[seedLength]; #endif MasterRandom.NextBytes(seed); generator.AddSeedMaterial(seed); diff --git a/crypto/src/util/Arrays.cs b/crypto/src/util/Arrays.cs index 41e3c3195..a9ae6724a 100644 --- a/crypto/src/util/Arrays.cs +++ b/crypto/src/util/Arrays.cs @@ -606,9 +606,7 @@ namespace Org.BouncyCastle.Utilities return false; } - public static void Fill( - byte[] buf, - byte b) + public static void Fill(byte[] buf, byte b) { int i = buf.Length; while (i > 0) @@ -618,9 +616,7 @@ namespace Org.BouncyCastle.Utilities } [CLSCompliant(false)] - public static void Fill( - ulong[] buf, - ulong b) + public static void Fill(ulong[] buf, ulong b) { int i = buf.Length; while (i > 0) diff --git a/crypto/test/src/tls/test/LoggingDatagramTransport.cs b/crypto/test/src/tls/test/LoggingDatagramTransport.cs index 0ad15e065..59113cf73 100644 --- a/crypto/test/src/tls/test/LoggingDatagramTransport.cs +++ b/crypto/test/src/tls/test/LoggingDatagramTransport.cs @@ -96,7 +96,7 @@ namespace Org.BouncyCastle.Tls.Tests { if (pos % 16 == 0) { - sb.Append(Environment.NewLine); + sb.AppendLine(); sb.Append(" "); } else if (pos % 16 == 8) @@ -122,7 +122,7 @@ namespace Org.BouncyCastle.Tls.Tests { if (pos % 16 == 0) { - sb.Append(Environment.NewLine); + sb.AppendLine(); sb.Append(" "); } else if (pos % 16 == 8) |