From f638294887d4e1d66e1980971f1f50be3786b0b8 Mon Sep 17 00:00:00 2001 From: Wojciech Wais Date: Sat, 17 Apr 2021 21:23:46 +0000 Subject: [PATCH] chore(elixir): improve API exposed via NIF calls --- .../elixir/ockam/ockam/lib/ockam/vault.ex | 56 ++++++++++--------- .../lib/vault_software.ex | 26 ++++----- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/implementations/elixir/ockam/ockam/lib/ockam/vault.ex b/implementations/elixir/ockam/ockam/lib/ockam/vault.ex index b3031f59544..98ae3e53e31 100644 --- a/implementations/elixir/ockam/ockam/lib/ockam/vault.ex +++ b/implementations/elixir/ockam/ockam/lib/ockam/vault.ex @@ -1,56 +1,60 @@ defmodule Ockam.Vault do @moduledoc false - def sha256(%vault_module{id: vault_id}, b) do - vault_module.sha256(vault_id, b) + @doc """ + Returns computed sha256 hash. + """ + @spec sha256(Ockam.Vault, String.t() | binary) :: {:ok, binary} | :error + def sha256(%vault_module{id: vault_id}, input) do + vault_module.sha256(vault_id, input) end - def random_bytes(%vault_module{id: vault_id}, b) do - vault_module.random_bytes(vault_id, b) + def random_bytes(%vault_module{id: vault_id}, output_buffer) do + vault_module.random_bytes(vault_id, output_buffer) end - def secret_generate(%vault_module{id: vault_id}, b) do - vault_module.secret_generate(vault_id, b) + def secret_generate(%vault_module{id: vault_id}, attributes) do + vault_module.secret_generate(vault_id, attributes) end - def secret_import(%vault_module{id: vault_id}, b, c) do - vault_module.secret_import(vault_id, b, c) + def secret_import(%vault_module{id: vault_id}, attributes, input) do + vault_module.secret_import(vault_id, attributes, input) end - def secret_export(%vault_module{id: vault_id}, b) do - vault_module.secret_export(vault_id, b) + def secret_export(%vault_module{id: vault_id}, secret_handle) do + vault_module.secret_export(vault_id, secret_handle) end - def secret_publickey_get(%vault_module{id: vault_id}, b) do - vault_module.secret_publickey_get(vault_id, b) + def secret_publickey_get(%vault_module{id: vault_id}, secret_handle) do + vault_module.secret_publickey_get(vault_id, secret_handle) end - def secret_attributes_get(%vault_module{id: vault_id}, b) do - vault_module.secret_attributes_get(vault_id, b) + def secret_attributes_get(%vault_module{id: vault_id}, secret_handle) do + vault_module.secret_attributes_get(vault_id, secret_handle) end - def secret_destroy(%vault_module{id: vault_id}, b) do - vault_module.secret_destroy(vault_id, b) + def secret_destroy(%vault_module{id: vault_id}, secret_handle) do + vault_module.secret_destroy(vault_id, secret_handle) end - def ecdh(%vault_module{id: vault_id}, b, c) do - vault_module.ecdh(vault_id, b, c) + def ecdh(%vault_module{id: vault_id}, secret_handle, input) do + vault_module.ecdh(vault_id, secret_handle, input) end - def hkdf_sha256(%vault_module{id: vault_id}, b, c, d) do - vault_module.hkdf_sha256(vault_id, b, c, d) + def hkdf_sha256(%vault_module{id: vault_id}, salt_handle, ikm_handle, derived_outputs_count) do + vault_module.hkdf_sha256(vault_id, salt_handle, ikm_handle, derived_outputs_count) end - def hkdf_sha256(%vault_module{id: vault_id}, b, c) do - vault_module.hkdf_sha256(vault_id, b, c) + def hkdf_sha256(%vault_module{id: vault_id}, salt_handle, ikm_handle) do + vault_module.hkdf_sha256(vault_id, salt_handle, ikm_handle) end - def aead_aes_gcm_encrypt(%vault_module{id: vault_id}, b, c, d, e) do - vault_module.aead_aes_gcm_encrypt(vault_id, b, c, d, e) + def aead_aes_gcm_encrypt(%vault_module{id: vault_id}, key_handle, nonce, ad, plain_text) do + vault_module.aead_aes_gcm_encrypt(vault_id, key_handle, nonce, ad, plain_text) end - def aead_aes_gcm_decrypt(%vault_module{id: vault_id}, b, c, d, e) do - vault_module.aead_aes_gcm_decrypt(vault_id, b, c, d, e) + def aead_aes_gcm_decrypt(%vault_module{id: vault_id}, key_handle, nonce, ad, cipher_text) do + vault_module.aead_aes_gcm_decrypt(vault_id, key_handle, nonce, ad, cipher_text) end def deinit(%vault_module{id: vault_id}) do diff --git a/implementations/elixir/ockam/ockam_vault_software/lib/vault_software.ex b/implementations/elixir/ockam/ockam_vault_software/lib/vault_software.ex index 264ac3a182f..c912e3ec11e 100644 --- a/implementations/elixir/ockam/ockam_vault_software/lib/vault_software.ex +++ b/implementations/elixir/ockam/ockam_vault_software/lib/vault_software.ex @@ -51,55 +51,55 @@ defmodule Ockam.Vault.Software do raise "natively implemented default_init/0 not loaded" end - def sha256(_a, _b) do + def sha256(_vault, _input) do raise "natively implemented sha256/2 not loaded" end - def secret_generate(_a, _b) do + def secret_generate(_vault, _attributes) do raise "natively implemented secret_generate/2 not loaded" end - def secret_import(_a, _b, _c) do + def secret_import(_vault, _attributes, _input) do raise "natively implemented secret_import/3 not loaded" end - def secret_export(_a, _b) do + def secret_export(_vault, _secret_handle) do raise "natively implemented secret_export/2 not loaded" end - def secret_publickey_get(_a, _b) do + def secret_publickey_get(_vault, _secret_handle) do raise "natively implemented secret_publickey_get/2 not loaded" end - def secret_attributes_get(_a, _b) do + def secret_attributes_get(_vault, _secret_handle) do raise "natively implemented secret_attributes_get/2 not loaded" end - def secret_destroy(_a, _b) do + def secret_destroy(_vault, _secret_handle) do raise "natively implemented secret_destroy/2 not loaded" end - def ecdh(_a, _b, _c) do + def ecdh(_vault, _secret_handle, _input) do raise "natively implemented ecdh/3 not loaded" end - def hkdf_sha256(_a, _b, _c, _d) do + def hkdf_sha256(_vault, _salt_handle, _ikm_handle, _derived_outputs_count) do raise "natively implemented hkdf_sha256/4 not loaded" end - def hkdf_sha256(_a, _b, _c) do + def hkdf_sha256(_vault, _salt_handle, _ikm_handle) do raise "natively implemented hkdf_sha256/3 not loaded" end - def aead_aes_gcm_encrypt(_a, _b, _c, _d, _e) do + def aead_aes_gcm_encrypt(_vault, _key_handle, _nonce, _ad, _plain_text) do raise "natively implemented aead_aes_gcm_encrypt/5 not loaded" end - def aead_aes_gcm_decrypt(_a, _b, _c, _d, _e) do + def aead_aes_gcm_decrypt(_vault, _key_handle, _nonce, _ad, _cipher_text) do raise "natively implemented aead_aes_gcm_decrypt/5 not loaded" end - def deinit(_a) do + def deinit(_vault) do raise "natively implemented deinit/1 not loaded" end end