WebAssembly / wasi-crypto

WASI Cryptography API Proposal
163 stars 25 forks source link

symmetric_state_options_get defination #46

Closed sonder-joker closed 2 years ago

sonder-joker commented 2 years ago

Return an array_output handle or copy to allocated in guset?

sonder-joker commented 2 years ago

In the previous example, it use

let nonce_handle = symmetric_state_options_get(state_handle, "nonce")?; // array_output handle

however defination in witx have such a signature

    ;;; Retrieve a parameter from the current state.
    ;;;
    ;;; In particular, `symmetric_state_options_get("nonce")` can be used to get a nonce that as automatically generated.
    ;;;
    ;;; The function may return `options_not_set` if an option was not set, which is different from an empty value.
    ;;;
    ;;; It may also return `unsupported_option` if the option doesn't exist for the chosen algorithm.
    (@interface func (export "symmetric_state_options_get")
        (param $handle $symmetric_state)
        (param $name string)
        (param $value (@witx pointer u8))
        (param $value_max_len $size)
        (result $error (expected $size (error $crypto_errno)))
    )
jedisct1 commented 2 years ago

Hi!

And thanks for spotting this inconsistency.

The API originally meant to return an array_output.

But options are always very small, and most of the time their size is often known in advance. So, the idea was to simplify the API and return the value directly.

Can you think of a case where an arbitrary long/very long option would be returned?

If not, I will fix the examples to match the fact that we don't return a handle.

sonder-joker commented 2 years ago

I can't. I believe guest provide buffer is a better way.

jedisct1 commented 2 years ago

It's also simpler and faster.

I'm going to update the examples, thank you!