diff --git a/.scalafmt.conf b/.scalafmt.conf index 60f578d..a5f80a8 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = 2.2.2 +version = 2.7.5 style = defaultWithAlign maxColumn = 160 align.openParenCallSite = false diff --git a/build.sbt b/build.sbt index d4da680..1400ded 100644 --- a/build.sbt +++ b/build.sbt @@ -7,16 +7,16 @@ libraryDependencies ++= { val akkaHttpV = "10.2.1" Seq( - "com.pauldijou" %% "jwt-core" % "4.3.0", - "org.apache.httpcomponents" % "fluent-hc" % "4.5.13", - "org.bouncycastle" % "bcprov-jdk15on" % "1.67", - "com.typesafe.akka" %% "akka-actor" % akkaV, - "com.typesafe.akka" %% "akka-stream" % akkaV, - "com.typesafe.akka" %% "akka-stream-testkit" % akkaV % Test, - "com.typesafe.akka" %% "akka-http" % akkaHttpV, - "com.typesafe.akka" %% "akka-http-testkit" % akkaHttpV % Test, - "org.scalatest" %% "scalatest" % "3.3.0-SNAP2" % Test, - "com.github.tomakehurst" % "wiremock" % "2.27.2" % Test, + "com.pauldijou" %% "jwt-core" % "4.3.0", + "org.apache.httpcomponents" % "fluent-hc" % "4.5.13", + "org.bouncycastle" % "bcprov-jdk15on" % "1.67", + "com.typesafe.akka" %% "akka-actor" % akkaV, + "com.typesafe.akka" %% "akka-stream" % akkaV, + "com.typesafe.akka" %% "akka-stream-testkit" % akkaV % Test, + "com.typesafe.akka" %% "akka-http" % akkaHttpV, + "com.typesafe.akka" %% "akka-http-testkit" % akkaHttpV % Test, + "org.scalatest" %% "scalatest" % "3.3.0-SNAP2" % Test, + "com.github.tomakehurst" % "wiremock" % "2.27.2" % Test, ) } @@ -45,10 +45,10 @@ publishTo in ThisBuild := { scmInfo := Some( ScmInfo( url("https://github.com/TeamWanari/web-push"), - "scm:git:git@github.com:TeamWanari/web-push.git" - ) + "scm:git:git@github.com:TeamWanari/web-push.git", + ), ) developers := List( - Developer("Csabi", "Csaba Pálfi", "csibcsab@wanari.com", url("https://www.wanari.com")) + Developer("Csabi", "Csaba Pálfi", "csibcsab@wanari.com", url("https://www.wanari.com")), ) diff --git a/src/main/scala/com/wanari/webpush/Encryption.scala b/src/main/scala/com/wanari/webpush/Encryption.scala index 0212bfd..dd24874 100644 --- a/src/main/scala/com/wanari/webpush/Encryption.scala +++ b/src/main/scala/com/wanari/webpush/Encryption.scala @@ -5,8 +5,7 @@ import java.security.{KeyPairGenerator, PublicKey, SecureRandom} import org.bouncycastle.jce.ECNamedCurveTable import org.bouncycastle.jce.provider.BouncyCastleProvider -/** - * Encryption object to mange payload ECDH encryption. +/** Encryption object to mange payload ECDH encryption. */ object Encryption { private val localCurve = KeyPairGenerator.getInstance("ECDH", BouncyCastleProvider.PROVIDER_NAME) diff --git a/src/main/scala/com/wanari/webpush/HttpEce.scala b/src/main/scala/com/wanari/webpush/HttpEce.scala index 12c14f2..a9b1b46 100644 --- a/src/main/scala/com/wanari/webpush/HttpEce.scala +++ b/src/main/scala/com/wanari/webpush/HttpEce.scala @@ -11,8 +11,7 @@ import org.bouncycastle.crypto.generators.HKDFBytesGenerator import org.bouncycastle.crypto.params.HKDFParameters import org.bouncycastle.jce.provider.BouncyCastleProvider -/** - * A simplified implementation of HTTP ECE (Encrypted Content Encoding). +/** A simplified implementation of HTTP ECE (Encrypted Content Encoding). */ object HttpEce { def encrypt(keys: KeyPair, buffer: Array[Byte], salt: Array[Byte], dh: PublicKey, authSecret: Array[Byte]): Array[Byte] = { diff --git a/src/main/scala/com/wanari/webpush/PushService.scala b/src/main/scala/com/wanari/webpush/PushService.scala index d0bd74f..87e6241 100644 --- a/src/main/scala/com/wanari/webpush/PushService.scala +++ b/src/main/scala/com/wanari/webpush/PushService.scala @@ -14,24 +14,21 @@ import pdi.jwt.JwtAlgorithm.ES256 import scala.concurrent.Future import scala.concurrent.duration._ -/** - * Push service. +/** Push service. */ case class PushService(publicKey: ECPublicKey, privateKey: ECPrivateKey, subject: String, exp: FiniteDuration = 12.hours)(implicit as: ActorSystem) { protected def httpExt: HttpExt = Http() private val base64encoder = Base64.getUrlEncoder private val defaultTtl: Int = 2419200 - /** - * Send a data free push notification. + /** Send a data free push notification. * * @param subscription Browser subscription object. * @return HttpResponse from push server. */ def send(subscription: Subscription): Future[HttpResponse] = send(subscription, None, defaultTtl) - /** - * Send a data free push notification. + /** Send a data free push notification. * * @param subscription Browser subscription object. * @param ttl Suggestion to the message server for how long it should keep the message @@ -40,8 +37,7 @@ case class PushService(publicKey: ECPublicKey, privateKey: ECPrivateKey, subject */ def send(subscription: Subscription, ttl: Int): Future[HttpResponse] = send(subscription, None, ttl) - /** - * Sends a data bearing push notification. + /** Sends a data bearing push notification. * * @param subscription Browser subscription object. * @param payload Push notification payload. @@ -53,9 +49,7 @@ case class PushService(publicKey: ECPublicKey, privateKey: ECPrivateKey, subject def send(subscription: Subscription, payload: String): Future[HttpResponse] = send(subscription, Some(payload.getBytes), defaultTtl) - /** - * - * Sends a data bearing push notification. + /** Sends a data bearing push notification. * * @param subscription Browser subscription object. * @param payload Push notification data as a Byte Array. @@ -65,8 +59,7 @@ case class PushService(publicKey: ECPublicKey, privateKey: ECPrivateKey, subject */ def send(subscription: Subscription, payload: Array[Byte], ttl: Int = defaultTtl): Future[HttpResponse] = send(subscription, Some(payload), ttl) - /** - * Returns the server public key as a URL safe base64 string. + /** Returns the server public key as a URL safe base64 string. */ def publicKeyToBase64: String = { base64encoder.withoutPadding().encodeToString(Utils.publicKeyToBytes(publicKey.asInstanceOf[ECPublicKey]))