mirror of
https://github.com/v1k45/pastepass.git
synced 2026-01-05 13:07:15 +00:00
initial commit; working state
This commit is contained in:
31
db/models.go
Normal file
31
db/models.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Paste struct {
|
||||
ID string `json:"id"`
|
||||
Text string `json:"-"`
|
||||
EncryptedBytes []byte `json:"-"`
|
||||
Key string `json:"-"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
ExpiresAt time.Time `json:"expiresAt"`
|
||||
}
|
||||
|
||||
func NewEncryptedPaste(text string, expiresAt time.Time) (*Paste, error) {
|
||||
key := randomKey()
|
||||
encryptedText, err := encrypt(text, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Paste{
|
||||
ID: randomKey(),
|
||||
Text: text,
|
||||
EncryptedBytes: encryptedText,
|
||||
Key: key,
|
||||
CreatedAt: time.Now(),
|
||||
ExpiresAt: expiresAt,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user