From 6db89e38961ffefb919fb3d34bee4a189f08237e Mon Sep 17 00:00:00 2001 From: Martin Zachrison Date: Sun, 24 Aug 2025 17:57:21 +0200 Subject: [PATCH] Add `AesAppSpec` for comprehensive AES encryption/decryption tests and streamline imports in `DefaultAppSpec`. --- core/src/test/scala/app/AesAppSpec.scala | 38 ++++++++++++++++++++ core/src/test/scala/app/DefaultAppSpec.scala | 1 - 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 core/src/test/scala/app/AesAppSpec.scala diff --git a/core/src/test/scala/app/AesAppSpec.scala b/core/src/test/scala/app/AesAppSpec.scala new file mode 100644 index 0000000..b70467e --- /dev/null +++ b/core/src/test/scala/app/AesAppSpec.scala @@ -0,0 +1,38 @@ +package app + +import org.scalatest.TryValues +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +import scala.util.{Success, Try} + +class AesAppSpec extends AnyFlatSpec with Matchers with TryValues: + + import cryptic.{*, given} + import cryptic.codec.default.given + import cryptic.crypto.Aes.{*, given} + + given passphrase: Passphrase = Passphrase("correct horse") + val clear = "secret" + val encrypted: Encrypted[String] = clear.encrypted + val decrypted: Try[String] = encrypted.decrypted + + "Cryptic" should "encrypt" in: + encrypted.bytes should not equal clear.getBytes + + "Cryptic" should "decrypt" in: + decrypted.success shouldEqual Success(clear) + + case class Person(id: Long, email: Encrypted[String]) + + val id = 17 + val email = "martin@scalacrypto.org" + val person: Person = Person(id, email.encrypted) + + "Email" should "be encrypted" in: + person.email.bytes.unsafeArray should not equal email.getBytes() + person.email.contains(email) shouldBe true + person.toString should startWith("Person(17,Encrypted(CipherText(0x") + + "Email" should "be decrypted" in: + person.email.decrypted.success shouldEqual Success(email) diff --git a/core/src/test/scala/app/DefaultAppSpec.scala b/core/src/test/scala/app/DefaultAppSpec.scala index d3ef769..7404749 100644 --- a/core/src/test/scala/app/DefaultAppSpec.scala +++ b/core/src/test/scala/app/DefaultAppSpec.scala @@ -1,6 +1,5 @@ package app -import cryptic.crypto.Aes.{*, given} import org.scalatest.TryValues import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers