encaps static method
Encapsulates to publicKey, producing a ciphertext and shared secret.
Implementation
static Encapsulation encaps(List<int> publicKey) => using((arena) {
final pkey = rawPublicKey(arena, algorithm, publicKey);
final ctx = checkNotNull(
ssl.EVP_PKEY_CTX_new_from_pkey(nullptr, pkey, nullptr),
'EVP_PKEY_CTX_new_from_pkey',
);
arena.using(ctx, ssl.EVP_PKEY_CTX_free);
checkOne(
ssl.EVP_PKEY_encapsulate_init(ctx, nullptr),
'EVP_PKEY_encapsulate_init',
);
final ctLen = arena<Size>()..value = ciphertextLength;
final ssLen = arena<Size>()..value = sharedSecretLength;
final ct = arena<UnsignedChar>(ciphertextLength);
final ss = secretBuffer(arena, sharedSecretLength);
checkOne(
ssl.EVP_PKEY_encapsulate(ctx, ct, ctLen, ss, ssLen),
'EVP_PKEY_encapsulate',
);
return Encapsulation(
fromNative(ct, ctLen.value),
fromNative(ss, ssLen.value),
);
});