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 <gpe@openrs2.org>
Graham 4 years ago
parent c10ab13181
commit a86f000f88
  1. 4
      crypto/src/main/kotlin/org/openrs2/crypto/IsaacRandom.kt
  2. 7
      crypto/src/main/kotlin/org/openrs2/crypto/NopStreamCipher.kt
  3. 5
      crypto/src/main/kotlin/org/openrs2/crypto/StreamCipher.kt

@ -1,6 +1,6 @@
package org.openrs2.crypto package org.openrs2.crypto
public class IsaacRandom { public class IsaacRandom : StreamCipher {
private var count = 0 private var count = 0
private val rsl: IntArray private val rsl: IntArray
private val mem = IntArray(SIZE) private val mem = IntArray(SIZE)
@ -257,7 +257,7 @@ public class IsaacRandom {
this.a = a this.a = a
} }
public fun nextInt(): Int { public override fun nextInt(): Int {
if (count-- == 0) { if (count-- == 0) {
isaac() isaac()
count = SIZE - 1 count = SIZE - 1

@ -0,0 +1,7 @@
package org.openrs2.crypto
public object NopStreamCipher : StreamCipher {
override fun nextInt(): Int {
return 0
}
}

@ -0,0 +1,5 @@
package org.openrs2.crypto
public interface StreamCipher {
public fun nextInt(): Int
}
Loading…
Cancel
Save