rust-umbral icon indicating copy to clipboard operation
rust-umbral copied to clipboard

Get rid of a getter for `ciphertext` in EncryptionResult

Open fjarri opened this issue 5 years ago • 3 comments

EncryptionResult struct which we have to return from encrypt() because wasm-bindgen does not support returning tuples has a field ciphertext: Box<[u8]>. Box<[u8]> does not implement Copy, so the field must be private, and we have to define a getter; see https://github.com/rustwasm/wasm-bindgen/issues/439.

Remove the getter when the issue is fixed, or maybe when wasm-bindgen starts supporting tuples.

fjarri avatar Nov 30 '20 00:11 fjarri

@fjarri I'm not sure I understand what needs to be done here.

This struct as is provides a decent interface through JS like let { ciphertext, capsule } = umbral.encrypt(alice_pk, plaintext_bytes); which is pretty "tuple like".

What exactly are we going for here?

vepkenez avatar Jul 20 '21 22:07 vepkenez

I guess it may be a little simpler to destructure lists if you do several encryptions in a row, e.g.

let { ciphertext: ciphertext1, capsule: capsule1 } = umbral.encrypt(alice_pk, plaintext1);
let { ciphertext: ciphertext2, capsule: capsule2 } = umbral.encrypt(alice_pk, plaintext2);

// as opposed to
let [ciphertext1, capsule1] = umbral.encrypt(alice_pk, plaintext1);
let [ciphertext2, capsule2] = umbral.encrypt(alice_pk, plaintext2);

But perhaps the former variant is safer and should be forced anyway.

fjarri avatar Sep 14 '21 22:09 fjarri

For now we're using a custom type (EncryptionResult, declared as TS [Capsule, Uint8Array]) and a manual conversion to js_sys::Array. When wasm-bindgen fixes the underlying issue, the internals can be updated too. The API is now

let [ciphertext1, capsule1] = umbral.encrypt(alice_pk, plaintext1);

as desired.

fjarri avatar Sep 19 '22 23:09 fjarri