diff --git a/README.md b/README.md index f226a04..ba7cf90 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,10 @@ val optValue: Option[T] = decrypter.reads(encryptedValue).asOpt.map(_.decryptedV ## Changes +### Version 8.0.0 + +Built for Scala 3 and Scala 2.13 - drops Scala 2.12. + ### Version 7.6.0 Adds support for Play 2.9 and Play 3.0 diff --git a/build.sbt b/build.sbt index 81aba32..4fe9863 100644 --- a/build.sbt +++ b/build.sbt @@ -1,7 +1,7 @@ -val scala2_12 = "2.12.18" val scala2_13 = "2.13.12" +val scala3 = "3.3.3" -ThisBuild / majorVersion := 7 +ThisBuild / majorVersion := 8 ThisBuild / scalaVersion := scala2_13 ThisBuild / isPublicArtefact := true ThisBuild / scalacOptions ++= Seq("-feature") @@ -17,7 +17,7 @@ lazy val library = Project("library", file(".")) lazy val crypto = Project("crypto", file("crypto")) .settings( - crossScalaVersions := Seq(scala2_12, scala2_13), + crossScalaVersions := Seq(scala2_13, scala3), libraryDependencies ++= LibDependencies.cryptoCompile ++ LibDependencies.cryptoTest ) @@ -30,7 +30,7 @@ def shareSources(location: String) = Seq( lazy val cryptoJsonPlay28 = Project("crypto-json-play-28", file("crypto-json-play-28")) .settings( - crossScalaVersions := Seq(scala2_12, scala2_13), + crossScalaVersions := Seq(scala2_13), shareSources("crypto-json"), libraryDependencies ++= LibDependencies.cryptoJsonPlay28Compile ++ LibDependencies.cryptoTest ).dependsOn(crypto) @@ -44,7 +44,7 @@ lazy val cryptoJsonPlay29 = Project("crypto-json-play-29", file("crypto-json-pla lazy val cryptoJsonPlay30 = Project("crypto-json-play-30", file("crypto-json-play-30")) .settings( - crossScalaVersions := Seq(scala2_13), + crossScalaVersions := Seq(scala2_13, scala3), shareSources("crypto-json"), libraryDependencies ++= LibDependencies.cryptoJsonPlay30Compile ++ LibDependencies.cryptoTest ).dependsOn(crypto) diff --git a/crypto-json/src/main/scala/uk/gov/hmrc/crypto/json/CryptoFormats.scala b/crypto-json/src/main/scala/uk/gov/hmrc/crypto/json/CryptoFormats.scala index eda2df0..2e37d2f 100644 --- a/crypto-json/src/main/scala/uk/gov/hmrc/crypto/json/CryptoFormats.scala +++ b/crypto-json/src/main/scala/uk/gov/hmrc/crypto/json/CryptoFormats.scala @@ -25,5 +25,5 @@ object CryptoFormats { val encryptedValueFormat: Format[EncryptedValue] = ( (__ \ "value").format[String] ~ (__ \ "nonce").format[String] - )(EncryptedValue.apply, unlift(EncryptedValue.unapply)) + )(EncryptedValue.apply, ev => (ev.value, ev.nonce)) } diff --git a/crypto-json/src/test/scala/uk/gov/hmrc/crypto/json/JsonEncryptionSpec.scala b/crypto-json/src/test/scala/uk/gov/hmrc/crypto/json/JsonEncryptionSpec.scala index 3db4f7c..53846eb 100644 --- a/crypto-json/src/test/scala/uk/gov/hmrc/crypto/json/JsonEncryptionSpec.scala +++ b/crypto-json/src/test/scala/uk/gov/hmrc/crypto/json/JsonEncryptionSpec.scala @@ -84,7 +84,8 @@ class CryptoFormatsSpec } object CryptoFormatsSpec { - implicit val crypto = SymmetricCryptoFactory.aesCrypto("P5xsJ9Nt+quxGZzB4DeLfw==") + implicit val crypto: Encrypter with Decrypter = + SymmetricCryptoFactory.aesCrypto("P5xsJ9Nt+quxGZzB4DeLfw==") case class SensitiveTestEntity( normalString : String, @@ -94,7 +95,7 @@ object CryptoFormatsSpec { ) object SensitiveTestEntity { - implicit val formats = { + implicit val formats: Format[SensitiveTestEntity] = { implicit val sensitiveStringCrypto : Format[SensitiveString] = JsonEncryption.sensitiveEncrypterDecrypter(SensitiveString.apply) implicit val sensitiveBooleanCrypto : Format[SensitiveBoolean] = JsonEncryption.sensitiveEncrypterDecrypter(SensitiveBoolean.apply) implicit val sensitiveBigDecimalCrypto: Format[SensitiveBigDecimal] = JsonEncryption.sensitiveEncrypterDecrypter(SensitiveBigDecimal.apply) @@ -110,7 +111,8 @@ object CryptoFormatsSpec { ) object TestForm { - implicit val formats = Json.format[TestForm] + implicit val formats: Format[TestForm] = + Json.format[TestForm] } case class SensitiveTestForm(override val decryptedValue: TestForm) extends Sensitive[TestForm] diff --git a/crypto/src/main/scala/uk/gov/hmrc/crypto/AesCrypto.scala b/crypto/src/main/scala/uk/gov/hmrc/crypto/AesCrypto.scala index ff2e78d..27909d8 100644 --- a/crypto/src/main/scala/uk/gov/hmrc/crypto/AesCrypto.scala +++ b/crypto/src/main/scala/uk/gov/hmrc/crypto/AesCrypto.scala @@ -38,7 +38,6 @@ trait AesCrypto extends Encrypter with Decrypter { plain match { case PlainBytes(bytes) => Crypted(encrypter.encrypt(bytes)) case PlainText(text) => Crypted(encrypter.encrypt(text)) - case _ => throw new Exception(s"Unable to encrypt unkown message type: $plain") } override def decrypt(encrypted: Crypted): PlainText = diff --git a/crypto/src/main/scala/uk/gov/hmrc/crypto/AesGCMCrypto.scala b/crypto/src/main/scala/uk/gov/hmrc/crypto/AesGCMCrypto.scala index ca450ad..7b347e1 100644 --- a/crypto/src/main/scala/uk/gov/hmrc/crypto/AesGCMCrypto.scala +++ b/crypto/src/main/scala/uk/gov/hmrc/crypto/AesGCMCrypto.scala @@ -40,7 +40,6 @@ trait AesGCMCrypto extends Encrypter with Decrypter { plain match { case PlainBytes(bytes) => Crypted(fromEncryptedValue(crypto.encrypt(bytes , emptyAssociatedData))) case PlainText(text) => Crypted(fromEncryptedValue(crypto.encrypt(text.getBytes, emptyAssociatedData))) - case _ => throw new RuntimeException(s"Unable to encrypt unknown message type: $plain") } private def fromEncryptedValue(ev: EncryptedBytes): String = { diff --git a/crypto/src/main/scala/uk/gov/hmrc/crypto/CompositeSymmetricCrypto.scala b/crypto/src/main/scala/uk/gov/hmrc/crypto/CompositeSymmetricCrypto.scala index 87d68a4..ad8257e 100644 --- a/crypto/src/main/scala/uk/gov/hmrc/crypto/CompositeSymmetricCrypto.scala +++ b/crypto/src/main/scala/uk/gov/hmrc/crypto/CompositeSymmetricCrypto.scala @@ -35,7 +35,7 @@ trait CompositeSymmetricCrypto extends Encrypter with Decrypter { decrypt(d => Try(d.decryptAsBytes(scrambled))) private def decrypt[T <: PlainContent](tryDecryption: Decrypter => Try[T]): T = { - val decrypterStream = (currentCrypto +: previousCryptos).toStream + val decrypterStream = (currentCrypto +: previousCryptos).to(LazyList) val message = decrypterStream diff --git a/crypto/src/main/scala/uk/gov/hmrc/crypto/SymmetricCryptoFactory.scala b/crypto/src/main/scala/uk/gov/hmrc/crypto/SymmetricCryptoFactory.scala index b7b1a83..b881033 100644 --- a/crypto/src/main/scala/uk/gov/hmrc/crypto/SymmetricCryptoFactory.scala +++ b/crypto/src/main/scala/uk/gov/hmrc/crypto/SymmetricCryptoFactory.scala @@ -37,7 +37,7 @@ object SymmetricCryptoFactory { decrypt(d => Try(d.decryptAsBytes(scrambled))) private def decrypt[T <: PlainContent](tryDecryption: Decrypter => Try[T]): T = { - val decrypterStream = (currentCrypto +: previousDecrypters).toStream + val decrypterStream = (currentCrypto +: previousDecrypters).to(LazyList) decrypterStream .map(tryDecryption) .collectFirst { case Success(msg) => msg } @@ -95,7 +95,7 @@ object SymmetricCryptoFactory { currentCrypto.encrypt(valueToEncrypt, associatedText) override def decrypt(valueToDecrypt: EncryptedValue, associatedText: String): String = { - val decrypterStream = (currentCrypto +: previousDecrypters).toStream + val decrypterStream = (currentCrypto +: previousDecrypters).to(LazyList) decrypterStream .map(crypter => Try(crypter.decrypt(valueToDecrypt, associatedText))) .collectFirst { case Success(msg) => msg } diff --git a/crypto/src/main/scala/uk/gov/hmrc/crypto/ValueFinder.scala b/crypto/src/main/scala/uk/gov/hmrc/crypto/ValueFinder.scala index 51c17ce..0dde912 100644 --- a/crypto/src/main/scala/uk/gov/hmrc/crypto/ValueFinder.scala +++ b/crypto/src/main/scala/uk/gov/hmrc/crypto/ValueFinder.scala @@ -17,7 +17,7 @@ package uk.gov.hmrc.crypto import com.typesafe.config.Config -import collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.util.Try diff --git a/crypto/src/test/scala/uk/gov/hmrc/crypto/ApplicationCryptoSpec.scala b/crypto/src/test/scala/uk/gov/hmrc/crypto/ApplicationCryptoSpec.scala index 7415a5d..8e5e42d 100644 --- a/crypto/src/test/scala/uk/gov/hmrc/crypto/ApplicationCryptoSpec.scala +++ b/crypto/src/test/scala/uk/gov/hmrc/crypto/ApplicationCryptoSpec.scala @@ -20,7 +20,7 @@ import com.typesafe.config.ConfigFactory import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpecLike -import collection.JavaConverters._ +import scala.jdk.CollectionConverters._ class ApplicationCryptoSpec extends AnyWordSpecLike with Matchers { diff --git a/crypto/src/test/scala/uk/gov/hmrc/crypto/CompositeOneWayCryptoSpec.scala b/crypto/src/test/scala/uk/gov/hmrc/crypto/CompositeOneWayCryptoSpec.scala index e0e8a66..59d8712 100644 --- a/crypto/src/test/scala/uk/gov/hmrc/crypto/CompositeOneWayCryptoSpec.scala +++ b/crypto/src/test/scala/uk/gov/hmrc/crypto/CompositeOneWayCryptoSpec.scala @@ -17,12 +17,12 @@ package uk.gov.hmrc.crypto import com.typesafe.config.ConfigFactory -import org.mockito.MockitoSugar import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpecLike +import org.scalatestplus.mockito.MockitoSugar import java.util.Base64 -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ @annotation.nowarn("msg=deprecated") class CompositeOneWayCryptoSpec extends AnyWordSpecLike with Matchers with MockitoSugar { diff --git a/crypto/src/test/scala/uk/gov/hmrc/crypto/CryptoGCMWithKeysFromConfigSpec.scala b/crypto/src/test/scala/uk/gov/hmrc/crypto/CryptoGCMWithKeysFromConfigSpec.scala index 8f735d3..098ee0a 100644 --- a/crypto/src/test/scala/uk/gov/hmrc/crypto/CryptoGCMWithKeysFromConfigSpec.scala +++ b/crypto/src/test/scala/uk/gov/hmrc/crypto/CryptoGCMWithKeysFromConfigSpec.scala @@ -17,13 +17,13 @@ package uk.gov.hmrc.crypto import com.typesafe.config.ConfigFactory -import org.mockito.MockitoSugar import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpecLike +import org.scalatestplus.mockito.MockitoSugar import java.security.SecureRandom import java.util.Base64 -import collection.JavaConverters._ +import scala.jdk.CollectionConverters._ @annotation.nowarn("msg=deprecated") class CryptoGCMWithKeysFromConfigSpec extends AnyWordSpecLike with Matchers with MockitoSugar { diff --git a/crypto/src/test/scala/uk/gov/hmrc/crypto/CryptoWithKeysFromConfigSpec.scala b/crypto/src/test/scala/uk/gov/hmrc/crypto/CryptoWithKeysFromConfigSpec.scala index 9120dcf..f6de568 100644 --- a/crypto/src/test/scala/uk/gov/hmrc/crypto/CryptoWithKeysFromConfigSpec.scala +++ b/crypto/src/test/scala/uk/gov/hmrc/crypto/CryptoWithKeysFromConfigSpec.scala @@ -17,12 +17,12 @@ package uk.gov.hmrc.crypto import com.typesafe.config.ConfigFactory -import org.mockito.MockitoSugar import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpecLike +import org.scalatestplus.mockito.MockitoSugar import java.util.Base64 -import collection.JavaConverters._ +import scala.jdk.CollectionConverters._ @annotation.nowarn("msg=deprecated") class CryptoWithKeysFromConfigSpec extends AnyWordSpecLike with Matchers with MockitoSugar { diff --git a/project/LibDependencies.scala b/project/LibDependencies.scala index d6f2d36..7ddfe58 100644 --- a/project/LibDependencies.scala +++ b/project/LibDependencies.scala @@ -11,18 +11,18 @@ object LibDependencies { "org.scalatest" %% "scalatest" % "3.2.17" % Test, "com.vladsch.flexmark" % "flexmark-all" % "0.64.8" % Test, "org.scalatestplus" %% "scalacheck-1-17" % "3.2.17.0" % Test, - "org.mockito" %% "mockito-scala" % "1.17.29" % Test + "org.scalatestplus" %% "mockito-3-4" % "3.2.10.0" % Test ) val cryptoJsonPlay28Compile = Seq( - "com.typesafe.play" %% "play-json" % "2.8.1" // version provided by Play 2.8 + "com.typesafe.play" %% "play-json" % "2.8.2" // version provided by Play 2.8 ) val cryptoJsonPlay29Compile = Seq( - "com.typesafe.play" %% "play-json" % "2.10.2" // version provided by Play 2.9 + "com.typesafe.play" %% "play-json" % "2.10.5" // version provided by Play 2.9 ) val cryptoJsonPlay30Compile = Seq( - "org.playframework" %% "play-json" % "3.0.0" // version provided by Play 3.0 + "org.playframework" %% "play-json" % "3.0.3" // version provided by Play 3.0 ) } diff --git a/project/build.properties b/project/build.properties index e8a1e24..04267b1 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.7 +sbt.version=1.9.9 diff --git a/project/plugins.sbt b/project/plugins.sbt index 993acb0..e8fc669 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,4 @@ resolvers += MavenRepository("HMRC-open-artefacts-maven2", "https://open.artefacts.tax.service.gov.uk/maven2") resolvers += Resolver.url("HMRC-open-artefacts-ivy2", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns) -addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.15.0") +addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.21.0")