Skip to content

Commit

Permalink
Update JSON libraries (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrktkt authored Mar 10, 2021
1 parent 6f7ea9e commit 5d52013
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
8 changes: 4 additions & 4 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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))
}
}
8 changes: 7 additions & 1 deletion json/ninny/src/black/door/jose/json/ninny/JsonSupport.scala
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions json/ninny/test/src/black/door/jose/NinnyJsonJwtSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
})

Expand Down Expand Up @@ -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")
}
})

Expand Down
3 changes: 2 additions & 1 deletion json/play/src/black/door/jose/json/playjson/package.scala
Original file line number Diff line number Diff line change
@@ -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] =
Expand Down

0 comments on commit 5d52013

Please sign in to comment.