diff --git a/crypto/gopenpgp.go b/crypto/gopenpgp.go index 0e599e4..2884b31 100644 --- a/crypto/gopenpgp.go +++ b/crypto/gopenpgp.go @@ -8,13 +8,13 @@ import "sync" type GopenPGP struct { latestServerTime int64 generationOffset int64 - lock *sync.Mutex + lock *sync.RWMutex } var pgp = GopenPGP{ latestServerTime: 0, generationOffset: 0, - lock: &sync.Mutex{}, + lock: &sync.RWMutex{}, } // clone returns a clone of the byte slice. Internal function used to make sure diff --git a/crypto/time.go b/crypto/time.go index a20529b..b208d87 100644 --- a/crypto/time.go +++ b/crypto/time.go @@ -36,8 +36,8 @@ func GetTime() time.Time { // getNow returns the latest server time. func getNow() time.Time { - pgp.lock.Lock() - defer pgp.lock.Unlock() + pgp.lock.RLock() + defer pgp.lock.RUnlock() if pgp.latestServerTime == 0 { return time.Now() @@ -53,8 +53,8 @@ func getTimeGenerator() func() time.Time { // getNowKeyGenerationOffset returns the current time with the key generation offset. func getNowKeyGenerationOffset() time.Time { - pgp.lock.Lock() - defer pgp.lock.Unlock() + pgp.lock.RLock() + defer pgp.lock.RUnlock() if pgp.latestServerTime == 0 { return time.Unix(time.Now().Unix()+pgp.generationOffset, 0)