mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 12:41:05 +08:00
Add IcalinguaSinger struct and client module
This commit is contained in:
parent
29c43e64e6
commit
ec399233cc
26
ica-rs/src/client.rs
Normal file
26
ica-rs/src/client.rs
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
|
mod client;
|
||||||
|
|
||||||
use ed25519_dalek::{Signature, Signer, SigningKey};
|
use ed25519_dalek::{Signature, Signer, SigningKey};
|
||||||
use rust_socketio::{ClientBuilder, Payload, RawClient, Event};
|
use rust_socketio::{ClientBuilder, Payload, RawClient, Event};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user