From: Per Cederqvist <ced...@opera.com>
Date: Wed, 14 Mar 2012 14:34:38 +0100

Fix the compatibility function sha1 so that it reads from
stdin (and not a file with a zero-length file name) when
no argument is supplied.

[jn: adapted to also handle newer versions of OpenSSL,
 based on reports from Andreas Schwab and John Szakmeister.

 $ openssl dgst -sha1</dev/null
 da39a3ee5e6b4b0d3255bfef95601890afd80709
 $ openssl version
 OpenSSL 0.9.8o 01 Jun 2010

 $ openssl dgst -sha1 </dev/null
 (stdin)= da39a3ee5e6b4b0d3255bfef95601890afd80709
 $ openssl version
 OpenSSL 1.0.0d 8 Feb 2011
]

Signed-off-by: Per Cederqvist <ced...@opera.com>
Signed-off-by: Jonathan Nieder <jrnie...@gmail.com>
---
 os.Darwin | 7 ++++++-
 os.Linux  | 7 ++++++-
 os.SunOS  | 7 ++++++-
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/os.Darwin b/os.Darwin
index 470f5fb..3f23121 100644
--- a/os.Darwin
+++ b/os.Darwin
@@ -27,7 +27,12 @@ head_n()
 # usage: sha1 [file]
 sha1()
 {
-       openssl dgst -sha1 "$1" | sed "s,SHA1.\(.*\).= \(.*\),\2  \1,"
+       if [ $# = 1 ]
+       then
+               openssl dgst -sha1 "$1" | sed "s,SHA1.\(.*\).= \(.*\),\2  \1,"
+       else
+               openssl dgst -sha1 | sed 's,\(.*= \)*\(.*\),\2  -,'
+       fi
 }
 
 # usage: cp_a <src> <dst>
diff --git a/os.Linux b/os.Linux
index 30b9cb0..aaebf88 100644
--- a/os.Linux
+++ b/os.Linux
@@ -30,7 +30,12 @@ head_n()
 # usage: sha1 [file]
 sha1()
 {
-       sha1sum "$1"
+       if [ $# = 1 ]
+       then
+               sha1sum "$1"
+       else
+               sha1sum
+       fi
 }
 
 # usage: cp_a <src> <dst>
diff --git a/os.SunOS b/os.SunOS
index 30b9cb0..aaebf88 100644
--- a/os.SunOS
+++ b/os.SunOS
@@ -30,7 +30,12 @@ head_n()
 # usage: sha1 [file]
 sha1()
 {
-       sha1sum "$1"
+       if [ $# = 1 ]
+       then
+               sha1sum "$1"
+       else
+               sha1sum
+       fi
 }
 
 # usage: cp_a <src> <dst>
-- 
1.8.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to