Tcl Library Source Code

Check-in [aa67a2cdc0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make sha module compatible with channels that issue only one event each time the end of the channel is reached.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: aa67a2cdc00ad89d47f3b800872ab12ddeeb9c50d2f7c4ddf01d34fcdb970683
User & Date: pooryorick 2019-04-29 10:04:28.807
References
2019-05-06
22:53
sha1: sha1, sha256 Bugfixes - (original commit, and now) Version bump. sha256 1.0.4 sha1 2.0.4 Fixed testsuite issues introduced by commit [aa67a2cdc0]. The switch from `rename` to `interp alias` to activate an implementation was not compensated for in the code doing the deactivation just a few lines higher. check-in: 885b50ec5e user: aku tags: trunk
Context
2019-05-06
01:49
math::quasirandom - Fix testsuite setup - Requirements are 8.5+OO check-in: d898baf8e5 user: aku tags: trunk
2019-04-29
10:04
Make sha module compatible with channels that issue only one event each time the end of the channel is reached. check-in: aa67a2cdc0 user: pooryorick tags: trunk
2019-04-26
12:43
coroutine properly quote coroutine name check-in: 3bea76f022 user: pooryorick tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to modules/sha1/sha1.tcl.
640
641
642
643
644
645
646


647
648
649
650
651
652
653
654
655
656
657
658
659
# -------------------------------------------------------------------------

# fileevent handler for chunked file hashing.
#
proc ::sha1::Chunk {token channel {chunksize 4096}} {
    upvar #0 $token state
    


    if {[eof $channel]} {
        fileevent $channel readable {}
        set state(reading) 0
    }
        
    SHA1Update $token [read $channel $chunksize]
}

# -------------------------------------------------------------------------

proc ::sha1::sha1 {args} {
    array set opts {-hex 0 -filename {} -channel {} -chunksize 4096}
    if {[llength $args] == 1} {







>
>





<







640
641
642
643
644
645
646
647
648
649
650
651
652
653

654
655
656
657
658
659
660
# -------------------------------------------------------------------------

# fileevent handler for chunked file hashing.
#
proc ::sha1::Chunk {token channel {chunksize 4096}} {
    upvar #0 $token state
    
    SHA1Update $token [read $channel $chunksize]

    if {[eof $channel]} {
        fileevent $channel readable {}
        set state(reading) 0
    }
        

}

# -------------------------------------------------------------------------

proc ::sha1::sha1 {args} {
    array set opts {-hex 0 -filename {} -channel {} -chunksize 4096}
    if {[llength $args] == 1} {
Changes to modules/sha1/sha256.tcl.
27
28
29
30
31
32
33

34
35
36
37
38
39
40
namespace eval ::sha2 {
    variable  accel
    array set accel {tcl 0 critcl 0}
    variable  loaded {}

    namespace export sha256 hmac \
            SHA256Init SHA256Update SHA256Final


    variable uid
    if {![info exists uid]} {
        set uid 0
    }

    variable K







>







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
namespace eval ::sha2 {
    variable  accel
    array set accel {tcl 0 critcl 0}
    variable  loaded {}

    namespace export sha256 hmac \
            SHA256Init SHA256Update SHA256Final


    variable uid
    if {![info exists uid]} {
        set uid 0
    }

    variable K
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

    if {![string equal $key ""]} {
        foreach c {
            SHA256Init   SHA224Init
            SHA256Final  SHA224Final
            SHA256Update
        } {
            rename ::sha2::${c}-${key} ::sha2::$c
        }
    }

    # Remember the active implementation, for deactivation by future
    # switches.

    set loaded $key







|







184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

    if {![string equal $key ""]} {
        foreach c {
            SHA256Init   SHA224Init
            SHA256Final  SHA224Final
            SHA256Update
        } {
	    interp alias {} ::sha2::$c {} ::sha2::${c}-${key}
        }
    }

    # Remember the active implementation, for deactivation by future
    # switches.

    set loaded $key
655
656
657
658
659
660
661


662
663
664
665
666
667
668
669
670
671
672
673
674
# -------------------------------------------------------------------------

# fileevent handler for chunked file hashing.
#
proc ::sha2::Chunk {token channel {chunksize 4096}} {
    upvar #0 $token state
    


    if {[eof $channel]} {
        fileevent $channel readable {}
        set state(reading) 0
    }
        
    SHA256Update $token [read $channel $chunksize]
}

# -------------------------------------------------------------------------

proc ::sha2::_sha256 {ver args} {
    array set opts {-hex 0 -filename {} -channel {} -chunksize 4096}
    if {[llength $args] == 1} {







>
>




|
<







656
657
658
659
660
661
662
663
664
665
666
667
668
669

670
671
672
673
674
675
676
# -------------------------------------------------------------------------

# fileevent handler for chunked file hashing.
#
proc ::sha2::Chunk {token channel {chunksize 4096}} {
    upvar #0 $token state
    
    SHA256Update $token [read $channel $chunksize]

    if {[eof $channel]} {
        fileevent $channel readable {}
        set state(reading) 0
    }
	return

}

# -------------------------------------------------------------------------

proc ::sha2::_sha256 {ver args} {
    array set opts {-hex 0 -filename {} -channel {} -chunksize 4096}
    if {[llength $args] == 1} {
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709

    if {$opts(-filename) != {}} {
        set opts(-channel) [open $opts(-filename) r]
        fconfigure $opts(-channel) -translation binary
    }

    if {$opts(-channel) == {}} {

        if {[llength $args] != 1} {
            return -code error "wrong # args: should be\
                \"[namespace current]::sha$ver ?-hex|-bin? -filename file\
                | -channel channel | string\""
        }
        set tok [SHA${ver}Init]
        SHA${ver}Update $tok [lindex $args 0]







<







697
698
699
700
701
702
703

704
705
706
707
708
709
710

    if {$opts(-filename) != {}} {
        set opts(-channel) [open $opts(-filename) r]
        fconfigure $opts(-channel) -translation binary
    }

    if {$opts(-channel) == {}} {

        if {[llength $args] != 1} {
            return -code error "wrong # args: should be\
                \"[namespace current]::sha$ver ?-hex|-bin? -filename file\
                | -channel channel | string\""
        }
        set tok [SHA${ver}Init]
        SHA${ver}Update $tok [lindex $args 0]