1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00
pasty/internal/pastes/paste.go
2023-06-07 19:51:54 +02:00

32 lines
870 B
Go

package pastes
import "github.com/alexedwards/argon2id"
type Paste struct {
ID string `json:"id"`
Content string `json:"content"`
ModificationToken string `json:"modificationToken,omitempty"`
Created int64 `json:"created"`
Metadata map[string]any `json:"metadata"`
}
func (paste *Paste) HashModificationToken() error {
if paste.ModificationToken == "" {
return nil
}
hash, err := argon2id.CreateHash(paste.ModificationToken, argon2id.DefaultParams)
if err != nil {
return err
}
paste.ModificationToken = hash
return nil
}
func (paste *Paste) CheckModificationToken(modificationToken string) bool {
if paste.ModificationToken == "" {
return false
}
match, err := argon2id.ComparePasswordAndHash(modificationToken, paste.ModificationToken)
return err == nil && match
}