• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / atala-prism-building-blocks / 8819221863

24 Apr 2024 03:32PM UTC coverage: 50.082% (+18.2%) from 31.912%
8819221863

Pull #973

mineme0110
minor cleanup

Signed-off-by: mineme0110 <shailesh.patil@iohk.io>
Pull Request #973: feat: Align the repo with new name identus-cloud-agent

1 of 6 new or added lines in 4 files covered. (16.67%)

2998 existing lines in 264 files now uncovered.

7340 of 14656 relevant lines covered (50.08%)

0.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/pollux/lib/vc-jwt/src/main/scala/io/iohk/atala/pollux/vc/jwt/MultiBaseString.scala
1
package io.iohk.atala.pollux.vc.jwt
2

3
import io.circe.*
4
import io.iohk.atala.shared.utils.Base64Utils
5
import scodec.bits.ByteVector
6

7
case class MultiBaseString(header: MultiBaseString.Header, data: String) {
8
  def toMultiBaseString: String = s"${header.value}$data"
1✔
9

10
  def getBytes: Either[String, Array[Byte]] = header match {
1✔
11
    case MultiBaseString.Header.Base64Url => Right(Base64Utils.decodeURL(data))
1✔
12
    case MultiBaseString.Header.Base58Btc =>
1✔
13
      ByteVector.fromBase58(data).map(_.toArray).toRight(s"Invalid base58 string: $data")
1✔
14
  }
15
}
16

17
object MultiBaseString {
18
  enum Header(val value: Char) {
19
    case Base64Url extends Header('u')
20
    case Base58Btc extends Header('z')
21
  }
22

23
  def fromString(str: String): Either[String, MultiBaseString] = {
1✔
24
    val header = Header.fromValue(str.head)
1✔
25
    header match {
26
      case Some(value) => Right(MultiBaseString(value, str.tail))
1✔
UNCOV
27
      case None        => Left(s"$str - is not a multi base string")
×
28
    }
29
  }
30

31
  object Header {
32
    def fromValue(value: Char): Option[Header] = value match {
1✔
33
      case 'u' => Some(Header.Base64Url)
1✔
34
      case 'z' => Some(Header.Base58Btc)
1✔
UNCOV
35
      case _   => None
×
36
    }
37
  }
38

39
  given multiBaseStringEncoder: Encoder[MultiBaseString] = (multiBaseString: MultiBaseString) =>
40
    Json.fromString(multiBaseString.toMultiBaseString)
1✔
41

42
  given multiBaseStringDecoder: Decoder[MultiBaseString] = (c: HCursor) =>
43
    Decoder.decodeString(c).flatMap { str =>
1✔
44
      val header = MultiBaseString.Header.fromValue(str.head)
1✔
45
      header match {
46
        case Some(value) => Right(MultiBaseString(value, str.tail))
1✔
UNCOV
47
        case None        => Left(DecodingFailure(s"no enum value matched for $str", List(CursorOp.Field(str))))
×
48
      }
49
    }
50
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc