Skip to content

Commit

Permalink
Added no_discard to hasher
Browse files Browse the repository at this point in the history
  • Loading branch information
EduMenges committed May 6, 2024
1 parent e208549 commit c3aa901
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
17 changes: 8 additions & 9 deletions src/crypto/hasher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#define SUPERGENIUS_SRC_HASHER_HASHER_HPP_

#include "base/blob.hpp"
#include "base/buffer.hpp"
#include "integration/IComponent.hpp"

namespace sgns::crypto {
Expand All @@ -23,58 +22,58 @@ namespace sgns::crypto {
* @return 128-bit hash value
*/
//------------ by ruymaster ----//
virtual Hash64 twox_64(gsl::span<const uint8_t> buffer) const = 0;
[[nodiscard]] virtual Hash64 twox_64( gsl::span<const uint8_t> buffer ) const = 0;

/**
* @brief twox_128 calculates 16-byte twox hash
* @param buffer source buffer
* @return 128-bit hash value
*/
//------------ by ruymaster ----//
virtual Hash128 twox_128(gsl::span<const uint8_t> buffer) const = 0;
[[nodiscard]] virtual Hash128 twox_128( gsl::span<const uint8_t> buffer ) const = 0;

/**
* @brief blake2b_128 function calculates 16-byte blake2b hash
* @param buffer source value
* @return 128-bit hash value
*/
virtual Hash128 blake2b_128(gsl::span<const uint8_t> buffer) const = 0;
[[nodiscard]] virtual Hash128 blake2b_128( gsl::span<const uint8_t> buffer ) const = 0;

/**
* @brief twox_256 calculates 32-byte twox hash
* @param buffer source buffer
* @return 256-bit hash value
*/
//---------------------
virtual Hash256 twox_256(gsl::span<const uint8_t> buffer) const = 0;
[[nodiscard]] virtual Hash256 twox_256( gsl::span<const uint8_t> buffer ) const = 0;

/**
* @brief blake2b_256 function calculates 32-byte blake2b hash
* @param buffer source value
* @return 256-bit hash value
*/
virtual Hash256 blake2b_256(gsl::span<const uint8_t> buffer) const = 0;
[[nodiscard]] virtual Hash256 blake2b_256( gsl::span<const uint8_t> buffer ) const = 0;

/**
* @brief keccak_256 function calculates 32-byte keccak hash
* @param buffer source value
* @return 256-bit hash value
*/
virtual Hash256 keccak_256(gsl::span<const uint8_t> buffer) const = 0;
[[nodiscard]] virtual Hash256 keccak_256( gsl::span<const uint8_t> buffer ) const = 0;

/**
* @brief blake2s_256 function calculates 32-byte blake2s hash
* @param buffer source value
* @return 256-bit hash value
*/
virtual Hash256 blake2s_256(gsl::span<const uint8_t> buffer) const = 0;
[[nodiscard]] virtual Hash256 blake2s_256( gsl::span<const uint8_t> buffer ) const = 0;

/**
* @brief sha2_256 function calculates 32-byte sha2-256 hash
* @param buffer source value
* @return 256-bit hash value
*/
virtual Hash256 sha2_256(gsl::span<const uint8_t> buffer) const = 0;
[[nodiscard]] virtual Hash256 sha2_256( gsl::span<const uint8_t> buffer ) const = 0;
};
} // namespace sgns::crypto

Expand Down
45 changes: 21 additions & 24 deletions src/crypto/hasher/hasher_impl.hpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@


#ifndef SUPERGENIUS_SRC_CRYPTO_HASHER_HASHER_IMPL_HPP_
#define SUPERGENIUS_SRC_CRYPTO_HASHER_HASHER_IMPL_HPP_

#include "crypto/hasher.hpp"

namespace sgns::crypto {

class HasherImpl : public Hasher {
public:
~HasherImpl() override = default;
namespace sgns::crypto
{
class HasherImpl : public Hasher
{
public:
~HasherImpl() override = default;

//-----------------------------
Hash64 twox_64(gsl::span<const uint8_t> buffer) const override;
[[nodiscard]] Hash64 twox_64( gsl::span<const uint8_t> buffer ) const override;

Hash128 twox_128(gsl::span<const uint8_t> buffer) const override;
[[nodiscard]] Hash128 twox_128( gsl::span<const uint8_t> buffer ) const override;

Hash128 blake2b_128(gsl::span<const uint8_t> buffer) const override;
//----------------------------
Hash256 twox_256(gsl::span<const uint8_t> buffer) const override;
[[nodiscard]] Hash128 blake2b_128( gsl::span<const uint8_t> buffer ) const override;

Hash256 blake2b_256(gsl::span<const uint8_t> buffer) const override;
[[nodiscard]] Hash256 twox_256( gsl::span<const uint8_t> buffer ) const override;

Hash256 keccak_256(gsl::span<const uint8_t> buffer) const override;
[[nodiscard]] Hash256 blake2b_256( gsl::span<const uint8_t> buffer ) const override;

Hash256 blake2s_256(gsl::span<const uint8_t> buffer) const override;
[[nodiscard]] Hash256 keccak_256( gsl::span<const uint8_t> buffer ) const override;

Hash256 sha2_256(gsl::span<const uint8_t> buffer) const override;
[[nodiscard]] Hash256 blake2s_256( gsl::span<const uint8_t> buffer ) const override;

std::string GetName() override
{
return "HasherImpl";
}
};
[[nodiscard]] Hash256 sha2_256( gsl::span<const uint8_t> buffer ) const override;

} // namespace sgns::hash
std::string GetName() override
{
return "HasherImpl";
}
};
}

#endif // SUPERGENIUS_SRC_CRYPTO_HASHER_HASHER_IMPL_HPP_
#endif

0 comments on commit c3aa901

Please sign in to comment.