Skip to content

Commit

Permalink
Merge pull request #46 from ReneeVandervelde/fix-chacha-result-equality
Browse files Browse the repository at this point in the history
Fix Equality Check in `XChaCha20EncryptionResult`
  • Loading branch information
ionspin authored Jun 15, 2024
2 parents da46a3c + 77445bb commit b919de5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ data class XChaCha20EncryptionResult(val nonce: UByteArray, val encryptionData:

other as XChaCha20EncryptionResult

if (nonce != other.nonce) return false
if (encryptionData != other.encryptionData) return false
if (!nonce.contentEquals(other.nonce)) return false
if (!encryptionData.contentEquals(other.encryptionData)) return false

return true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.iospin.kotlin.crypto.symmetric

import com.ionspin.kotlin.crypto.symmetric.XChaCha20EncryptionResult
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals

class XChaCha20EncryptionResultTest {
@Test
fun testEquality() {
val firstResult = XChaCha20EncryptionResult(
nonce = ubyteArrayOf(0x12u, 0x34u, 0x56u),
encryptionData = ubyteArrayOf(0x78u, 0x9Au),
)
val secondResult = XChaCha20EncryptionResult(
nonce = ubyteArrayOf(0x12u, 0x34u, 0x56u),
encryptionData = ubyteArrayOf(0x78u, 0x9Au),
)
val differingResult = XChaCha20EncryptionResult(
nonce = ubyteArrayOf(0u),
encryptionData = ubyteArrayOf(0u),
)

assertEquals(firstResult, secondResult)
assertNotEquals(firstResult, differingResult)
assertNotEquals(secondResult, differingResult)
}
}

0 comments on commit b919de5

Please sign in to comment.