diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2019-08-10 00:18:03 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2019-08-10 00:18:03 +0700 |
commit | 9c6880706476c6066b9aa2ce82c159d64c8766c6 (patch) | |
tree | 092fb747c1e8d483d4e611e08a1e648f9d864620 /crypto/src/asn1/tsp/Accuracy.cs | |
parent | Use utility method (diff) | |
download | BouncyCastle.NET-ed25519-9c6880706476c6066b9aa2ce82c159d64c8766c6.tar.xz |
Add and use IntValueExact properties
Diffstat (limited to 'crypto/src/asn1/tsp/Accuracy.cs')
-rw-r--r-- | crypto/src/asn1/tsp/Accuracy.cs | 74 |
1 files changed, 32 insertions, 42 deletions
diff --git a/crypto/src/asn1/tsp/Accuracy.cs b/crypto/src/asn1/tsp/Accuracy.cs index 9da8f1d68..31289db99 100644 --- a/crypto/src/asn1/tsp/Accuracy.cs +++ b/crypto/src/asn1/tsp/Accuracy.cs @@ -22,26 +22,22 @@ namespace Org.BouncyCastle.Asn1.Tsp DerInteger millis, DerInteger micros) { - //Verifications - if (millis != null - && (millis.Value.IntValue < MinMillis - || millis.Value.IntValue > MaxMillis)) - { - throw new ArgumentException( - "Invalid millis field : not in (1..999)"); - } - - if (micros != null - && (micros.Value.IntValue < MinMicros - || micros.Value.IntValue > MaxMicros)) - { - throw new ArgumentException( - "Invalid micros field : not in (1..999)"); - } + if (null != millis) + { + int millisValue = millis.IntValueExact; + if (millisValue < MinMillis || millisValue > MaxMillis) + throw new ArgumentException("Invalid millis field : not in (1..999)"); + } + if (null != micros) + { + int microsValue = micros.IntValueExact; + if (microsValue < MinMicros || microsValue > MaxMicros) + throw new ArgumentException("Invalid micros field : not in (1..999)"); + } - this.seconds = seconds; - this.millis = millis; - this.micros = micros; + this.seconds = seconds; + this.millis = millis; + this.micros = micros; } private Accuracy( @@ -58,29 +54,23 @@ namespace Org.BouncyCastle.Asn1.Tsp { Asn1TaggedObject extra = (Asn1TaggedObject)seq[i]; - switch (extra.TagNo) - { - case 0: - millis = DerInteger.GetInstance(extra, false); - if (millis.Value.IntValue < MinMillis - || millis.Value.IntValue > MaxMillis) - { - throw new ArgumentException( - "Invalid millis field : not in (1..999)."); - } - break; - case 1: - micros = DerInteger.GetInstance(extra, false); - if (micros.Value.IntValue < MinMicros - || micros.Value.IntValue > MaxMicros) - { - throw new ArgumentException( - "Invalid micros field : not in (1..999)."); - } - break; - default: - throw new ArgumentException("Invalig tag number"); - } + switch (extra.TagNo) + { + case 0: + millis = DerInteger.GetInstance(extra, false); + int millisValue = millis.IntValueExact; + if (millisValue < MinMillis || millisValue > MaxMillis) + throw new ArgumentException("Invalid millis field : not in (1..999)"); + break; + case 1: + micros = DerInteger.GetInstance(extra, false); + int microsValue = micros.IntValueExact; + if (microsValue < MinMicros || microsValue > MaxMicros) + throw new ArgumentException("Invalid micros field : not in (1..999)"); + break; + default: + throw new ArgumentException("Invalid tag number"); + } } } } |