Furrent
hash.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <array>
4 #include <cstdint>
5 #include <string>
6 #include <vector>
7 
8 #include "util/result.hpp"
9 
10 namespace fur::hash {
11 
13 using hash_t = std::array<uint8_t, 20>;
14 
15 enum class HashError {
18 };
19 
21 std::string error_to_string(HashError error);
22 
25 std::string hash_to_str(const hash_t& hash);
26 
28 std::string hash_to_hex(const hash_t& hash);
29 
31 hash_t compute_info_hash(const std::string& bencoded_info_dict);
32 
36  const std::string& pieces);
37 
39 bool verify_piece(const std::vector<uint8_t>& piece, hash_t hash);
40 } // namespace fur::hash
fur::hash
Definition: hash.cpp:12
fur::hash::compute_info_hash
hash_t compute_info_hash(const std::string &bencoded_info_dict)
Computes the info hash given a bencoded string for the .torrent info dict.
Definition: hash.cpp:35
fur::hash::split_piece_hashes
util::Result< std::vector< hash_t >, HashError > split_piece_hashes(const std::string &piece_hashes_str)
Definition: hash.cpp:47
fur::hash::HashError::PieceHashesStringTooLarge
@ PieceHashesStringTooLarge
fur::util::Result
Used to handle errors without using exceptions.
Definition: result.hpp:18
fur::hash::verify_piece
bool verify_piece(const std::vector< uint8_t > &piece, hash_t hash)
Checks that a downloaded piece matches the provided hash.
Definition: hash.cpp:79
fur::hash::hash_t
std::array< uint8_t, 20 > hash_t
Type for a SHA1 hash.
Definition: hash.hpp:13
fur::hash::HashError
HashError
Definition: hash.hpp:15
fur::hash::error_to_string
std::string error_to_string(const HashError error)
Function to translate an HashError to a string.
Definition: hash.cpp:14
fur::hash::hash_to_hex
std::string hash_to_hex(const hash_t &hash)
Returns an hex string for the provided hash.
Definition: hash.cpp:29
fur::hash::hash_to_str
std::string hash_to_str(const hash_t &hash)
Definition: hash.cpp:25
result.hpp
fur::hash::HashError::MalformedPieceHashesString
@ MalformedPieceHashesString