Add IcalinguaSinger struct and client module

This commit is contained in:
shenjack 2023-12-11 01:17:25 +08:00
parent 29c43e64e6
commit ec399233cc
Signed by: shenjack
GPG Key ID: 7B1134A979775551
2 changed files with 28 additions and 0 deletions

26
ica-rs/src/client.rs Normal file
View File

@ -0,0 +1,26 @@
use ed25519_dalek::{Signature, Signer, SigningKey};
use rust_socketio::{ClientBuilder, Event, Payload, RawClient};
pub struct IcalinguaSinger {
pub host: String,
pub pub_key: SigningKey,
}
impl IcalinguaSinger {
pub fn new(host: String, pub_key: &str) -> Self {
let array_key: [u8; 32] = hex::decode(pub_key).unwrap().try_into().unwrap();
let signing_key: SigningKey = SigningKey::from_bytes(&array_key);
Self {
host,
pub_key: signing_key,
}
}
pub fn sign_for_salt(&self, salt: String) -> Vec<u8> {
let salt: Vec<u8> = hex::decode(salt).unwrap();
let signature: Signature = self.pub_key.sign(salt.as_slice());
signature.to_bytes().to_vec()
}
}

View File

@ -1,3 +1,5 @@
mod client;
use ed25519_dalek::{Signature, Signer, SigningKey};
use rust_socketio::{ClientBuilder, Payload, RawClient, Event};
use std::time::Duration;