2018-09-02 15:02:26 +02:00
|
|
|
package pmcrypto
|
2018-06-04 16:05:14 -07:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// UpdateTime update cached time
|
|
|
|
|
func (o *OpenPGP) UpdateTime(newTime int64) {
|
2018-06-04 17:50:26 -07:00
|
|
|
o.latestServerTime = newTime
|
2018-06-22 16:04:20 +02:00
|
|
|
o.latestClientTime = time.Now()
|
2018-06-04 16:05:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//GetTime get latest cached time
|
|
|
|
|
func (o *OpenPGP) GetTime() int64 {
|
2018-06-22 16:04:20 +02:00
|
|
|
return o.getNow().Unix()
|
2018-06-04 16:05:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *OpenPGP) getNow() time.Time {
|
2018-06-22 16:04:20 +02:00
|
|
|
if o.latestServerTime > 0 && !o.latestClientTime.IsZero() {
|
|
|
|
|
// Sub is monotome, it uses a monotime time clock in this case instead of the wall clock
|
|
|
|
|
extrapolate := int64(o.latestClientTime.Sub(time.Now()).Seconds())
|
|
|
|
|
return time.Unix(o.latestServerTime + extrapolate, 0)
|
2018-06-04 16:05:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return time.Now()
|
|
|
|
|
}
|
2018-06-22 16:04:20 +02:00
|
|
|
|
|
|
|
|
func (o *OpenPGP) getTimeGenerator() func() time.Time {
|
|
|
|
|
return func() time.Time {
|
|
|
|
|
return o.getNow()
|
|
|
|
|
}
|
|
|
|
|
}
|