Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Mar 18, 2024
1 parent 4b1f6a7 commit b06c7d3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
20 changes: 20 additions & 0 deletions hash/tiger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,23 @@ func (this Hash) NewTiger() Hash {

return this
}

// ===============


// Tiger
func (this Hash) Tiger2() Hash {
h := tiger.New2()
h.Write(this.data)

this.data = h.Sum(nil)

return this
}

// NewTiger
func (this Hash) NewTiger2() Hash {
this.hash = tiger.New2()

return this
}
28 changes: 28 additions & 0 deletions hash/tiger_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package hash

import (
"fmt"
"testing"
)

func Test_Tiger(t *testing.T) {
in := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
check := "8dcea680a17583ee502ba38a3c368651890ffbccdc49a8cc"

res := FromString(in).Tiger().ToBytes()

if fmt.Sprintf("%x", res) != check {
t.Errorf("Check Hash error, got %x, want %s", res, check)
}
}

func Test_Tiger2(t *testing.T) {
in := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
check := "ea9ab6228cee7b51b77544fca6066c8cbb5bbae6319505cd"

res := FromString(in).Tiger2().ToBytes()

if fmt.Sprintf("%x", res) != check {
t.Errorf("Check Hash error, got %x, want %s", res, check)
}
}

0 comments on commit b06c7d3

Please sign in to comment.