Skip to content
This repository was archived by the owner on Apr 27, 2023. It is now read-only.
This repository was archived by the owner on Apr 27, 2023. It is now read-only.

Proposal: library revision #6

Description

@vitaliihonta

Hello @mkubala @kciesielski ! I already e-mailed Adam about my question and decided to discuss it directly with you.

stringmask is pretty useful in such a field as fintech (for masking data not only in logs, but even in API responses), and I used this library for a while.

But the caveat is macro annotations because it's unclear if Scala 3 will support them.

So I developed a library sharing the same purpose but with a different approach, based on typeclasses.
I wonder if you're interested in adopting it as a part of stringmask?
I could open a PR and do all the work.

Here is the source code.
It looks pretty the same as chimney, having simple builders for describing masking logic.
For instance:

import sensitive._
import scala.util.matching.Regex

case class CardData(number: String, expMonth: Int, expYear: Int, cvv: String)

object CardData {
  implicit val sensitiveCardData: Sensitive[CardData] = sensitiveOf[CardData]
    .withFieldMasked(_.number)(
      regexp(
        "([0-9]{4})-([0-9]{4})-([0-9]{4})-([0-9]{4})".r,
        replaceAll(replacer = {
          case Regex.Groups(first, second, _, fourth) =>
            s"$first-${second.take(2)}**-****-$fourth"
        })
      )
    )
    .withFieldMasked(_.cvv)(substitute("***"))
    .build

}

The only thing that should be improved is Scala 3 macros for the builder DSL.
I already did some experiments and it seems to be possible to implement it in Scala 3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions