From 4802f833909cb5a30439600ae370429bb89c27fe Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 24 Jul 2014 13:14:36 +0700 Subject: Add more variations of check/isValid --- .../java/org/bouncycastle/crypto/tls/TlsUtils.java | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/core/src/main/java/org/bouncycastle/crypto/tls/TlsUtils.java b/core/src/main/java/org/bouncycastle/crypto/tls/TlsUtils.java index a1cf9d4b..552486b3 100644 --- a/core/src/main/java/org/bouncycastle/crypto/tls/TlsUtils.java +++ b/core/src/main/java/org/bouncycastle/crypto/tls/TlsUtils.java @@ -63,6 +63,14 @@ public class TlsUtils } } + public static void checkUint8(long i) throws IOException + { + if (!isValidUint8(i)) + { + throw new TlsFatalAlert(AlertDescription.internal_error); + } + } + public static void checkUint16(int i) throws IOException { if (!isValidUint16(i)) @@ -71,6 +79,14 @@ public class TlsUtils } } + public static void checkUint16(long i) throws IOException + { + if (!isValidUint16(i)) + { + throw new TlsFatalAlert(AlertDescription.internal_error); + } + } + public static void checkUint24(int i) throws IOException { if (!isValidUint24(i)) @@ -79,6 +95,14 @@ public class TlsUtils } } + public static void checkUint24(long i) throws IOException + { + if (!isValidUint24(i)) + { + throw new TlsFatalAlert(AlertDescription.internal_error); + } + } + public static void checkUint32(long i) throws IOException { if (!isValidUint32(i)) @@ -113,16 +137,31 @@ public class TlsUtils return (i & 0xFF) == i; } + public static boolean isValidUint8(long i) + { + return (i & 0xFFL) == i; + } + public static boolean isValidUint16(int i) { return (i & 0xFFFF) == i; } + public static boolean isValidUint16(long i) + { + return (i & 0xFFFFL) == i; + } + public static boolean isValidUint24(int i) { return (i & 0xFFFFFF) == i; } + public static boolean isValidUint24(long i) + { + return (i & 0xFFFFFFL) == i; + } + public static boolean isValidUint32(long i) { return (i & 0xFFFFFFFFL) == i; -- cgit v1.2.3