Skip to content

Commit

Permalink
chore(elixir): improve API exposed via NIF calls
Browse files Browse the repository at this point in the history
  • Loading branch information
feniks65 committed Apr 17, 2021
1 parent 2eb09fb commit f638294
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 39 deletions.
56 changes: 30 additions & 26 deletions implementations/elixir/ockam/ockam/lib/ockam/vault.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f638294

Please sign in to comment.