aboutsummaryrefslogtreecommitdiff
path: root/src/keypair.go
blob: 53e123ff3b73d97c0f39217f9738242350048aad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main

import (
	"crypto/cipher"
	"sync"
)

type KeyPair struct {
	recv      cipher.AEAD
	recvNonce uint64
	send      cipher.AEAD
	sendNonce uint64
}

type KeyPairs struct {
	mutex      sync.RWMutex
	current    *KeyPair
	previous   *KeyPair
	next       *KeyPair  // not yet "confirmed by transport"
	newKeyPair chan bool // signals when "current" has been updated
}

func (kp *KeyPairs) Init() {
	kp.mutex.Lock()
	kp.newKeyPair = make(chan bool, 5)
	kp.mutex.Unlock()
}

func (kp *KeyPairs) Current() *KeyPair {
	kp.mutex.RLock()
	defer kp.mutex.RUnlock()
	return kp.current
}