mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-04-01 01:25:32 +00:00
add client certificate api
This commit is contained in:
parent
9d240c4c37
commit
4e712260ff
6 changed files with 129 additions and 5 deletions
41
src/client/certificate/scope.rs
Normal file
41
src/client/certificate/scope.rs
Normal 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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue