 M: evp-md-context dispose*
     handle>> EVP_MD_CTX_destroy ;
 
-: with-evp-md-context ( quot -- )
-    maybe-init-ssl [ <evp-md-context> ] dip with-disposal ; inline
+<PRIVATE
 
 : digest-named ( name -- md )
     dup EVP_get_digestbyname

: set-digest ( name ctx -- )
    handle>> swap digest-named f EVP_DigestInit_ex ssl-error ;

: checksum-loop ( ctx -- )
    dup handle>>
    4096 read-partial dup [
        dup length EVP_DigestUpdate ssl-error
        checksum-loop
    ] [ 3drop ] if ;

: digest-value ( ctx -- value )
    handle>>
    { { int EVP_MAX_MD_SIZE } int }
    [ EVP_DigestFinal_ex ssl-error ] with-out-parameters
    memory>byte-array ;

PRIVATE>

M: openssl-checksum checksum-stream
    name>> swap [
        [
            [ set-digest ]
            [ checksum-loop ]
            [ digest-value ]
            tri
        ] with-evp-md-context
    ] with-input-stream ;


C: <openssl-checksum> openssl-checksum

TUPLE: evp-md-context < disposable handle ;

: <evp-md-context> ( -- ctx )
