-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow
SignatureBundle
s to encapsulate plaintext (#67)
LTR-180
- Loading branch information
Showing
5 changed files
with
202 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/tech/relaycorp/veraid/SignatureBundleVerification.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package tech.relaycorp.veraid | ||
|
||
/** | ||
* Successful signature bundle verification. | ||
*/ | ||
public data class SignatureBundleVerification( | ||
/** | ||
* The plaintext whose signature was verified. | ||
*/ | ||
public val plaintext: ByteArray, | ||
|
||
/** | ||
* The member that produced the signature. | ||
*/ | ||
public val member: Member, | ||
) { | ||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
|
||
other as SignatureBundleVerification | ||
|
||
if (!plaintext.contentEquals(other.plaintext)) return false | ||
return member == other.member | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = plaintext.contentHashCode() | ||
result = 31 * result + member.hashCode() | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/test/kotlin/tech/relaycorp/veraid/SignatureBundleVerificationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package tech.relaycorp.veraid | ||
|
||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.shouldNotBe | ||
import org.junit.jupiter.api.Nested | ||
import org.junit.jupiter.api.Test | ||
|
||
class SignatureBundleVerificationTest { | ||
val verification = SignatureBundleVerification( | ||
"plaintext".toByteArray(), | ||
Member(ORG_NAME, USER_NAME), | ||
) | ||
|
||
@Nested | ||
inner class Equals { | ||
@Test | ||
@Suppress("ReplaceCallWithBinaryOperator") | ||
fun `The same object should equal`() { | ||
verification.equals(verification) shouldBe true | ||
} | ||
|
||
@Test | ||
fun `Null should not equal`() { | ||
verification.equals(null) shouldBe false | ||
} | ||
|
||
@Test | ||
fun `Different class should not equal`() { | ||
verification.equals("foo") shouldBe false | ||
} | ||
|
||
@Test | ||
fun `Different plaintext should not equal`() { | ||
verification shouldNotBe verification.copy(plaintext = "foo".toByteArray()) | ||
} | ||
|
||
@Test | ||
fun `Different member should not equal`() { | ||
val differentMember = verification.member.copy(orgName = "not-$ORG_NAME") | ||
|
||
verification shouldNotBe verification.copy(member = differentMember) | ||
} | ||
} | ||
|
||
@Test | ||
fun `Hashcode should compine member and plaintext`() { | ||
val constant = 31 | ||
val expectedHashCode = | ||
verification.member.hashCode() + constant * verification.plaintext.contentHashCode() | ||
|
||
verification.hashCode() shouldBe expectedHashCode | ||
} | ||
} |