about summary refs log tree commit homepage
path: root/t/bin/sha1sum.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-02-17 18:53:52 -0800
committerEric Wong <normalperson@yhbt.net>2010-02-17 18:53:52 -0800
commit5cef71dc6c640db414c41f59a5016fd3f5326bf9 (patch)
tree500cd48b0d92ba8b847ce6839d6889d5304fa11b /t/bin/sha1sum.rb
parent13598f977ec3b707bd1a8f2abb99825cb8f85b58 (diff)
downloadunicorn-5cef71dc6c640db414c41f59a5016fd3f5326bf9.tar.gz
Diffstat (limited to 't/bin/sha1sum.rb')
-rwxr-xr-xt/bin/sha1sum.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/t/bin/sha1sum.rb b/t/bin/sha1sum.rb
new file mode 100755
index 0000000..b602e79
--- /dev/null
+++ b/t/bin/sha1sum.rb
@@ -0,0 +1,23 @@
+#!/usr/bin/env ruby
+# -*- encoding: binary -*-
+
+# Reads from stdin and outputs the SHA1 hex digest of the input this is
+# ONLY used as a last resort, our test code will try to use sha1sum(1),
+# openssl(1), or gsha1sum(1) before falling back to using this.  We try
+# all options first because we have a strong and healthy distrust of our
+# Ruby abilities in general, and *especially* when it comes to
+# understanding (and trusting the implementation of) Ruby 1.9 encoding.
+
+require 'digest/sha1'
+$stdout.sync = $stderr.sync = true
+$stdout.binmode
+$stdin.binmode
+bs = 16384
+digest = Digest::SHA1.new
+if buf = $stdin.read(bs)
+  begin
+    digest.update(buf)
+  end while $stdin.read(bs, buf)
+end
+
+$stdout.syswrite("#{digest.hexdigest}\n")