Rename PmCrypto to GopenPGP

This commit is contained in:
Daniel Huigens 2019-05-14 18:05:01 +02:00
parent 37cbb276fd
commit bb1be4a43b
19 changed files with 125 additions and 126 deletions

View file

@ -4,41 +4,41 @@ import (
"time"
)
var pmCrypto = PmCrypto{}
var pgp = GopenPGP{}
// GetPmCrypto return global PmCrypto
func GetPmCrypto() *PmCrypto {
return &pmCrypto
// GetGopenPGP return global GopenPGP
func GetGopenPGP() *GopenPGP {
return &pgp
}
// UpdateTime updates cached time
func (pm *PmCrypto) UpdateTime(newTime int64) {
pm.latestServerTime = newTime
pm.latestClientTime = time.Now()
func (pgp *GopenPGP) UpdateTime(newTime int64) {
pgp.latestServerTime = newTime
pgp.latestClientTime = time.Now()
}
// GetTimeUnix gets latest cached time
func (pm *PmCrypto) GetTimeUnix() int64 {
return pm.getNow().Unix()
func (pgp *GopenPGP) GetTimeUnix() int64 {
return pgp.getNow().Unix()
}
// GetTime gets latest cached time
func (pm *PmCrypto) GetTime() time.Time {
return pm.getNow()
func (pgp *GopenPGP) GetTime() time.Time {
return pgp.getNow()
}
func (pm *PmCrypto) getNow() time.Time {
if pm.latestServerTime > 0 && !pm.latestClientTime.IsZero() {
func (pgp *GopenPGP) getNow() time.Time {
if pgp.latestServerTime > 0 && !pgp.latestClientTime.IsZero() {
// Until is monotonic, it uses a monotonic clock in this case instead of the wall clock
extrapolate := int64(time.Until(pm.latestClientTime).Seconds())
return time.Unix(pm.latestServerTime+extrapolate, 0)
extrapolate := int64(time.Until(pgp.latestClientTime).Seconds())
return time.Unix(pgp.latestServerTime+extrapolate, 0)
}
return time.Now()
}
func (pm *PmCrypto) getTimeGenerator() func() time.Time {
func (pgp *GopenPGP) getTimeGenerator() func() time.Time {
return func() time.Time {
return pm.getNow()
return pgp.getNow()
}
}