Furrent
Typedefs | Enumerations | Functions
fur::hash Namespace Reference

Typedefs

using hash_t = std::array< uint8_t, 20 >
 Type for a SHA1 hash. More...
 

Enumerations

enum  HashError { HashError::MalformedPieceHashesString, HashError::PieceHashesStringTooLarge }
 

Functions

std::string error_to_string (HashError error)
 Function to translate an HashError to a string. More...
 
std::string hash_to_str (const hash_t &hash)
 
std::string hash_to_hex (const hash_t &hash)
 Returns an hex string for the provided hash. More...
 
hash_t compute_info_hash (const std::string &bencoded_info_dict)
 Computes the info hash given a bencoded string for the .torrent info dict. More...
 
util::Result< std::vector< hash_t >, HashErrorsplit_piece_hashes (const std::string &piece_hashes_str)
 
bool verify_piece (const std::vector< uint8_t > &piece, hash_t hash)
 Checks that a downloaded piece matches the provided hash. More...
 

Typedef Documentation

◆ hash_t

using fur::hash::hash_t = typedef std::array<uint8_t, 20>

Type for a SHA1 hash.

Enumeration Type Documentation

◆ HashError

enum fur::hash::HashError
strong
Enumerator
MalformedPieceHashesString 
PieceHashesStringTooLarge 

Function Documentation

◆ compute_info_hash()

hash_t fur::hash::compute_info_hash ( const std::string &  bencoded_info_dict)

Computes the info hash given a bencoded string for the .torrent info dict.

◆ error_to_string()

std::string fur::hash::error_to_string ( const HashError  error)

Function to translate an HashError to a string.

◆ hash_to_hex()

std::string fur::hash::hash_to_hex ( const hash_t hash)

Returns an hex string for the provided hash.

◆ hash_to_str()

std::string fur::hash::hash_to_str ( const hash_t hash)

Encodes an hash to a string. Note that we're forcing the compiler to make "char" unsigned so a string can contain arbitrary bytes

◆ split_piece_hashes()

util::Result< std::vector< hash_t >, HashError > fur::hash::split_piece_hashes ( const std::string &  pieces)

Takes a string with the hashes of pieces from a torrent file and parses them into a vector of "hash_t". Each hash is 20 bytes long

◆ verify_piece()

bool fur::hash::verify_piece ( const std::vector< uint8_t > &  piece,
hash_t  hash 
)

Checks that a downloaded piece matches the provided hash.