#!/usr/local/bin/python2.5

'''
sha1hash.py

Copyright 2006 Andres Riancho

This file is part of w3af, w3af.sourceforge.net .

w3af is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.

w3af is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with w3af; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

'''

import sha
import sys
import getopt
try:
	import core.controllers.outputManager as om
except:
	class om:
		class out:
			def information( str ):
				print '\r' + str
			information = staticmethod(information)

def usage():
	om.out.information('w3af - sha1 hash calculator')
	om.out.information('')
	om.out.information('Options:')
	om.out.information('	-h	Print this help message.')
	om.out.information('	-e	String to be hashed.')
	om.out.information('')
	om.out.information('Example: sha1hash -e makeHash')
	
def main():
	
	try:
		opts, args = getopt.getopt(sys.argv[1:], "he:", ["help", "encode"])
	except getopt.GetoptError:
		# print help information and exit:
		usage()
		sys.exit(2)
	encode = None
	for o, a in opts:
		if o in ("-e", "--encode"):
			encode = a
		if o in ("-h", "--help"):
			usage()
			sys.exit()

	if encode == None:
			usage()
			sys.exit()
	else:
		om.out.information( sha.new(encode).hexdigest() )
		
if __name__ == "__main__":
  main()
  
