Resolve warnings for Kotlin ByteArray. (#3521)

This commit is contained in:
Chris Rankin 2018-07-05 13:00:29 +01:00 committed by GitHub
parent 35b2170b9c
commit 02978fc174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 10 additions and 11 deletions

View File

@ -17,7 +17,7 @@ import net.corda.finance.flows.CashPaymentFlow.PaymentRequest
open class EventGenerator(val parties: List<Party>, val currencies: List<Currency>, val notary: Party) {
protected val partyGenerator = Generator.pickOne(parties)
protected val issueRefGenerator = Generator.intRange(0, 1).map { number -> OpaqueBytes(ByteArray(1, { number.toByte() })) }
protected val issueRefGenerator = Generator.intRange(0, 1).map { number -> OpaqueBytes.of(number.toByte()) }
protected val amountGenerator = Generator.longRange(10000, 1000000)
protected val currencyGenerator = Generator.pickOne(currencies)
protected val currencyMap: MutableMap<Currency, Long> = mutableMapOf(USD to 0L, GBP to 0L) // Used for estimation of how much money we have in general.

View File

@ -5,7 +5,6 @@ import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder
import java.io.OutputStream
import java.math.BigInteger
import java.math.BigInteger.TEN
import java.security.KeyPairGenerator
import java.security.KeyStore

View File

@ -11,7 +11,7 @@ class PrivacySaltTest {
@Test
fun testValidSalt() {
PrivacySalt(ByteArray(SALT_SIZE, { 0x14 }))
PrivacySalt(ByteArray(SALT_SIZE) { 0x14 })
}
@Test
@ -22,13 +22,13 @@ class PrivacySaltTest {
@Test
fun testTooShortPrivacySalt() {
val ex = assertFailsWith<IllegalArgumentException> { PrivacySalt(ByteArray(SALT_SIZE - 1, { 0x7f })) }
val ex = assertFailsWith<IllegalArgumentException> { PrivacySalt(ByteArray(SALT_SIZE - 1) { 0x7f }) }
assertEquals("Privacy salt should be 32 bytes.", ex.message)
}
@Test
fun testTooLongPrivacySalt() {
val ex = assertFailsWith<IllegalArgumentException> { PrivacySalt(ByteArray(SALT_SIZE + 1, { 0x7f })) }
val ex = assertFailsWith<IllegalArgumentException> { PrivacySalt(ByteArray(SALT_SIZE + 1) { 0x7f }) }
assertEquals("Privacy salt should be 32 bytes.", ex.message)
}
}

View File

@ -33,7 +33,7 @@ class SecureHashTest {
@Test
fun testConstants() {
assertArrayEquals(SecureHash.zeroHash.bytes, ByteArray(32))
assertArrayEquals(SecureHash.allOnesHash.bytes, ByteArray(32, { 0xFF.toByte() }))
assertArrayEquals(SecureHash.allOnesHash.bytes, ByteArray(32) { 0xFF.toByte() })
}
}

View File

@ -90,7 +90,7 @@ sealed class SecureHash(bytes: ByteArray) : OpaqueBytes(bytes) {
* This field provides more intuitive access from Java.
*/
@JvmField
val zeroHash: SHA256 = SecureHash.SHA256(ByteArray(32, { 0.toByte() }))
val zeroHash: SHA256 = SecureHash.SHA256(ByteArray(32) { 0.toByte() })
/**
* A SHA-256 hash value consisting of 32 0x00 bytes.
@ -104,7 +104,7 @@ sealed class SecureHash(bytes: ByteArray) : OpaqueBytes(bytes) {
* This field provides more intuitive access from Java.
*/
@JvmField
val allOnesHash: SHA256 = SecureHash.SHA256(ByteArray(32, { 255.toByte() }))
val allOnesHash: SHA256 = SecureHash.SHA256(ByteArray(32) { 255.toByte() })
/**
* A SHA-256 hash value consisting of 32 0xFF bytes.

View File

@ -170,7 +170,7 @@ class KryoTests(private val compression: CordaSerializationEncoding?) {
@Test
fun `InputStream serialisation`() {
val rubbish = ByteArray(12345, { (it * it * 0.12345).toByte() })
val rubbish = ByteArray(12345) { (it * it * 0.12345).toByte() }
val readRubbishStream: InputStream = rubbish.inputStream().serialize(factory, context).deserialize(factory, context)
for (i in 0..12344) {
assertEquals(rubbish[i], readRubbishStream.read().toByte())
@ -208,7 +208,7 @@ class KryoTests(private val compression: CordaSerializationEncoding?) {
@Test
fun `HashCheckingStream (de)serialize`() {
val rubbish = ByteArray(12345, { (it * it * 0.12345).toByte() })
val rubbish = ByteArray(12345) { (it * it * 0.12345).toByte() }
val readRubbishStream: InputStream = NodeAttachmentService.HashCheckingStream(
SecureHash.sha256(rubbish),
rubbish.size,

View File

@ -170,7 +170,7 @@ class ExplorerSimulation(private val options: OptionSet) {
for (ref in 0..1) {
for ((currency, issuer) in issuers) {
val amount = Amount(1_000_000, currency)
issuer.startFlow(::CashIssueAndPaymentFlow, amount, OpaqueBytes(ByteArray(1, { ref.toByte() })),
issuer.startFlow(::CashIssueAndPaymentFlow, amount, OpaqueBytes.of( ref.toByte() ),
it, anonymous, notary).returnValue.getOrThrow()
}
}