add client certificate api

This commit is contained in:
yggverse 2024-11-27 18:03:22 +02:00
parent 9d240c4c37
commit 4e712260ff
6 changed files with 129 additions and 5 deletions

View file

@ -0,0 +1,41 @@
pub mod error;
pub use error::Error;
use glib::{GString, Uri, UriFlags, UriHideFlags};
/// Scope implement path prefix to apply TLS authorization for
/// * https://geminiprotocol.net/docs/protocol-specification.gmi#status-60
pub struct Scope {
uri: Uri,
}
impl Scope {
// Constructors
/// Create new `Self` for given `url` string
/// * check URI parts required for valid `Scope` build
pub fn from_url(url: &str) -> Result<Self, Error> {
match Uri::parse(url, UriFlags::NONE) {
Ok(uri) => {
if !uri.scheme().to_lowercase().contains("gemini") {
return Err(Error::Scheme);
}
if uri.host().is_none() {
return Err(Error::Host);
}
Ok(Self { uri })
}
Err(reason) => Err(Error::Uri(reason)),
}
}
// Getters
/// Get `Scope` string match [Specification](https://geminiprotocol.net/docs/protocol-specification.gmi#status-60)
pub fn to_string(&self) -> GString {
self.uri
.to_string_partial(UriHideFlags::QUERY | UriHideFlags::FRAGMENT)
}
}