tester and esp32 create signed timestamp for auth

This commit is contained in:
Evan Feenstra
2022-09-16 12:30:33 -07:00
parent 5de335c797
commit aeb48e36c3
8 changed files with 48 additions and 40 deletions

View File

@@ -1,6 +1,7 @@
use anyhow::Result;
use sphinx_auther::nonce;
use sphinx_auther::secp256k1::{PublicKey, SecretKey};
use sphinx_auther::token::Token;
pub use sphinx_glyph::types::{Config, ControlMessage, ControlResponse, Interval, Policy};
use std::sync::{Arc, Mutex};
@@ -21,6 +22,16 @@ impl Controller {
let nonce = store.read_nonce().unwrap_or(0);
Self(sk, pk, nonce, per)
}
pub fn make_auth_token(&self) -> Result<String> {
let t = Token::new();
Ok(t.sign_to_base64(&self.0)?)
}
pub fn pubkey(&self) -> PublicKey {
self.1
}
pub fn nonce(&self) -> u64 {
self.2
}
pub fn build_msg(&mut self, msg: ControlMessage) -> anyhow::Result<Vec<u8>> {
let data = rmp_serde::to_vec(&msg)?;
self.2 = self.2 + 1;