[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/maint-0.3.4] Fix compilation of Rust crypto doctests



commit bfd36177c46e3348989c55bdfdacf5e694b4766b
Author: Taylor Yu <catalyst@xxxxxxxxxxxxxx>
Date:   Mon Jun 18 13:41:38 2018 -0500

    Fix compilation of Rust crypto doctests
    
    The doctests for src/rust/crypto don't compile for multiple reasons,
    including some missing exports and incorrect identifier paths.  Fixes
    bug 26415; bugfix on 0.3.4.1-alpha.
---
 changes/bug26415                |  3 +++
 src/rust/crypto/digests/sha2.rs | 24 ++++++++++++------------
 src/rust/crypto/lib.rs          | 14 +++++++-------
 3 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/changes/bug26415 b/changes/bug26415
new file mode 100644
index 000000000..497fbb736
--- /dev/null
+++ b/changes/bug26415
@@ -0,0 +1,3 @@
+  o Minor bugfixes (testing):
+    - Fix compilation of the doctests in the Rust crypto crate.  Fixes
+      bug 26415; bugfix on 0.3.4.1-alpha.
diff --git a/src/rust/crypto/digests/sha2.rs b/src/rust/crypto/digests/sha2.rs
index 1cbb6c581..62863aaa4 100644
--- a/src/rust/crypto/digests/sha2.rs
+++ b/src/rust/crypto/digests/sha2.rs
@@ -44,9 +44,9 @@ pub struct Sha256 {
 /// # Examples
 ///
 /// ```
-/// use crypto::digest::Sha256;
+/// use crypto::digests::sha2::{Sha256, Digest};
 ///
-/// let hasher: Sha256 = Sha256::default();
+/// let mut hasher: Sha256 = Sha256::default();
 /// ```
 ///
 /// # Returns
@@ -67,12 +67,12 @@ impl BlockInput for Sha256 {
 /// # Examples
 ///
 /// ```
-/// use crypto::digest::Sha256;
+/// use crypto::digests::sha2::{Sha256, Digest};
 ///
-/// let hasher: Sha256 = Sha256::default();
+/// let mut hasher: Sha256 = Sha256::default();
 ///
-/// hasher.process(b"foo");
-/// hasher.process(b"bar");
+/// hasher.input(b"foo");
+/// hasher.input(b"bar");
 /// ```
 impl Input for Sha256 {
     fn process(&mut self, msg: &[u8]) {
@@ -111,9 +111,9 @@ pub struct Sha512 {
 /// # Examples
 ///
 /// ```
-/// use crypto::digest::Sha512;
+/// use crypto::digests::sha2::{Sha512, Digest};
 ///
-/// let hasher: Sha256 = Sha512::default();
+/// let mut hasher: Sha512 = Sha512::default();
 /// ```
 ///
 /// # Returns
@@ -134,12 +134,12 @@ impl BlockInput for Sha512 {
 /// # Examples
 ///
 /// ```
-/// use crypto::digest::Sha512;
+/// use crypto::digests::sha2::{Sha512, Digest};
 ///
-/// let hasher: Sha512 = Sha512::default();
+/// let mut hasher: Sha512 = Sha512::default();
 ///
-/// hasher.process(b"foo");
-/// hasher.process(b"bar");
+/// hasher.input(b"foo");
+/// hasher.input(b"bar");
 /// ```
 impl Input for Sha512 {
     fn process(&mut self, msg: &[u8]) {
diff --git a/src/rust/crypto/lib.rs b/src/rust/crypto/lib.rs
index b4250dec3..d120635b9 100644
--- a/src/rust/crypto/lib.rs
+++ b/src/rust/crypto/lib.rs
@@ -10,18 +10,18 @@
 //! and extendable output functions.
 //!
 //! ```
-//! use crypto::digests::sha256::Sha256;
+//! use crypto::digests::sha2::*;
 //!
-//! let hasher: Sha256 = Sha256::default();
+//! let mut hasher: Sha256 = Sha256::default();
 //! let mut result: [u8; 32] = [0u8; 32];
 //!
-//! hasher.input("foo");
-//! hasher.input("bar");
-//! hasher.input("baz");
+//! hasher.input(b"foo");
+//! hasher.input(b"bar");
+//! hasher.input(b"baz");
 //!
-//! result.copy_from_slice(hasher.result().as_bytes());
+//! result.copy_from_slice(hasher.result().as_slice());
 //!
-//! assert!(result == "XXX");
+//! assert!(result == [b'X'; DIGEST256_LEN]);
 //! ```
 
 #[deny(missing_docs)]



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits