// Copyright 2025 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 use crate::models::CurrentUpgradeModeStatus; use crate::traits::{ Id, PendingRegistrationResponse, RegisteredResponse, RemainingBandwidthResponse, TopUpBandwidthResponse, UpgradeModeStatus, }; use crate::{v2, v3, v4, v5, v6}; use nym_sphinx::addressing::Recipient; #[derive(Debug)] pub enum AuthenticatorResponse { PendingRegistration(Box), Registered(Box), RemainingBandwidth(Box), TopUpBandwidth(Box), UpgradeMode(Box), } pub struct SerialisedResponse { pub bytes: Vec, pub reply_to: Option, } impl SerialisedResponse { pub fn new(bytes: Vec, reply_to: Option) -> Self { Self { bytes, reply_to } } } impl UpgradeModeStatus for AuthenticatorResponse { fn upgrade_mode_status(&self) -> CurrentUpgradeModeStatus { match self { AuthenticatorResponse::PendingRegistration(pending_registration_response) => { pending_registration_response.upgrade_mode_status() } AuthenticatorResponse::Registered(registered_response) => { registered_response.upgrade_mode_status() } AuthenticatorResponse::RemainingBandwidth(remaining_bandwidth_response) => { remaining_bandwidth_response.upgrade_mode_status() } AuthenticatorResponse::TopUpBandwidth(top_up_bandwidth_response) => { top_up_bandwidth_response.upgrade_mode_status() } AuthenticatorResponse::UpgradeMode(upgrade_mode_response) => { upgrade_mode_response.upgrade_mode_status() } } } } impl Id for AuthenticatorResponse { fn id(&self) -> u64 { match self { AuthenticatorResponse::PendingRegistration(pending_registration_response) => { pending_registration_response.id() } AuthenticatorResponse::Registered(registered_response) => registered_response.id(), AuthenticatorResponse::RemainingBandwidth(remaining_bandwidth_response) => { remaining_bandwidth_response.id() } AuthenticatorResponse::TopUpBandwidth(top_up_bandwidth_response) => { top_up_bandwidth_response.id() } AuthenticatorResponse::UpgradeMode(upgrade_mode_response) => upgrade_mode_response.id(), } } } impl From for AuthenticatorResponse { fn from(value: v2::response::AuthenticatorResponse) -> Self { match value.data { v2::response::AuthenticatorResponseData::PendingRegistration( pending_registration_response, ) => Self::PendingRegistration(Box::new(pending_registration_response)), v2::response::AuthenticatorResponseData::Registered(registered_response) => { Self::Registered(Box::new(registered_response)) } v2::response::AuthenticatorResponseData::RemainingBandwidth( remaining_bandwidth_response, ) => Self::RemainingBandwidth(Box::new(remaining_bandwidth_response)), } } } impl From for AuthenticatorResponse { fn from(value: v3::response::AuthenticatorResponse) -> Self { match value.data { v3::response::AuthenticatorResponseData::PendingRegistration( pending_registration_response, ) => Self::PendingRegistration(Box::new(pending_registration_response)), v3::response::AuthenticatorResponseData::Registered(registered_response) => { Self::Registered(Box::new(registered_response)) } v3::response::AuthenticatorResponseData::RemainingBandwidth( remaining_bandwidth_response, ) => Self::RemainingBandwidth(Box::new(remaining_bandwidth_response)), v3::response::AuthenticatorResponseData::TopUpBandwidth(top_up_bandwidth_response) => { Self::TopUpBandwidth(Box::new(top_up_bandwidth_response)) } } } } impl From for AuthenticatorResponse { fn from(value: v4::response::AuthenticatorResponse) -> Self { match value.data { v4::response::AuthenticatorResponseData::PendingRegistration( pending_registration_response, ) => Self::PendingRegistration(Box::new(pending_registration_response)), v4::response::AuthenticatorResponseData::Registered(registered_response) => { Self::Registered(Box::new(registered_response)) } v4::response::AuthenticatorResponseData::RemainingBandwidth( remaining_bandwidth_response, ) => Self::RemainingBandwidth(Box::new(remaining_bandwidth_response)), v4::response::AuthenticatorResponseData::TopUpBandwidth(top_up_bandwidth_response) => { Self::TopUpBandwidth(Box::new(top_up_bandwidth_response)) } } } } impl From for AuthenticatorResponse { fn from(value: v5::response::AuthenticatorResponse) -> Self { match value.data { v5::response::AuthenticatorResponseData::PendingRegistration( pending_registration_response, ) => Self::PendingRegistration(Box::new(pending_registration_response)), v5::response::AuthenticatorResponseData::Registered(registered_response) => { Self::Registered(Box::new(registered_response)) } v5::response::AuthenticatorResponseData::RemainingBandwidth( remaining_bandwidth_response, ) => Self::RemainingBandwidth(Box::new(remaining_bandwidth_response)), v5::response::AuthenticatorResponseData::TopUpBandwidth(top_up_bandwidth_response) => { Self::TopUpBandwidth(Box::new(top_up_bandwidth_response)) } } } } impl From for AuthenticatorResponse { fn from(value: v6::response::AuthenticatorResponse) -> Self { match value.data { v6::response::AuthenticatorResponseData::PendingRegistration( pending_registration_response, ) => Self::PendingRegistration(Box::new(pending_registration_response)), v6::response::AuthenticatorResponseData::Registered(registered_response) => { Self::Registered(Box::new(registered_response)) } v6::response::AuthenticatorResponseData::RemainingBandwidth( remaining_bandwidth_response, ) => Self::RemainingBandwidth(Box::new(remaining_bandwidth_response)), v6::response::AuthenticatorResponseData::TopUpBandwidth(top_up_bandwidth_response) => { Self::TopUpBandwidth(Box::new(top_up_bandwidth_response)) } v6::response::AuthenticatorResponseData::UpgradeMode(upgrade_mode_check_response) => { Self::UpgradeMode(Box::new(upgrade_mode_check_response)) } } } }