From 67f4bdea7085f3d46ab4379a6ae2f618f4b30d7a Mon Sep 17 00:00:00 2001 From: colin-lamed <9568290+colin-lamed@users.noreply.github.com> Date: Mon, 22 Aug 2022 16:03:57 +0100 Subject: [PATCH] Fix Crypted.toBase64 --- .../main/scala/uk/gov/hmrc/crypto/model.scala | 2 +- .../scala/uk/gov/hmrc/crypto/ModelSpec.scala | 29 +++++++++++++++++++ project/build.properties | 2 +- project/plugins.sbt | 2 +- 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 crypto/src/test/scala/uk/gov/hmrc/crypto/ModelSpec.scala diff --git a/crypto/src/main/scala/uk/gov/hmrc/crypto/model.scala b/crypto/src/main/scala/uk/gov/hmrc/crypto/model.scala index a909b51..c470eae 100644 --- a/crypto/src/main/scala/uk/gov/hmrc/crypto/model.scala +++ b/crypto/src/main/scala/uk/gov/hmrc/crypto/model.scala @@ -54,7 +54,7 @@ case class PlainBytes(value: Array[Byte]) extends PlainContent case class Crypted(value: String) { def toBase64 = - Base64.getDecoder.decode(value.getBytes("UTF-8")) + Base64.getEncoder.encode(value.getBytes("UTF-8")) } object Crypted extends (String => Crypted) { diff --git a/crypto/src/test/scala/uk/gov/hmrc/crypto/ModelSpec.scala b/crypto/src/test/scala/uk/gov/hmrc/crypto/ModelSpec.scala new file mode 100644 index 0000000..345e6d7 --- /dev/null +++ b/crypto/src/test/scala/uk/gov/hmrc/crypto/ModelSpec.scala @@ -0,0 +1,29 @@ +/* + * Copyright 2022 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package uk.gov.hmrc.crypto + +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike + +class ModelSpec extends AnyWordSpecLike with Matchers { + "Crypted" should { + "encode and decode Base64" in { + val encrypted = Crypted("") + Crypted.fromBase64(new String(encrypted.toBase64)).value shouldBe encrypted.value + } + } +} diff --git a/project/build.properties b/project/build.properties index e64c208..c8fcab5 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.5.8 +sbt.version=1.6.2 diff --git a/project/plugins.sbt b/project/plugins.sbt index 7721c8b..b50ff88 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.7.0") +addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.8.0")