From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 987E2621A6 for ; Mon, 23 Nov 2020 09:07:05 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8A15D2487E for ; Mon, 23 Nov 2020 09:07:05 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 2521724873 for ; Mon, 23 Nov 2020 09:07:05 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id E31A043E9C for ; Mon, 23 Nov 2020 09:07:04 +0100 (CET) Date: Mon, 23 Nov 2020 09:07:03 +0100 From: Wolfgang Bumiller To: Fabian =?utf-8?Q?Gr=C3=BCnbichler?= Cc: pbs-devel@lists.proxmox.com Message-ID: <20201123080703.lvosrrhcn7ilopna@wobu-vie.proxmox.com> References: <20201120163845.1225080-1-f.gruenbichler@proxmox.com> <20201120163845.1225080-3-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20201120163845.1225080-3-f.gruenbichler@proxmox.com> User-Agent: NeoMutt/20180716 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.025 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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. [format.rs] Subject: Re: [pbs-devel] [PATCH proxmox-backup 02/13] key: add fingerprint to key config X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Nov 2020 08:07:05 -0000 On Fri, Nov 20, 2020 at 05:38:32PM +0100, Fabian Grünbichler wrote: > diff --git a/src/tools/format.rs b/src/tools/format.rs > index 8fe6aa82..c9f50053 100644 > --- a/src/tools/format.rs > +++ b/src/tools/format.rs > @@ -102,6 +102,40 @@ impl From for HumanByte { > } > } > Minor nit (maybe for a follow-up cleanup depending on how the rest of the series goes): > +pub fn as_fingerprint(bytes: &[u8]) -> String { > + proxmox::tools::digest_to_hex(bytes) > + .as_bytes() > + .chunks(2) > + .map(|v| std::str::from_utf8(v).unwrap()) ^ this performs an unnecessary check, even if you just unwrap it, use unsafe { std::str::from_utf8_unchecked(v) } > + .collect::>().join(":") ^ this allocates multiple tiny vectors. Since you already know even the length of the resulting string it's nicer to just allocate it before hand and fill it in a loop. lex hex = proxmox::tools::digest_to_hex(bytes); // avoid underflow: if hex.is_empty() { return String::new(); } let mut out = String::with_capacity((hex.len() / 2) - 1); for pair in hex.as_bytes().chunks(2) { if !out.is_empty() { out.push(':'); } out.push_str(unsafe { std::str::from_utf8_unchecked(pair) }); } out