summaryrefslogtreecommitdiffhomepage
path: root/src/keypair.go
blob: ba9c4379787252215d132dc2221ca1cba7bfe40a (plain)
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
34
35
36
37
package main

import (
	"crypto/cipher"
	"sync"
	"time"
)

type KeyPair struct {
	receive      cipher.AEAD
	replayFilter ReplayFilter
	send         cipher.AEAD
	sendNonce    uint64
	isInitiator  bool
	created      time.Time
	localIndex   uint32
	remoteIndex  uint32
}

type KeyPairs struct {
	mutex    sync.RWMutex
	current  *KeyPair
	previous *KeyPair
	next     *KeyPair // not yet "confirmed by transport"
}

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

func (device *Device) DeleteKeyPair(key *KeyPair) {
	key.send = nil
	key.receive = nil
	device.indices.Delete(key.localIndex)
}