- Implemented `LessonExport` and `LessonImport` actions in the action module. - Added corresponding command parsing for lesson export and import. - Created functions to handle lesson export and import in the memory module. - Updated state management to reflect changes after lesson operations. - Introduced deferred operations for handling asynchronous tasks in the event loop. - Enhanced the tool execution context to include graduated checks for file operations. - Added OAuth support with PKCE for secure authorization flows. - Implemented a loopback server for handling OAuth redirects. - Refactored various modules to improve code organization and maintainability.
42 lines
982 B
Rust
42 lines
982 B
Rust
use base64::{Engine as _, engine::general_purpose::URL_SAFE_NO_PAD};
|
|
use sha2::{Sha256, Digest};
|
|
|
|
const VERIFIER_LENGTH: usize = 64;
|
|
|
|
pub struct CodeVerifier(String);
|
|
|
|
impl CodeVerifier {
|
|
pub fn new() -> Self {
|
|
let bytes: Vec<u8> = (0..VERIFIER_LENGTH).map(|_| rand_byte()).collect();
|
|
CodeVerifier(URL_SAFE_NO_PAD.encode(&bytes))
|
|
}
|
|
|
|
pub fn as_str(&self) -> &str {
|
|
&self.0
|
|
}
|
|
|
|
pub fn challenge(&self) -> CodeChallenge {
|
|
let mut hasher = Sha256::new();
|
|
hasher.update(self.0.as_bytes());
|
|
let digest = hasher.finalize();
|
|
CodeChallenge(URL_SAFE_NO_PAD.encode(digest))
|
|
}
|
|
}
|
|
|
|
fn rand_byte() -> u8 {
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
|
let nanos = SystemTime::now()
|
|
.duration_since(UNIX_EPOCH)
|
|
.unwrap_or_default()
|
|
.subsec_nanos();
|
|
(nanos & 0xFF) as u8
|
|
}
|
|
|
|
pub struct CodeChallenge(String);
|
|
|
|
impl CodeChallenge {
|
|
pub fn as_str(&self) -> &str {
|
|
&self.0
|
|
}
|
|
}
|