41 lines
735 B
C++
41 lines
735 B
C++
/**
|
|
* @file SHA.h
|
|
* @author apio (cloudapio.eu)
|
|
* @brief SHA256 algorithm implementation.
|
|
*
|
|
* @copyright Copyright (c) 2024, the Luna authors.
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
#include <luna/Buffer.h>
|
|
#include <luna/String.h>
|
|
|
|
/**
|
|
* @brief A class to calculate a SHA256 hash.
|
|
*
|
|
*/
|
|
class SHA256
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Add data to the hash.
|
|
*
|
|
* @param data The data to add.
|
|
* @param size The amount of bytes to add.
|
|
*/
|
|
Result<void> append(const u8* data, usize size);
|
|
|
|
/**
|
|
* @brief Calculate the final hash.
|
|
*
|
|
* @return Buffer The calculated hash.
|
|
*/
|
|
Result<Buffer> digest();
|
|
|
|
static Result<String> hash_to_string(const Buffer& buffer);
|
|
|
|
private:
|
|
Buffer m_message;
|
|
};
|