Move shutdown sending to an event
[rust-lightning] / src / ln / peer_channel_encryptor.rs
index a20e77a17f3a7989053de518236245a20df629fd..7db33c92e47288f77d9fe12b0b43662b78600f8a 100644 (file)
@@ -7,12 +7,12 @@ use secp256k1::ecdh::SharedSecret;
 
 use crypto::digest::Digest;
 use crypto::hkdf::{hkdf_extract,hkdf_expand};
-use crypto::sha2::Sha256;
 
 use crypto::aead::{AeadEncryptor, AeadDecryptor};
 
 use util::chacha20poly1305rfc::ChaCha20Poly1305RFC;
 use util::{byte_utils,rng};
+use util::sha2::Sha256;
 
 // Sha256("Noise_XK_secp256k1_ChaChaPoly_SHA256")
 const NOISE_CK: [u8; 32] = [0x26, 0x40, 0xf5, 0x2e, 0xeb, 0xcd, 0x9e, 0x88, 0x29, 0x58, 0x95, 0x1c, 0x79, 0x42, 0x50, 0xee, 0xdb, 0x28, 0x00, 0x2c, 0x05, 0xd7, 0xdc, 0x2e, 0xa0, 0xf1, 0x95, 0x40, 0x60, 0x42, 0xca, 0xf1];
@@ -147,7 +147,7 @@ impl PeerChannelEncryptor {
 
                let mut chacha = ChaCha20Poly1305RFC::new(key, &nonce, h);
                if !chacha.decrypt(&cyphertext[0..cyphertext.len() - 16], res, &cyphertext[cyphertext.len() - 16..]) {
-                       return Err(HandleError{err: "Bad MAC", msg: Some(msgs::ErrorMessage::DisconnectPeer{})});
+                       return Err(HandleError{err: "Bad MAC", action: Some(msgs::ErrorAction::DisconnectPeer{})});
                }
                Ok(())
        }
@@ -195,11 +195,11 @@ impl PeerChannelEncryptor {
                assert_eq!(act.len(), 50);
 
                if act[0] != 0 {
-                       return Err(HandleError{err: "Unknown handshake version number", msg: Some(msgs::ErrorMessage::DisconnectPeer{})});
+                       return Err(HandleError{err: "Unknown handshake version number", action: Some(msgs::ErrorAction::DisconnectPeer{})});
                }
 
                let their_pub = match PublicKey::from_slice(secp_ctx, &act[1..34]) {
-                       Err(_) => return Err(HandleError{err: "Invalid public key", msg: Some(msgs::ErrorMessage::DisconnectPeer{})}),
+                       Err(_) => return Err(HandleError{err: "Invalid public key", action: Some(msgs::ErrorAction::DisconnectPeer{})}),
                        Ok(key) => key,
                };
 
@@ -349,14 +349,14 @@ impl PeerChannelEncryptor {
                                                        panic!("Requested act at wrong step");
                                                }
                                                if act_three[0] != 0 {
-                                                       return Err(HandleError{err: "Unknown handshake version number", msg: Some(msgs::ErrorMessage::DisconnectPeer{})});
+                                                       return Err(HandleError{err: "Unknown handshake version number", action: Some(msgs::ErrorAction::DisconnectPeer{})});
                                                }
 
                                                let mut their_node_id = [0; 33];
                                                PeerChannelEncryptor::decrypt_with_ad(&mut their_node_id, 1, &temp_k2.unwrap(), &bidirectional_state.h, &act_three[1..50])?;
                                                self.their_node_id = Some(match PublicKey::from_slice(&self.secp_ctx, &their_node_id) {
                                                        Ok(key) => key,
-                                                       Err(_) => return Err(HandleError{err: "Bad node_id from peer", msg: Some(msgs::ErrorMessage::DisconnectPeer{})}),
+                                                       Err(_) => return Err(HandleError{err: "Bad node_id from peer", action: Some(msgs::ErrorAction::DisconnectPeer{})}),
                                                });
 
                                                let mut sha = Sha256::new();