mirror of
https://github.com/v1k45/pastepass.git
synced 2025-12-23 06:15:48 +00:00
36 lines
728 B
Go
36 lines
728 B
Go
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, err := NewEncryptionKey()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
encryptedText, err := key.Encrypt(text)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Paste{
|
|
ID: randomKey(),
|
|
Text: text,
|
|
EncryptedBytes: encryptedText,
|
|
Key: key.Base64Key(),
|
|
CreatedAt: time.Now(),
|
|
ExpiresAt: expiresAt,
|
|
}, nil
|
|
}
|