package storage

import (
	"crypto/sha256"
	"encoding/hex"
	"hash"
	"io"
)

type Hasher struct {
	hasher hash.Hash
}

func NewHasher() *Hasher {
	return &Hasher{
		hasher: sha256.New(),
	}
}

func (ha *Hasher) Writer() io.Writer {
	return ha.hasher
}

func (ha *Hasher) Hex() string {
	data := ha.hasher.Sum(nil)
	res := hex.EncodeToString(data)
	return "sha256:" + res
}

func (ha *Hasher) Verify(hash string) bool {
	return hash == ha.Hex()
}
