Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
df4388e6dc
|
|||
fd33b43f31
|
@@ -16,12 +16,11 @@ import (
|
|||||||
// https://stackoverflow.com/a/18819040/1761622
|
// https://stackoverflow.com/a/18819040/1761622
|
||||||
|
|
||||||
type aesPayload struct {
|
type aesPayload struct {
|
||||||
Salt []byte `json:"s"`
|
Salt []byte `json:"s"`
|
||||||
IV []byte `json:"i"`
|
IV []byte `json:"i"`
|
||||||
Data []byte `json:"d"`
|
Data []byte `json:"d"`
|
||||||
Rounds int `json:"r"`
|
Rounds int `json:"r"`
|
||||||
Version uint `json:"v"`
|
Version uint `json:"v"`
|
||||||
Algorithm string `json:"a"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func EncryptAESSimple(password []byte, data []byte, rounds int) (string, error) {
|
func EncryptAESSimple(password []byte, data []byte, rounds int) (string, error) {
|
||||||
@@ -65,12 +64,11 @@ func EncryptAESSimple(password []byte, data []byte, rounds int) (string, error)
|
|||||||
cfb.XORKeyStream(ciphertext, combinedData)
|
cfb.XORKeyStream(ciphertext, combinedData)
|
||||||
|
|
||||||
pl := aesPayload{
|
pl := aesPayload{
|
||||||
Salt: salt,
|
Salt: salt,
|
||||||
IV: iv,
|
IV: iv,
|
||||||
Data: ciphertext,
|
Data: ciphertext,
|
||||||
Version: 1,
|
Version: 1,
|
||||||
Rounds: rounds,
|
Rounds: rounds,
|
||||||
Algorithm: "AES",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jbin, err := json.Marshal(pl)
|
jbin, err := json.Marshal(pl)
|
||||||
@@ -96,6 +94,10 @@ func DecryptAESSimple(password []byte, encText string) ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pl.Version != 1 {
|
||||||
|
return nil, errors.New("unsupported version")
|
||||||
|
}
|
||||||
|
|
||||||
key, err := scrypt.Key(password, pl.Salt, pl.Rounds, 8, 1, 32) // this is not 100% correct, rounds too low and salt is missing
|
key, err := scrypt.Key(password, pl.Salt, pl.Rounds, 8, 1, 32) // this is not 100% correct, rounds too low and salt is missing
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -43,3 +43,45 @@ type RFCTime interface {
|
|||||||
GoString() string
|
GoString() string
|
||||||
String() string
|
String() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RFCDuration interface {
|
||||||
|
Time() time.Time
|
||||||
|
Serialize() string
|
||||||
|
|
||||||
|
UnmarshalJSON(bytes []byte) error
|
||||||
|
MarshalJSON() ([]byte, error)
|
||||||
|
|
||||||
|
MarshalBinary() ([]byte, error)
|
||||||
|
UnmarshalBinary(data []byte) error
|
||||||
|
|
||||||
|
GobEncode() ([]byte, error)
|
||||||
|
GobDecode(data []byte) error
|
||||||
|
|
||||||
|
MarshalText() ([]byte, error)
|
||||||
|
UnmarshalText(data []byte) error
|
||||||
|
|
||||||
|
After(u RFCTime) bool
|
||||||
|
Before(u RFCTime) bool
|
||||||
|
Equal(u RFCTime) bool
|
||||||
|
IsZero() bool
|
||||||
|
Date() (year int, month time.Month, day int)
|
||||||
|
Year() int
|
||||||
|
Month() time.Month
|
||||||
|
Day() int
|
||||||
|
Weekday() time.Weekday
|
||||||
|
ISOWeek() (year, week int)
|
||||||
|
Clock() (hour, min, sec int)
|
||||||
|
Hour() int
|
||||||
|
Minute() int
|
||||||
|
Second() int
|
||||||
|
Nanosecond() int
|
||||||
|
YearDay() int
|
||||||
|
Sub(u RFCTime) time.Duration
|
||||||
|
Unix() int64
|
||||||
|
UnixMilli() int64
|
||||||
|
UnixMicro() int64
|
||||||
|
UnixNano() int64
|
||||||
|
Format(layout string) string
|
||||||
|
GoString() string
|
||||||
|
String() string
|
||||||
|
}
|
||||||
|
59
rfctime/seconds.go
Normal file
59
rfctime/seconds.go
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package rfctime
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"gogs.mikescher.com/BlackForestBytes/goext/timeext"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SecondsF64 time.Duration
|
||||||
|
|
||||||
|
func (d SecondsF64) Duration() time.Duration {
|
||||||
|
return time.Duration(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d SecondsF64) String() string {
|
||||||
|
return d.Duration().String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d SecondsF64) Nanoseconds() int64 {
|
||||||
|
return d.Duration().Nanoseconds()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d SecondsF64) Microseconds() int64 {
|
||||||
|
return d.Duration().Microseconds()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d SecondsF64) Milliseconds() int64 {
|
||||||
|
return d.Duration().Milliseconds()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d SecondsF64) Seconds() float64 {
|
||||||
|
return d.Duration().Seconds()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d SecondsF64) Minutes() float64 {
|
||||||
|
return d.Duration().Minutes()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d SecondsF64) Hours() float64 {
|
||||||
|
return d.Duration().Hours()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *SecondsF64) UnmarshalJSON(data []byte) error {
|
||||||
|
var secs float64 = 0
|
||||||
|
if err := json.Unmarshal(data, &secs); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*d = SecondsF64(timeext.FromSeconds(secs))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d SecondsF64) MarshalJSON() ([]byte, error) {
|
||||||
|
secs := d.Seconds()
|
||||||
|
return json.Marshal(secs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSecondsF64(t time.Duration) SecondsF64 {
|
||||||
|
return SecondsF64(t)
|
||||||
|
}
|
Reference in New Issue
Block a user