From 62d578cd3fee5001d280edcaa6c6bd3e4a6ec34b Mon Sep 17 00:00:00 2001 From: Pablo Polvorin Date: Sat, 16 Sep 2023 12:59:20 -0300 Subject: [PATCH] fix(elixir): fix format on list_member_ids response --- .../credential/authenticator/direct/client.ex | 2 +- .../ockam/ockly/native/ockly/src/lib.rs | 34 ++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/implementations/elixir/ockam/ockam/lib/ockam/credential/authenticator/direct/client.ex b/implementations/elixir/ockam/ockam/lib/ockam/credential/authenticator/direct/client.ex index 1c5a5dc214a..12ca54d3513 100644 --- a/implementations/elixir/ockam/ockam/lib/ockam/credential/authenticator/direct/client.ex +++ b/implementations/elixir/ockam/ockam/lib/ockam/credential/authenticator/direct/client.ex @@ -95,7 +95,7 @@ defmodule Ockam.Credential.Authenticator.Direct.Client do def list_member_ids(api_route) do case ApiClient.sync_request(:get, "/member_ids", "", api_route) do {:ok, %ApiResponse{status: 200, body: response}} -> - Ockam.TypedCBOR.decode_strict({:list, :string}, response) + Ockam.TypedCBOR.decode_strict({:list, :binary}, response) {:ok, %ApiResponse{status: status, body: body}} -> {:error, {:api_error, status, body}} diff --git a/implementations/elixir/ockam/ockly/native/ockly/src/lib.rs b/implementations/elixir/ockam/ockly/native/ockly/src/lib.rs index b26ef30b542..2e445641cf3 100644 --- a/implementations/elixir/ockam/ockly/native/ockly/src/lib.rs +++ b/implementations/elixir/ockam/ockly/native/ockly/src/lib.rs @@ -34,6 +34,8 @@ mod atoms { identity_import_error, credential_verification_failed, invalid_identifier, + identity_creation_error, + identity_export_error, utf8_error, attest_error, attestation_encode_error, @@ -72,26 +74,33 @@ fn identities_ref() -> NifResult> { #[rustler::nif] fn create_identity(env: Env, existing_key: Option) -> NifResult<(Binary, Binary)> { let identities_ref = identities_ref()?; + let secret_type = if SIGNING_MEMORY_VAULT.read().unwrap().is_some() { + SecretType::Ed25519 + } else { + SecretType::NistP256 + }; let identity = block_future(async move { if let Some(key) = existing_key { identities_ref .identities_creation() .identity_builder() - .with_existing_key(key, SecretType::Ed25519) + .with_existing_key(key, secret_type) .build() .await } else { - if SIGNING_MEMORY_VAULT.read().unwrap().is_some() { - identities_ref.identities_creation().identity_builder().with_random_key(SecretType::Ed25519).build().await - } else { - // AWS vault uses NistP256 keys - identities_ref.identities_creation().identity_builder().with_random_key(SecretType::NistP256).build().await - } + identities_ref + .identities_creation() + .identity_builder() + .with_random_key(secret_type) + .build() + .await } }) - .map_err(|_| Error::BadArg)?; + .map_err(|_| Error::Term(Box::new(atoms::identity_creation_error())))?; - let exported = identity.export().map_err(|_| Error::BadArg)?; + let exported = identity + .export() + .map_err(|_| Error::Term(Box::new(atoms::identity_export_error())))?; let id = identity.identifier().to_string(); let mut binary = NewBinary::new(env, id.len()); binary.copy_from_slice(id.as_bytes()); @@ -330,10 +339,9 @@ fn load_aws_vault() -> bool { *IDENTITIES.write().unwrap() = Some(builder.build()); true } - Err(_) => { - false - } - }}) + Err(_) => false, + } + }) } fn load(_env: rustler::Env, load_data: rustler::Term) -> bool {