Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/cargo/anyhow-1.0.88
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov authored Sep 18, 2024
2 parents e12433d + c9ef8b0 commit 441a31f
Show file tree
Hide file tree
Showing 18 changed files with 247 additions and 246 deletions.
48 changes: 48 additions & 0 deletions crates/bioauth-flow-rpc/src/data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//! The RPC request and response data, excluding errors.

/// The parameters necessary to initialize the FaceTec Device SDK.
pub type FacetecDeviceSdkParams = serde_json::Map<String, serde_json::Value>;

/// The bioauth status as used in the RPC.
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum BioauthStatus<Timestamp> {
/// When the status can't be determined, but there was no error.
/// Can happen if the validator key is absent.
Unknown,
/// There is no active authentication for the currently used validator key.
Inactive,
/// There is an active authentication for the currently used validator key.
Active {
/// The timestamp when the authentication will expire.
expires_at: Timestamp,
},
}

impl<T> From<bioauth_flow_api::BioauthStatus<T>> for BioauthStatus<T> {
fn from(status: bioauth_flow_api::BioauthStatus<T>) -> Self {
match status {
bioauth_flow_api::BioauthStatus::Inactive => Self::Inactive,
bioauth_flow_api::BioauthStatus::Active { expires_at } => Self::Active { expires_at },
}
}
}

/// `enroll_v2` flow result.
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EnrollV2Result {
/// Scan result blob.
pub scan_result_blob: Option<String>,
}

/// `authenticate_v2` related flow result.
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AuthenticateV2Result {
/// An opaque auth ticket generated for this authentication attempt.
pub auth_ticket: Box<[u8]>,
/// The robonode signature for this opaque auth ticket.
pub auth_ticket_signature: Box<[u8]>,
/// Scan result blob.
pub scan_result_blob: Option<String>,
}
21 changes: 21 additions & 0 deletions crates/bioauth-flow-rpc/src/error/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Custom rpc error codes.

/// Signer has failed.
pub const SIGN: i32 = 100;

/// Request to robonode has failed.
pub const ROBONODE: i32 = 200;

/// Call to runtime api has failed.
pub const RUNTIME_API: i32 = 300;

/// Authenticate transaction has failed.
pub const TRANSACTION: i32 = 400;

/// Validator key is not available.
pub const MISSING_VALIDATOR_KEY: i32 =
rpc_validator_key_logic::api_error_code::MISSING_VALIDATOR_KEY;

/// Validator key extraction has failed.
pub const VALIDATOR_KEY_EXTRACTION: i32 =
rpc_validator_key_logic::api_error_code::VALIDATOR_KEY_EXTRACTION;
File renamed without changes.
8 changes: 8 additions & 0 deletions crates/bioauth-flow-rpc/src/error/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! All bioauth flow error kinds that we expose in the RPC.

pub mod code;
pub mod data;
pub mod shared;
mod sign;

pub use self::sign::Error as Sign;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use rpc_validator_key_logic::Error as ValidatorKeyError;
use serde::Serialize;

use super::{api_error_code, sign::Error as SignError};
use super::{code, sign::Error as SignError};

/// The robonode requests related error.
#[derive(Debug)]
Expand All @@ -28,24 +28,21 @@ impl<T: std::error::Error + 'static> FlowBaseError<T> {
match self {
Self::KeyExtraction(err @ ValidatorKeyError::MissingValidatorKey) => {
rpc_error_response::data(
api_error_code::MISSING_VALIDATOR_KEY,
code::MISSING_VALIDATOR_KEY,
err.to_string(),
rpc_validator_key_logic::error_data::ValidatorKeyNotAvailable,
)
}
Self::KeyExtraction(err @ ValidatorKeyError::ValidatorKeyExtraction) => {
rpc_error_response::simple(
api_error_code::VALIDATOR_KEY_EXTRACTION,
err.to_string(),
)
rpc_error_response::simple(code::VALIDATOR_KEY_EXTRACTION, err.to_string())
}
Self::Sign(err) => rpc_error_response::simple(api_error_code::SIGN, err.to_string()),
Self::Sign(err) => rpc_error_response::simple(code::SIGN, err.to_string()),
Self::RobonodeClient(err @ robonode_client::Error::Call(inner)) => {
let maybe_data = (robonode_call_error_data)(inner);
rpc_error_response::raw(api_error_code::ROBONODE, err.to_string(), maybe_data)
rpc_error_response::raw(code::ROBONODE, err.to_string(), maybe_data)
}
Self::RobonodeClient(err @ robonode_client::Error::Reqwest(_)) => {
rpc_error_response::simple(api_error_code::ROBONODE, err.to_string())
rpc_error_response::simple(code::ROBONODE, err.to_string())
}
}
}
Expand Down
File renamed without changes.
34 changes: 0 additions & 34 deletions crates/bioauth-flow-rpc/src/errors/mod.rs

This file was deleted.

Loading

0 comments on commit 441a31f

Please sign in to comment.