19 lines
362 B
Go
19 lines
362 B
Go
package main
|
|
|
|
import (
|
|
"github.com/zeebo/bencode"
|
|
)
|
|
|
|
type TorrentMetadata struct {
|
|
Info bencode.RawMessage `bencode:"info"`
|
|
}
|
|
|
|
func getTorrentInfoHash(torrent []byte) (string, error) {
|
|
torrentMetadata := &TorrentMetadata{}
|
|
if err := bencode.DecodeBytes(torrent, torrentMetadata); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return toSha1(torrentMetadata.Info), nil
|
|
}
|