mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Don't require a prefix when configuring byte arrays
This commit is contained in:
@ -27,9 +27,9 @@ object Implicits {
|
||||
ConfigReader[String].emap(reason(str => {
|
||||
if (str.startsWith("hex:")) ByteVector.fromHex(str.drop(4)).toRight("Invalid hex value.")
|
||||
else if (str.startsWith("b64:")) ByteVector.fromBase64(str.drop(4)).toRight("Invalid Base64 string.")
|
||||
else ByteVector.fromHex(str).toRight("Invalid hex value.")
|
||||
else ByteVector.encodeUtf8(str).left.map(ex => s"Invalid utf8 string: ${ex.getMessage}")
|
||||
}))
|
||||
|
||||
def reason[A: ClassTag](f: String => Either[String, A]): String => Either[FailureReason, A] =
|
||||
in => f(in).left.map(str => CannotConvert(in, implicitly[ClassTag[A]].runtimeClass.toString, str))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user