From 5d52013ec021400def1474a20c3be6e6eebfaa81 Mon Sep 17 00:00:00 2001 From: Nathaniel Fischer Date: Tue, 9 Mar 2021 18:33:34 -0800 Subject: [PATCH] Update JSON libraries (#38) --- build.sc | 8 ++++---- .../src/black/door/jose/json/ninny/JsonSupport.scala | 8 +++++++- .../test/src/black/door/jose/NinnyJsonJwtSpec.scala | 7 ++++--- .../door/jose/json/playjson/jwk/JwkJsonSupport.scala | 10 +++++----- .../src/black/door/jose/json/playjson/package.scala | 3 ++- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/build.sc b/build.sc index f4a92fd..36bfffc 100644 --- a/build.sc +++ b/build.sc @@ -5,8 +5,8 @@ import scalalib._ val devInfo = Developer("kag0", "Nathan Fischer", "https://github.com/kag0", Some("blackdoor"), Some("https://github.com/blackdoor")) -val `2.12` = "2.12.12" -val `2.13` = "2.13.3" +val `2.12` = "2.12.13" +val `2.13` = "2.13.5" trait BaseModule extends CrossScalaModule { def scalacOptions = Seq("-Xfatal-warnings", "-feature", "-unchecked", "-deprecation") @@ -71,13 +71,13 @@ object json extends Module { object play extends Cross[PlayModule](`2.12`, `2.13`) class PlayModule(val crossScalaVersion: String) extends JsonModule("Play") with PublishModule { - def ivyDeps = Agg(ivy"com.typesafe.play::play-json:2.7.4") + def ivyDeps = Agg(ivy"com.typesafe.play::play-json:2.9.2") def moduleDeps = List(jose(crossScalaVersion)) } object ninny extends Cross[NinnyModule](`2.12`, `2.13`) class NinnyModule(val crossScalaVersion: String) extends JsonModule("ninny") with PublishModule { - def ivyDeps = Agg(ivy"io.github.kag0::ninny:0.2.1", ivy"org.scala-lang.modules::scala-collection-compat:2.2.0") + def ivyDeps = Agg(ivy"io.github.kag0::ninny:0.2.10", ivy"org.scala-lang.modules::scala-collection-compat:2.2.0") def moduleDeps = List(jose(crossScalaVersion)) } } diff --git a/json/ninny/src/black/door/jose/json/ninny/JsonSupport.scala b/json/ninny/src/black/door/jose/json/ninny/JsonSupport.scala index 0153c38..347dd3b 100644 --- a/json/ninny/src/black/door/jose/json/ninny/JsonSupport.scala +++ b/json/ninny/src/black/door/jose/json/ninny/JsonSupport.scala @@ -1,4 +1,10 @@ package black.door.jose.json.ninny -trait JsonSupport extends JwkJsonSupport with JwsJsonSupport with JwtJsonSupport +import io.github.kag0.ninny.ToSomeJsonObject +import io.github.kag0.ninny.ast.JsonObject + +trait JsonSupport extends JwkJsonSupport with JwsJsonSupport with JwtJsonSupport { + implicit val unitToCustomClaim: ToSomeJsonObject[Unit] = _ => JsonObject(Map.empty) +} + object JsonSupport extends JsonSupport diff --git a/json/ninny/test/src/black/door/jose/NinnyJsonJwtSpec.scala b/json/ninny/test/src/black/door/jose/NinnyJsonJwtSpec.scala index 3d4d54d..4896f50 100644 --- a/json/ninny/test/src/black/door/jose/NinnyJsonJwtSpec.scala +++ b/json/ninny/test/src/black/door/jose/NinnyJsonJwtSpec.scala @@ -2,12 +2,13 @@ package black.door.jose import black.door.jose.json.ninny.JsonSupport import black.door.jose.jwt.Claims -import io.github.kag0.ninny.Auto._ class NinnyJsonJwtSpec extends JwtSpec with JsonSupport { - val payloadUnitSerializer = implicitly[ByteSerializer[Claims[Unit]]] - val payloadUnitDeserializer = implicitly[ByteDeserializer[Claims[Unit]]] + val payloadUnitSerializer = implicitly[ByteSerializer[Claims[Unit]]] + val payloadUnitDeserializer = implicitly[ByteDeserializer[Claims[Unit]]] + + import io.github.kag0.ninny.Auto._ val payloadCustomDeserializer = implicitly[ByteDeserializer[Claims[MyCustomClaimsClass]]] val payloadCustomSerializer = implicitly[ByteSerializer[Claims[MyCustomClaimsClass]]] } diff --git a/json/play/src/black/door/jose/json/playjson/jwk/JwkJsonSupport.scala b/json/play/src/black/door/jose/json/playjson/jwk/JwkJsonSupport.scala index 4c78c50..b2570b8 100644 --- a/json/play/src/black/door/jose/json/playjson/jwk/JwkJsonSupport.scala +++ b/json/play/src/black/door/jose/json/playjson/jwk/JwkJsonSupport.scala @@ -28,11 +28,11 @@ trait JwkJsonSupport { obj \ "crv" match { case JsDefined(JsString("P-256")) => obj \ "d" match { - case JsDefined(_) => p256KeyPairReads.reads(obj) - case JsUndefined() => p256PublicKeyReads.reads(obj) + case JsDefined(_) => p256KeyPairReads.reads(obj) + case _ => p256PublicKeyReads.reads(obj) } - case JsDefined(_) => JsError(path \ "crv", "JWK does not have a supported curve") - case JsUndefined() => JsError(path \ "crv", "JWK does not have a defined curve") + case JsDefined(_) => JsError(path \ "crv", "JWK does not have a supported curve") + case _ => JsError(path \ "crv", "JWK does not have a defined curve") } }) @@ -71,7 +71,7 @@ trait JwkJsonSupport { case JsDefined(JsString("RSA")) => rsaJwkReads.reads(obj) case JsDefined(JsString("oct")) => octJwkFormat.reads(obj) case JsDefined(_) => JsError(path \ "kty", "JWK does not have a supported key type") - case JsUndefined() => JsError(path \ "kty", "JWK does not have a defined key type") + case _ => JsError(path \ "kty", "JWK does not have a defined key type") } }) diff --git a/json/play/src/black/door/jose/json/playjson/package.scala b/json/play/src/black/door/jose/json/playjson/package.scala index e68bb73..93a2bc6 100644 --- a/json/play/src/black/door/jose/json/playjson/package.scala +++ b/json/play/src/black/door/jose/json/playjson/package.scala @@ -1,9 +1,10 @@ package black.door.jose.json -import java.nio.charset.StandardCharsets import black.door.jose.{ByteDeserializer, ByteSerializer} import play.api.libs.json.{Json, Reads, Writes} +import java.nio.charset.StandardCharsets + package object playjson { def jsonSerializer[A](implicit writes: Writes[A]): ByteSerializer[A] =