From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id B5F171FF161 for ; Wed, 6 Nov 2024 15:18:11 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B19EEFA70; Wed, 6 Nov 2024 15:18:20 +0100 (CET) Date: Wed, 6 Nov 2024 15:18:16 +0100 From: Wolfgang Bumiller To: Stefan Hanreich Message-ID: References: <20241010155637.255451-1-s.hanreich@proxmox.com> <20241010155637.255451-13-s.hanreich@proxmox.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20241010155637.255451-13-s.hanreich@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.081 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [mod.rs, lib.rs] Subject: Re: [pve-devel] [PATCH proxmox-ve-rs v2 12/25] sdn: add name types X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Cc: pve-devel@lists.proxmox.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" On Thu, Oct 10, 2024 at 05:56:24PM GMT, Stefan Hanreich wrote: > Signed-off-by: Stefan Hanreich > --- > proxmox-ve-config/src/lib.rs | 1 + > proxmox-ve-config/src/sdn/mod.rs | 240 +++++++++++++++++++++++++++++++ > 2 files changed, 241 insertions(+) > create mode 100644 proxmox-ve-config/src/sdn/mod.rs > > diff --git a/proxmox-ve-config/src/lib.rs b/proxmox-ve-config/src/lib.rs > index 1b6feae..d17136c 100644 > --- a/proxmox-ve-config/src/lib.rs > +++ b/proxmox-ve-config/src/lib.rs > @@ -2,3 +2,4 @@ pub mod common; > pub mod firewall; > pub mod guest; > pub mod host; > +pub mod sdn; > diff --git a/proxmox-ve-config/src/sdn/mod.rs b/proxmox-ve-config/src/sdn/mod.rs > new file mode 100644 > index 0000000..4e7c525 > --- /dev/null > +++ b/proxmox-ve-config/src/sdn/mod.rs > @@ -0,0 +1,240 @@ > +use std::{error::Error, fmt::Display, str::FromStr}; > + > +use serde_with::DeserializeFromStr; > + > +use crate::firewall::types::Cidr; > + > +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] > +pub enum SdnNameError { > + Empty, > + TooLong, > + InvalidSymbols, > + InvalidSubnetCidr, > + InvalidSubnetFormat, > +} > + > +impl Error for SdnNameError {} > + > +impl Display for SdnNameError { > + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { > + f.write_str(match self { > + SdnNameError::TooLong => "name too long", > + SdnNameError::InvalidSymbols => "invalid symbols in name", > + SdnNameError::InvalidSubnetCidr => "invalid cidr in name", > + SdnNameError::InvalidSubnetFormat => "invalid format for subnet name", > + SdnNameError::Empty => "name is empty", > + }) > + } > +} > + > +fn validate_sdn_name(name: &str) -> Result<(), SdnNameError> { > + if name.is_empty() { > + return Err(SdnNameError::Empty); > + } > + > + if name.len() > 8 { > + return Err(SdnNameError::TooLong); > + } > + > + // safe because of empty check > + if !name.chars().next().unwrap().is_ascii_alphabetic() { > + return Err(SdnNameError::InvalidSymbols); > + } > + > + if !name.chars().all(|c| c.is_ascii_alphanumeric()) { > + return Err(SdnNameError::InvalidSymbols); > + } > + > + Ok(()) > +} > + > +/// represents the name of an sdn zone > +#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, DeserializeFromStr)] > +pub struct ZoneName(String); > + > +impl ZoneName { > + /// construct a new zone name > + /// > + /// # Errors > + /// > + /// This function will return an error if the name is empty, too long (>8 characters), starts > + /// with a non-alphabetic symbol or if there are non alphanumeric symbols contained in the name. > + pub fn new(name: String) -> Result { > + validate_sdn_name(&name)?; > + Ok(ZoneName(name)) > + } > + > + pub fn name(&self) -> &str { ^ I wonder if this should be `as_str()` And would it make sense to `impl AsRef`? _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel