<div dir="ltr">Apparently I did not think this through. For "instance (BlockCipher k, Byteable iv) => Serialize ((k, iv), Destination)", how should I code get function? I mean in get, I should give out (k, iv), instead of using them.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 22, 2015 at 9:52 AM, Magicloud Magiclouds <span dir="ltr"><<a href="mailto:magicloud.magiclouds@gmail.com" target="_blank">magicloud.magiclouds@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">This seems like what I need. Thanks.</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 21, 2015 at 10:13 PM, Erik Hesselink <span dir="ltr"><<a href="mailto:hesselink@gmail.com" target="_blank">hesselink@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">One thing I've done in the past is, instead of giving an 'instance<br>
Serialize YourType', give an 'instance Serialize (Input -> YourType)'.<br>
This way you can get access to the input in the instance, but you have<br>
to provide the input when you can the deserialization function.<br>
<br>
Regards,<br>
<br>
Erik<br>
<div><div><br>
On Tue, Apr 21, 2015 at 3:58 PM, Magicloud Magiclouds<br>
<<a href="mailto:magicloud.magiclouds@gmail.com" target="_blank">magicloud.magiclouds@gmail.com</a>> wrote:<br>
> Thank you. But how if the cipher was specified outside the binary data? I<br>
> mean I need to pass the decrypt/encrypt function to get/put while they do<br>
> not accept parameters. Should I use Reader here?<br>
><br>
> On Tue, Apr 21, 2015 at 6:43 PM, Yitzchak Gale <<a href="mailto:gale@sefer.org" target="_blank">gale@sefer.org</a>> wrote:<br>
>><br>
>> Magicloud Magiclouds wrote:<br>
>> > I am trying to work with some binary data that encrypted by field<br>
>> > instead of<br>
>> > the result of serialization. I'd like to use Data.Serialize to wrap the<br>
>> > data<br>
>> > structure. But I could not figure out how to apply an runtime specified<br>
>> > cipher method to the bytestring.<br>
>><br>
>> Are you using the set of crypto libraries written by<br>
>> Victor Hanquez, such as cryptocipher-types,<br>
>> crypto-pubkey-types, and cryptohash?<br>
>><br>
>> Or the set of libraries written by Thomas DuBuisson,<br>
>> such as crypto-api, cipher-aes128, etc.?<br>
>><br>
>> Here is an example of decoding for Victor's libraries.<br>
>> Encoding would be similar using Put instead of Get.<br>
>> Thomas' libraries would be similar using the other<br>
>> API.<br>
>><br>
>> Let's say you have a type like this:<br>
>><br>
>> data MyCipher = MyAES | MyBlowfish | ...<br>
>><br>
>> Then in your cereal code you would have a Get monad<br>
>> expression something like this (assuming you have<br>
>> written all of the functions called parseSomething):<br>
>><br>
>> getStuff = do<br>
>>   cipher <- parseCipher :: Get MyCipher<br>
>>   clearText <- case cipher of<br>
>>     MyAES -> do<br>
>>       keyBS <- parseAESKey :: Get ByteString<br>
>>       let key = either (error "bad AES key") id $ makeKey keyBS<br>
>>           cipher = cipherInit key<br>
>>       cipherText <- parseAESCipherText :: Get ByteString<br>
>>       return $ ecbDecrypt cipher cipherText<br>
>>     MyBlowfish -> do ...<br>
>><br>
>> etc.<br>
>><br>
>> Hope this helps,<br>
>> Yitz<br>
><br>
><br>
><br>
><br>
> --<br>
> 竹密岂妨流水过<br>
> 山高哪阻野云飞<br>
><br>
> And for G+, please use magiclouds#<a href="http://gmail.com" target="_blank">gmail.com</a>.<br>
><br>
</div></div><div><div>> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>竹密岂妨流水过<br>山高哪阻野云飞<br><br>And for G+, please use magiclouds#<a href="http://gmail.com" target="_blank">gmail.com</a>.</div>
</div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">竹密岂妨流水过<br>山高哪阻野云飞<br><br>And for G+, please use magiclouds#<a href="http://gmail.com" target="_blank">gmail.com</a>.</div>
</div>