Browse Source

Fixed issue with openssl test.

Matthew Carr 2 years ago
parent
commit
0eb7d2e5c2
3 changed files with 30 additions and 6 deletions
  1. 10 0
      crates/node/Cargo.lock
  2. 1 1
      crates/node/Cargo.toml
  3. 19 5
      crates/node/src/crypto.rs

+ 10 - 0
crates/node/Cargo.lock

@@ -77,6 +77,15 @@ dependencies = [
  "openssl-sys",
 ]
 
+[[package]]
+name = "openssl-src"
+version = "111.18.0+1.1.1n"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7897a926e1e8d00219127dc020130eca4292e5ca666dd592480d72c3eca2ff6c"
+dependencies = [
+ "cc",
+]
+
 [[package]]
 name = "openssl-sys"
 version = "0.9.72"
@@ -86,6 +95,7 @@ dependencies = [
  "autocfg",
  "cc",
  "libc",
+ "openssl-src",
  "pkg-config",
  "vcpkg",
 ]

+ 1 - 1
crates/node/Cargo.toml

@@ -10,4 +10,4 @@ edition = "2018"
 serde-block-tree = { path = "../serde-block-tree" }
 serde = { version = "^1.0.136", features = ["derive"] }
 serde-big-array = { version = "^0.4.1" }
-openssl = { version = "^0.10.38" }
+openssl = { version = "^0.10.38", features = ["vendored"] }

+ 19 - 5
crates/node/src/crypto.rs

@@ -70,8 +70,9 @@ fn decrypt_in_place(_ciphertext: &mut [u8], _key: &Key) -> Result<()> {
     unimplemented!();
 }
 
+/// Tests that validate the dependencies of this module.
 #[cfg(test)]
-mod tests {
+mod dependency_tests {
     use super::*;
 
     static KEY: [u8; 32] = [
@@ -80,31 +81,44 @@ mod tests {
         0x85, 0x48,
     ];
 
+    static IV: [u8; 16] = [
+        0x60, 0xE0, 0xBE, 0x45, 0xA9, 0xAB, 0x5D, 0x99, 0x3B, 0x3A, 0x1E, 0x54, 0x18, 0xE0, 0x46,
+        0xDE,
+    ];
+
+    /// This test validates that data decrypted with the `Crypter` API matches data that was
+    /// previously encrypted using it.
     #[test]
     fn cryptor() {
-        let expected = b"We attack at the crack of noon.";
+        let expected = b"We attack at the crack of noon!";
 
         let cipher = Cipher::aes_256_cbc();
         let mut encrypter = Crypter::new(
             cipher,
             Mode::Encrypt,
             &KEY,
-            Some(&KEY)).unwrap();
+            Some(&IV)).unwrap();
         let mut ciphertext = vec![0; expected.len() + cipher.block_size()];
         let mut written = encrypter.update(expected.as_slice(), &mut ciphertext).unwrap();
         written += encrypter.finalize(&mut ciphertext[written..]).unwrap();
         ciphertext.truncate(written);
 
-        let mut actual = vec![0u8; expected.len() + cipher.block_size()];
+        let mut actual = vec![0u8; ciphertext.len() + cipher.block_size()];
         let mut decrypter = Crypter::new(
             cipher,
             Mode::Decrypt,
             &KEY,
-            Some(&KEY)).unwrap();
+            Some(&IV)).unwrap();
         let mut written = decrypter.update(&ciphertext, &mut actual).unwrap();
         written += decrypter.finalize(&mut actual[written..]).unwrap();
         actual.truncate(written);
 
         assert_eq!(expected, actual.as_slice());
     }
+}
+
+/// Tests for the code that is actually in this module.
+#[cfg(test)]
+mod tests {
+
 }