summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crypto/src/asn1/DerInteger.cs39
1 files changed, 39 insertions, 0 deletions
diff --git a/crypto/src/asn1/DerInteger.cs b/crypto/src/asn1/DerInteger.cs

index d68a71e9d..666723527 100644 --- a/crypto/src/asn1/DerInteger.cs +++ b/crypto/src/asn1/DerInteger.cs
@@ -209,6 +209,45 @@ namespace Org.BouncyCastle.Asn1 } } + public bool TryGetIntPositiveValueExact(out int value) + { + int count = bytes.Length - start; + if (count > 4 || (count == 4 && 0 != (bytes[start] & 0x80))) + { + value = default; + return false; + } + + value = IntValue(bytes, start, SignExtUnsigned); + return true; + } + + public bool TryGetIntValueExact(out int value) + { + int count = bytes.Length - start; + if (count > 4) + { + value = default; + return false; + } + + value = IntValue(bytes, start, SignExtSigned); + return true; + } + + public bool TryGetLongValueExact(out long value) + { + int count = bytes.Length - start; + if (count > 8) + { + value = default; + return false; + } + + value = LongValue(bytes, start, SignExtSigned); + return true; + } + internal override IAsn1Encoding GetEncoding(int encoding) { return new PrimitiveEncoding(Asn1Tags.Universal, Asn1Tags.Integer, bytes);