-
Notifications
You must be signed in to change notification settings - Fork 1
/
sha1.tcl
44 lines (36 loc) · 895 Bytes
/
sha1.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! /usr/bin/env tclsh
proc sha1::sha1 args {
set outputmode "hex"
if {[lindex $args 0] == "-hex"} {
set outputmode "hex"
set args [lrange $args 1 end]
} elseif {[lindex $args 0] == "-bin"} {
set outputmode "binary"
set args [lrange $args 1 end]
}
if {[llength $args] == 2} {
set mode [lindex $args 0]
} elseif {[llength $args] == 1} {
set mode "-string"
} else {
return -code error "wrong # args: sha1::sha1 ?-bin|-hex? ?-channel channel|-file file|string?"
}
switch -- $mode {
"-channel" {
return -code error "Not implemented"
}
"-file" {
set output [_sha1_file [lindex $args end]]
}
"-string" {
set output [_sha1_string [lindex $args end]]
}
default {
return -code error "invalid mode: $mode, must be one of -channel or -file (or a plain string)"
}
}
if {$outputmode == "hex"} {
binary scan $output H* output
}
return $output
}