mirror of
https://github.com/fluencelabs/crypto
synced 2025-04-24 14:22:18 +00:00
changing btree key type from Array[Byte] to value class (#76)
This commit is contained in:
parent
d14de45aaa
commit
37fa5ac62c
@ -17,6 +17,11 @@
|
||||
|
||||
package fluence.crypto.cipher
|
||||
|
||||
import cats.Monad
|
||||
import cats.syntax.flatMap._
|
||||
import cats.syntax.functor._
|
||||
import fluence.codec.Codec
|
||||
|
||||
import scala.language.higherKinds
|
||||
|
||||
/**
|
||||
@ -33,3 +38,33 @@ trait Crypt[F[_], P, C] {
|
||||
def decrypt(cipherText: C): F[P]
|
||||
|
||||
}
|
||||
|
||||
object Crypt {
|
||||
|
||||
def apply[F[_], O, B](implicit crypt: Crypt[F, O, B]): Crypt[F, O, B] = crypt
|
||||
|
||||
implicit def transform[F[_] : Monad, K, K1, V, V1](
|
||||
crypt: Crypt[F, K, V]
|
||||
)(
|
||||
implicit
|
||||
plainTextCodec: Codec[F, K1, K],
|
||||
cipherTextCodec: Codec[F, V1, V]
|
||||
): Crypt[F, K1, V1] =
|
||||
|
||||
new Crypt[F, K1, V1] {
|
||||
|
||||
override def encrypt(plainText: K1): F[V1] = for {
|
||||
pt ← plainTextCodec.encode(plainText)
|
||||
v ← crypt.encrypt(pt)
|
||||
v1 ← cipherTextCodec.decode(v)
|
||||
} yield v1
|
||||
|
||||
override def decrypt(cipherText: V1): F[K1] = for {
|
||||
ct ← cipherTextCodec.encode(cipherText)
|
||||
v ← crypt.decrypt(ct)
|
||||
v1 ← plainTextCodec.decode(v)
|
||||
} yield v1
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user