From a86f000f88b7d02dc058aa477e62f6aec4c83190 Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 10 Nov 2020 20:45:41 +0000 Subject: [PATCH] Add StreamCipher interface and a NopStreamCipher implementation This will allow us to replace IsaacRandom in the future Netty encoders/decoders with an implementation suitable for use in a unit test. Signed-off-by: Graham --- crypto/src/main/kotlin/org/openrs2/crypto/IsaacRandom.kt | 4 ++-- .../src/main/kotlin/org/openrs2/crypto/NopStreamCipher.kt | 7 +++++++ crypto/src/main/kotlin/org/openrs2/crypto/StreamCipher.kt | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 crypto/src/main/kotlin/org/openrs2/crypto/NopStreamCipher.kt create mode 100644 crypto/src/main/kotlin/org/openrs2/crypto/StreamCipher.kt diff --git a/crypto/src/main/kotlin/org/openrs2/crypto/IsaacRandom.kt b/crypto/src/main/kotlin/org/openrs2/crypto/IsaacRandom.kt index df561ab3..75f3e3cd 100644 --- a/crypto/src/main/kotlin/org/openrs2/crypto/IsaacRandom.kt +++ b/crypto/src/main/kotlin/org/openrs2/crypto/IsaacRandom.kt @@ -1,6 +1,6 @@ package org.openrs2.crypto -public class IsaacRandom { +public class IsaacRandom : StreamCipher { private var count = 0 private val rsl: IntArray private val mem = IntArray(SIZE) @@ -257,7 +257,7 @@ public class IsaacRandom { this.a = a } - public fun nextInt(): Int { + public override fun nextInt(): Int { if (count-- == 0) { isaac() count = SIZE - 1 diff --git a/crypto/src/main/kotlin/org/openrs2/crypto/NopStreamCipher.kt b/crypto/src/main/kotlin/org/openrs2/crypto/NopStreamCipher.kt new file mode 100644 index 00000000..8b79013d --- /dev/null +++ b/crypto/src/main/kotlin/org/openrs2/crypto/NopStreamCipher.kt @@ -0,0 +1,7 @@ +package org.openrs2.crypto + +public object NopStreamCipher : StreamCipher { + override fun nextInt(): Int { + return 0 + } +} diff --git a/crypto/src/main/kotlin/org/openrs2/crypto/StreamCipher.kt b/crypto/src/main/kotlin/org/openrs2/crypto/StreamCipher.kt new file mode 100644 index 00000000..61ff1abb --- /dev/null +++ b/crypto/src/main/kotlin/org/openrs2/crypto/StreamCipher.kt @@ -0,0 +1,5 @@ +package org.openrs2.crypto + +public interface StreamCipher { + public fun nextInt(): Int +}