From fd27a4f2ade4a1454ff1272609fa22103d071e2f Mon Sep 17 00:00:00 2001 From: olaszakos Date: Mon, 18 Nov 2024 12:27:21 +0100 Subject: [PATCH] add account name length validation --- .../wizard/AccountConfigurationSettings.vue | 5 ++--- core/station/impl/src/errors/account.rs | 5 +++++ core/station/impl/src/models/account.rs | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/apps/wallet/src/components/accounts/wizard/AccountConfigurationSettings.vue b/apps/wallet/src/components/accounts/wizard/AccountConfigurationSettings.vue index 71995023d..266a1bc35 100644 --- a/apps/wallet/src/components/accounts/wizard/AccountConfigurationSettings.vue +++ b/apps/wallet/src/components/accounts/wizard/AccountConfigurationSettings.vue @@ -25,14 +25,13 @@ :disabled="isViewMode || !!model.id" :multiple="true" /> - ModelValidatorResult { Ok(()) } +fn validate_account_name(name: &str) -> ModelValidatorResult { + if (name.len() < Account::NAME_RANGE.0 as usize) + || (name.len() > Account::NAME_RANGE.1 as usize) + { + return Err(AccountError::InvalidNameLength { + min_length: Account::NAME_RANGE.0, + max_length: Account::NAME_RANGE.1, + }); + } + + Ok(()) +} + impl ModelValidator for Account { fn validate(&self) -> ModelValidatorResult { self.metadata.validate()?; + validate_account_name(&self.name)?; + for asset in &self.assets { validate_asset_id(&asset.asset_id)?; } @@ -216,6 +231,7 @@ impl ModelValidator for Account { impl Account { pub const OWNERS_RANGE: (u8, u8) = (1, 10); pub const ADDRESS_RANGE: (u8, u8) = (1, 255); + pub const NAME_RANGE: (u8, u8) = (1, 64); pub const SYMBOL_RANGE: (u8, u8) = (1, 8); pub const MAX_POLICIES: u8 = 10;