about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2011-03-26 17:36:08 -0700
committerGraydon Hoare <graydon@mozilla.com>2011-03-26 17:36:08 -0700
commite99feabf47351a461518760e6f5f5086e11e7c17 (patch)
treef50af696d3f3432d5237654445face3543268ce4
parentac6e1131e91d27f1211e028587e5f68e2900cdd2 (diff)
Add a result_str method to std.sha1.sha1.
-rw-r--r--src/lib/sha1.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib/sha1.rs b/src/lib/sha1.rs
index b2294a3c14a..3899dddbc27 100644
--- a/src/lib/sha1.rs
+++ b/src/lib/sha1.rs
@@ -19,6 +19,9 @@ state type sha1 = state obj {
                         // until reset is called
                         fn result() -> vec[u8];
 
+                        // Same as above, just a hex-string version.
+                        fn result_str() -> str;
+
                         // Reset the sha1 state for reuse. This is called
                         // automatically during construction
                         fn reset();
@@ -259,6 +262,15 @@ fn mk_sha1() -> sha1 {
         fn result() -> vec[u8] {
             ret mk_result(st);
         }
+
+        fn result_str() -> str {
+            auto r = mk_result(st);
+            auto s = "";
+            for (u8 b in r) {
+                s += _uint.to_str(b as uint, 16u);
+            }
+            ret s;
+        }
     }
 
     auto st = rec(h = _vec.init_elt_mut[u32](0u32, digest_buf_len),