Open damon-kwok opened 4 years ago
The purpose of the additional indirection in Lori is to allow for different implementations (for example for testing) to be swapped in.
Beyond some idea of "cleanliness", are there advantages around testability or something else that would come from this change?
Things are artificial. If we can think of more, we can do better.
I can see moving "new"/"edit" to it's own primitive.
@damon-kwok can you give a full example of the change for the snippet of code you included for how it is right now?
It's hard to envision from your initial example what the change would be.
class Digest
"""
Produces a hash from the chunks of input. Feed the input with append() and
produce a final hash from the concatenation of the input with final().
"""
let _digest_size: USize
let _ctx: Pointer[_EVPCTX]
var _hash: (Array[U8] val | None) = None
new md4() =>
"""
Use the MD4 algorithm to calculate the hash.
"""
_digest_size = 16
_ctx = Evp.md_ctx_new()
Evp.digest_init_ex(_ctx, EvpCmd.md_md4(), USize(0))
And what would the Evp primitive look like? What methods? And what would their implementation be?
primitive Evp
fun md_ctx_new(): Pointer[_MDCTX] => ...
fun cipher_ctx_new(): Pointer[_CIPHERCTX] => ...
fun encode_ctx_new(): Pointer[_ENCODECTX] => ...
fun ssl_version(): String => ...
primitive EvpCmd
fun md_md4(): Pointer[_EVPMD] =>
fun md_md5(): Pointer[_EVPMD] =>
fun cipher_aes(): Pointer[_EVPMD] =>
Or
primitive EvpMd
fun ctx_new(): Pointer[_MDCTX] => ...
fun md_md4(): Pointer[_EVPMD] =>
fun md_md5(): Pointer[_EVPMD] =>
primitive EvpCipher
fun ctx_new(): Pointer[_CIPHERCTX] => ...
fun cmd_aes(): Pointer[_EVPMD] =>
Can you give the implementations for the methods you listed?
@SeanTAllen Yes, see: https://github.com/pony-ready/crypto/tree/refactor/crypto
@damon-kwok I don't have time to figure out where in that repo I am supposed to be looking. Where specifically should I look?
https://github.com/pony-ready/crypto/blob/refactor/crypto/_test.pony It contains all the hash algorithms.
@damon-kwok that isn't what I asked for an example of.
At moment, the ffi methods are spread throughout the entire library. For clean and maintainable code, we can refer to the practice of lori: https://github.com/seantallen-org/lori/blob/master/lori/pony_asio.pony
In the end it should look like this: