2022-08-29 16:52:21 +03:00
|
|
|
package paste
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/alexedwards/argon2id"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Paste represents a paste
|
|
|
|
type Paste struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Content string `json:"content"`
|
|
|
|
ModificationToken string `json:"modificationToken,omitempty"`
|
|
|
|
Created int64 `json:"created"`
|
|
|
|
Metadata map[string]interface{} `json:"metadata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// HashModificationToken hashes the current modification token of a paste
|
|
|
|
func (paste *Paste) HashModificationToken() error {
|
|
|
|
hash, err := argon2id.CreateHash(paste.ModificationToken, argon2id.DefaultParams)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
paste.ModificationToken = hash
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-06-07 18:46:19 +03:00
|
|
|
// CheckModificationToken checks whether the given modification token is correct
|
2022-08-29 16:52:21 +03:00
|
|
|
func (paste *Paste) CheckModificationToken(modificationToken string) bool {
|
|
|
|
match, err := argon2id.ComparePasswordAndHash(modificationToken, paste.ModificationToken)
|
|
|
|
return err == nil && match
|
|
|
|
}
|