tfa: let OriginUrl deref to its inner Url, add FromStr impl

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2021-11-26 14:55:21 +01:00 committed by Thomas Lamprecht
parent df3e1c53d5
commit 508c1e7c85

View File

@ -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 },