delegate certificate init to ggemini wrapper, add structs for some, tuple entities, move match_priority to gemini impl area

This commit is contained in:
yggverse 2024-11-27 21:40:44 +02:00
parent 36f07aa773
commit 053c078e11
6 changed files with 53 additions and 29 deletions

View file

@ -1,4 +1,7 @@
pub mod auth;
pub mod error;
pub use auth::Auth;
pub use error::Error;
use std::{cell::RefCell, collections::HashMap};
@ -49,23 +52,26 @@ impl Memory {
}
}
/// Get `profile_identity_gemini_id` vector match given `request`
/// Get identity match `request`
/// * [Client certificates specification](https://geminiprotocol.net/docs/protocol-specification.gmi#client-certificates)
/// * contain unspecified length priority implementation @TODO
pub fn match_priority(&self, request: &str) -> Option<i64> {
pub fn match_priority(&self, request: &str) -> Option<Auth> {
let mut result = Vec::new();
// Get all records starts with URL cached, collect length for priority
for (url, &profile_identity_gemini_id) in self.index.borrow().iter() {
if request.starts_with(url) {
result.push((profile_identity_gemini_id, url.len()))
for (scope, &profile_identity_gemini_id) in self.index.borrow().iter() {
if request.starts_with(scope) {
result.push(Auth {
profile_identity_gemini_id,
scope: scope.clone(),
})
}
}
// Sort by length desc @TODO
result.sort_by(|a, b| b.1.cmp(&a.1));
result.sort_by(|a, b| b.scope.len().cmp(&a.scope.len()));
// Get first match ID
result.first().map(|value| value.0)
// Get first copy
result.first().cloned()
}
}