[pmg-devel] [PATCH proxmox 3/6] tfa: let OriginUrl deref to its inner Url, add FromStr impl

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Nov 26 14:55:21 CET 2021


Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 proxmox-tfa/src/api/webauthn.rs | 35 +++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/proxmox-tfa/src/api/webauthn.rs b/proxmox-tfa/src/api/webauthn.rs
index 6453808..486e4f5 100644
--- a/proxmox-tfa/src/api/webauthn.rs
+++ b/proxmox-tfa/src/api/webauthn.rs
@@ -1,14 +1,13 @@
 //! Webauthn configuration and challenge data.
 
+use anyhow::Error;
 use serde::{Deserialize, Serialize};
+use url::Url;
+use webauthn_rs::proto::{COSEKey, Credential, CredentialID, UserVerificationPolicy};
 
 #[cfg(feature = "api-types")]
 use proxmox_schema::{api, Updater, UpdaterType};
 
-use url::Url;
-
-use webauthn_rs::proto::{COSEKey, Credential, CredentialID, UserVerificationPolicy};
-
 use super::IsExpired;
 
 #[derive(Clone, Deserialize, Serialize)]
@@ -20,6 +19,34 @@ impl UpdaterType for OriginUrl {
     type Updater = Option<Self>;
 }
 
+impl std::str::FromStr for OriginUrl {
+    type Err = Error;
+
+    fn from_str(s: &str) -> Result<Self, Error> {
+        Ok(Self(s.parse()?))
+    }
+}
+
+impl std::ops::Deref for OriginUrl {
+    type Target = Url;
+
+    fn deref(&self) -> &Url {
+        &self.0
+    }
+}
+
+impl std::ops::DerefMut for OriginUrl {
+    fn deref_mut(&mut self) -> &mut Url {
+        &mut self.0
+    }
+}
+
+impl Into<String> for OriginUrl {
+    fn into(self) -> String {
+        self.0.into()
+    }
+}
+
 #[cfg_attr(feature = "api-types", api(
     properties: {
         rp: { type: String },
-- 
2.30.2





More information about the pmg-devel mailing list