mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 09:10:08 +00:00
update certificate match function
This commit is contained in:
parent
7ff9efb166
commit
e60a00c500
@ -37,14 +37,14 @@ impl Identity {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get `pem` record match `request` according to
|
||||
/// [Gemini protocol specification](https://geminiprotocol.net/docs/protocol-specification.gmi#client-certificates)
|
||||
/// * this function work with memory cache not database
|
||||
/// Get `pem` record match `request`
|
||||
/// * [Client certificates specification](https://geminiprotocol.net/docs/protocol-specification.gmi#client-certificates)
|
||||
/// * this function work with memory cache collected (not database)
|
||||
pub fn gemini(&self, request: &str) -> Option<String> {
|
||||
// @TODO apply protocol rules to certificate selection
|
||||
for profile_identity_gemini_id in self.gemini.auth.memory.starts_with(request) {
|
||||
if let Ok(pem) = self.gemini.memory.get(profile_identity_gemini_id) {
|
||||
return Some(pem);
|
||||
if let Some(id) = self.gemini.auth.memory.match_priority(request) {
|
||||
match self.gemini.memory.get(id) {
|
||||
Ok(pem) => return Some(pem),
|
||||
Err(_) => todo!(),
|
||||
}
|
||||
}
|
||||
None
|
||||
|
@ -39,14 +39,26 @@ impl Memory {
|
||||
self.index.borrow_mut().clear()
|
||||
} */
|
||||
|
||||
/// Search for `profile_identity_gemini_id` by `url` starts with given substring
|
||||
pub fn starts_with(&self, prefix: &str) -> Vec<i64> {
|
||||
/// Get `profile_identity_gemini_id` vector match given `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> {
|
||||
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 url.starts_with(prefix) {
|
||||
result.push(profile_identity_gemini_id)
|
||||
if request.starts_with(url) {
|
||||
result.push((profile_identity_gemini_id, url.len()))
|
||||
}
|
||||
}
|
||||
result
|
||||
|
||||
// Sort by length desc @TODO
|
||||
result.sort_by(|a, b| b.1.cmp(&a.1));
|
||||
|
||||
// Get first match ID
|
||||
match result.get(0) {
|
||||
Some(value) => Some(value.0),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user