misc.go | 5 +++++ torrent_test.go | 8 ++++++++ diff --git a/misc.go b/misc.go index b96faf06573ea3d19c3e275df9ba7e2f567a5077..6b589e2490c0606fc8283aa781a44729bc1f01c8 100644 --- a/misc.go +++ b/misc.go @@ -3,6 +3,7 @@ import ( "crypto" "errors" + "fmt" "math/rand" "os" "path/filepath" @@ -30,6 +31,10 @@ ) func (ih *InfoHash) AsString() string { return string(ih[:]) +} + +func (ih *InfoHash) HexString() string { + return fmt.Sprintf("%x", ih[:]) } type piece struct { diff --git a/torrent_test.go b/torrent_test.go index eedb4beadd8a9274adb31428a41831220327d587..ffe43ca7cdd231848b94325386924ef26a875b91 100644 --- a/torrent_test.go +++ b/torrent_test.go @@ -67,3 +67,11 @@ if orig[0] != 1 { t.FailNow() } } + +func TestTorrentString(t *testing.T) { + tor := &torrent{} + s := tor.InfoHash.HexString() + if s != "0000000000000000000000000000000000000000" { + t.FailNow() + } +}