Rename public_key variables to pubkey
This commit is contained in:
parent
b2067d2721
commit
d7e4e57548
12
src/drone.rs
12
src/drone.rs
|
@ -23,7 +23,7 @@ pub const DRONE_PORT: u16 = 9900;
|
||||||
pub enum DroneRequest {
|
pub enum DroneRequest {
|
||||||
GetAirdrop {
|
GetAirdrop {
|
||||||
airdrop_request_amount: u64,
|
airdrop_request_amount: u64,
|
||||||
client_public_key: PublicKey,
|
client_pubkey: PublicKey,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,16 +111,16 @@ impl Drone {
|
||||||
let tx = match req {
|
let tx = match req {
|
||||||
DroneRequest::GetAirdrop {
|
DroneRequest::GetAirdrop {
|
||||||
airdrop_request_amount,
|
airdrop_request_amount,
|
||||||
client_public_key,
|
client_pubkey,
|
||||||
} => {
|
} => {
|
||||||
info!(
|
info!(
|
||||||
"Requesting airdrop of {} to {:?}",
|
"Requesting airdrop of {} to {:?}",
|
||||||
airdrop_request_amount, client_public_key
|
airdrop_request_amount, client_pubkey
|
||||||
);
|
);
|
||||||
request_amount = airdrop_request_amount;
|
request_amount = airdrop_request_amount;
|
||||||
Transaction::new(
|
Transaction::new(
|
||||||
&self.mint_keypair,
|
&self.mint_keypair,
|
||||||
client_public_key,
|
client_pubkey,
|
||||||
airdrop_request_amount as i64,
|
airdrop_request_amount as i64,
|
||||||
last_id,
|
last_id,
|
||||||
)
|
)
|
||||||
|
@ -321,14 +321,14 @@ mod tests {
|
||||||
|
|
||||||
let bob_req = DroneRequest::GetAirdrop {
|
let bob_req = DroneRequest::GetAirdrop {
|
||||||
airdrop_request_amount: 50,
|
airdrop_request_amount: 50,
|
||||||
client_public_key: bob_pubkey,
|
client_pubkey: bob_pubkey,
|
||||||
};
|
};
|
||||||
let bob_sig = drone.send_airdrop(bob_req).unwrap();
|
let bob_sig = drone.send_airdrop(bob_req).unwrap();
|
||||||
assert!(client.poll_for_signature(&bob_sig).is_ok());
|
assert!(client.poll_for_signature(&bob_sig).is_ok());
|
||||||
|
|
||||||
let carlos_req = DroneRequest::GetAirdrop {
|
let carlos_req = DroneRequest::GetAirdrop {
|
||||||
airdrop_request_amount: 5_000_000,
|
airdrop_request_amount: 5_000_000,
|
||||||
client_public_key: carlos_pubkey,
|
client_pubkey: carlos_pubkey,
|
||||||
};
|
};
|
||||||
let carlos_sig = drone.send_airdrop(carlos_req).unwrap();
|
let carlos_sig = drone.send_airdrop(carlos_req).unwrap();
|
||||||
assert!(client.poll_for_signature(&carlos_sig).is_ok());
|
assert!(client.poll_for_signature(&carlos_sig).is_ok());
|
||||||
|
|
|
@ -48,11 +48,11 @@ impl Signature {
|
||||||
pub fn new(signature_slice: &[u8]) -> Self {
|
pub fn new(signature_slice: &[u8]) -> Self {
|
||||||
Signature(GenericArray::clone_from_slice(&signature_slice))
|
Signature(GenericArray::clone_from_slice(&signature_slice))
|
||||||
}
|
}
|
||||||
pub fn verify(&self, peer_public_key_bytes: &[u8], msg_bytes: &[u8]) -> bool {
|
pub fn verify(&self, pubkey_bytes: &[u8], msg_bytes: &[u8]) -> bool {
|
||||||
let peer_public_key = Input::from(peer_public_key_bytes);
|
let pubkey = Input::from(pubkey_bytes);
|
||||||
let msg = Input::from(msg_bytes);
|
let msg = Input::from(msg_bytes);
|
||||||
let sig = Input::from(self.0.as_slice());
|
let sig = Input::from(self.0.as_slice());
|
||||||
signature::verify(&signature::ED25519, peer_public_key, msg, sig).is_ok()
|
signature::verify(&signature::ED25519, pubkey, msg, sig).is_ok()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ extern "C" {
|
||||||
vecs: *const Elems,
|
vecs: *const Elems,
|
||||||
num: u32, //number of vecs
|
num: u32, //number of vecs
|
||||||
message_size: u32, //size of each element inside the elems field of the vec
|
message_size: u32, //size of each element inside the elems field of the vec
|
||||||
public_key_offset: u32,
|
pubkey_offset: u32,
|
||||||
signature_offset: u32,
|
signature_offset: u32,
|
||||||
signed_message_offset: u32,
|
signed_message_offset: u32,
|
||||||
signed_message_len_offset: u32,
|
signed_message_len_offset: u32,
|
||||||
|
@ -50,8 +50,8 @@ fn verify_packet(packet: &Packet) -> u8 {
|
||||||
let msg_start = TX_OFFSET + SIGNED_DATA_OFFSET;
|
let msg_start = TX_OFFSET + SIGNED_DATA_OFFSET;
|
||||||
let sig_start = TX_OFFSET + SIG_OFFSET;
|
let sig_start = TX_OFFSET + SIG_OFFSET;
|
||||||
let sig_end = sig_start + size_of::<Signature>();
|
let sig_end = sig_start + size_of::<Signature>();
|
||||||
let pub_key_start = TX_OFFSET + PUB_KEY_OFFSET;
|
let pubkey_start = TX_OFFSET + PUB_KEY_OFFSET;
|
||||||
let pub_key_end = pub_key_start + size_of::<PublicKey>();
|
let pubkey_end = pubkey_start + size_of::<PublicKey>();
|
||||||
|
|
||||||
if packet.meta.size <= msg_start {
|
if packet.meta.size <= msg_start {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -60,7 +60,7 @@ fn verify_packet(packet: &Packet) -> u8 {
|
||||||
let msg_end = packet.meta.size;
|
let msg_end = packet.meta.size;
|
||||||
signature::verify(
|
signature::verify(
|
||||||
&signature::ED25519,
|
&signature::ED25519,
|
||||||
untrusted::Input::from(&packet.data[pub_key_start..pub_key_end]),
|
untrusted::Input::from(&packet.data[pubkey_start..pubkey_end]),
|
||||||
untrusted::Input::from(&packet.data[msg_start..msg_end]),
|
untrusted::Input::from(&packet.data[msg_start..msg_end]),
|
||||||
untrusted::Input::from(&packet.data[sig_start..sig_end]),
|
untrusted::Input::from(&packet.data[sig_start..sig_end]),
|
||||||
).is_ok() as u8
|
).is_ok() as u8
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub fn request_airdrop(
|
||||||
let mut stream = TcpStream::connect(drone_addr)?;
|
let mut stream = TcpStream::connect(drone_addr)?;
|
||||||
let req = DroneRequest::GetAirdrop {
|
let req = DroneRequest::GetAirdrop {
|
||||||
airdrop_request_amount: tokens,
|
airdrop_request_amount: tokens,
|
||||||
client_public_key: *id,
|
client_pubkey: *id,
|
||||||
};
|
};
|
||||||
let tx = serialize(&req).expect("serialize drone request");
|
let tx = serialize(&req).expect("serialize drone request");
|
||||||
stream.write_all(&tx).unwrap();
|
stream.write_all(&tx).unwrap();
|
||||||
|
|
Loading…
Reference in New Issue