From 2d53cf14aeda106a550b15e8aa8c813fad2fffea Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 24 Jul 2014 13:15:24 +0700 Subject: Add more variations of Check/IsValid --- crypto/src/crypto/tls/TlsUtilities.cs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crypto/src/crypto/tls/TlsUtilities.cs b/crypto/src/crypto/tls/TlsUtilities.cs index f07626852..08fb6f0a4 100644 --- a/crypto/src/crypto/tls/TlsUtilities.cs +++ b/crypto/src/crypto/tls/TlsUtilities.cs @@ -25,18 +25,36 @@ namespace Org.BouncyCastle.Crypto.Tls throw new TlsFatalAlert(AlertDescription.internal_error); } + public static void CheckUint8(long i) + { + if (!IsValidUint8(i)) + throw new TlsFatalAlert(AlertDescription.internal_error); + } + public static void CheckUint16(int i) { if (!IsValidUint16(i)) throw new TlsFatalAlert(AlertDescription.internal_error); } + public static void CheckUint16(long i) + { + if (!IsValidUint16(i)) + throw new TlsFatalAlert(AlertDescription.internal_error); + } + public static void CheckUint24(int i) { if (!IsValidUint24(i)) throw new TlsFatalAlert(AlertDescription.internal_error); } + public static void CheckUint24(long i) + { + if (!IsValidUint24(i)) + throw new TlsFatalAlert(AlertDescription.internal_error); + } + public static void CheckUint32(long i) { if (!IsValidUint32(i)) @@ -60,15 +78,31 @@ namespace Org.BouncyCastle.Crypto.Tls return (i & 0xFF) == i; } + public static bool IsValidUint8(long i) + { + return (i & 0xFFL) == i; + } + public static bool IsValidUint16(int i) { return (i & 0xFFFF) == i; } + public static bool IsValidUint16(long i) + { + return (i & 0xFFFFL) == i; + } + public static bool IsValidUint24(int i) { return (i & 0xFFFFFF) == i; } + + public static bool IsValidUint24(long i) + { + return (i & 0xFFFFFFL) == i; + } + public static bool IsValidUint32(long i) { return (i & 0xFFFFFFFFL) == i; -- cgit 1.5.1