/**
 * @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/Slice.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);

    class Digest
    {
      public:
        const Slice<u8> bytes()
        {
            return { m_bytes, 32 };
        }

        Result<String> to_string();

      private:
        u8 m_bytes[32];

        friend class SHA256;
    };

    /**
     * @brief Calculate the final hash.
     *
     * @return Digest The calculated hash digest.
     */
    Result<Digest> digest();

  private:
    Buffer m_message;
};