Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Move all ffi methods to ssl.pony #36

Description

@damon-kwok
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
    ifdef "openssl_1.1.x" then
      _ctx = @EVP_MD_CTX_new[Pointer[_EVPCTX]]()
    else
      _ctx = @EVP_MD_CTX_create[Pointer[_EVPCTX]]()
    end
    @EVP_DigestInit_ex[None](_ctx, @EVP_md4[Pointer[_EVPMD]](), USize(0))
    
  new md5() =>
    """
    Use the MD5 algorithm to calculate the hash.
    """
    _digest_size = 16
    ifdef "openssl_1.1.x" then
      _ctx = @EVP_MD_CTX_new[Pointer[_EVPCTX]]()
    else
      _ctx = @EVP_MD_CTX_create[Pointer[_EVPCTX]]()
    end
    @EVP_DigestInit_ex[None](_ctx, @EVP_md5[Pointer[_EVPMD]](), USize(0))

  new ripemd160() =>
    """
    Use the RIPEMD160 algorithm to calculate the hash.
    """
    _digest_size = 20
    ifdef "openssl_1.1.x" then
      _ctx = @EVP_MD_CTX_new[Pointer[_EVPCTX]]()
    else
      _ctx = @EVP_MD_CTX_create[Pointer[_EVPCTX]]()
    end
    @EVP_DigestInit_ex[None](_ctx, @EVP_ripemd160[Pointer[_EVPMD]](), USize(0))

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:

primitive Evp
  fun md_ctx_new(): Pointer[_MDCTX] => ...
  fun cipher_ctx_new(): Pointer[_CIPHERCTX] => ...
  fun encode_ctx_new(): Pointer[_ENCODECTX] => ...
  fun ssl_version(): String => ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    discuss during syncShould be discussed during an upcoming syncneeds discussionNeeds to be discussed further

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions