summaryrefslogtreecommitdiffstats
path: root/vendor/go.mau.fi/libsignal/ratchet/SenderParameters.go
blob: ca972956067bc151a252a1d940351b4619108ef7 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package ratchet

import (
	"go.mau.fi/libsignal/ecc"
	"go.mau.fi/libsignal/keys/identity"
)

// NewSenderParameters creates a structure with all the keys needed to construct
// a new session when we are sending a message to a recipient for the first time.
func NewSenderParameters(ourIdentityKey *identity.KeyPair, ourBaseKey *ecc.ECKeyPair,
	theirIdentityKey *identity.Key, theirSignedPreKey ecc.ECPublicKeyable,
	theirRatchetKey ecc.ECPublicKeyable, theirOneTimePreKey ecc.ECPublicKeyable) *SenderParameters {

	senderParams := SenderParameters{
		ourIdentityKeyPair: ourIdentityKey,
		ourBaseKey:         ourBaseKey,
		theirIdentityKey:   theirIdentityKey,
		theirSignedPreKey:  theirSignedPreKey,
		theirOneTimePreKey: theirOneTimePreKey,
		theirRatchetKey:    theirRatchetKey,
	}

	return &senderParams
}

// NewEmptySenderParameters creates an empty structure with the sender parameters
// needed to create a session. You should use the `set` functions to set all the
// necessary keys needed to build a session.
func NewEmptySenderParameters() *SenderParameters {
	senderParams := SenderParameters{}

	return &senderParams
}

// SenderParameters describes the session parameters if we are sending the
// recipient a message for the first time. These parameters are used as the
// basis for deriving a shared secret with a recipient.
type SenderParameters struct {
	ourIdentityKeyPair *identity.KeyPair
	ourBaseKey         *ecc.ECKeyPair

	theirIdentityKey   *identity.Key
	theirSignedPreKey  ecc.ECPublicKeyable
	theirOneTimePreKey ecc.ECPublicKeyable
	theirRatchetKey    ecc.ECPublicKeyable
}

// OurIdentityKey returns the identity key pair of the sender.
func (s *SenderParameters) OurIdentityKey() *identity.KeyPair {
	return s.ourIdentityKeyPair
}

// OurBaseKey returns the base ECC key pair of the sender.
func (s *SenderParameters) OurBaseKey() *ecc.ECKeyPair {
	return s.ourBaseKey
}

// TheirIdentityKey returns the identity public key of the receiver.
func (s *SenderParameters) TheirIdentityKey() *identity.Key {
	return s.theirIdentityKey
}

// TheirSignedPreKey returns the signed pre key of the receiver.
func (s *SenderParameters) TheirSignedPreKey() ecc.ECPublicKeyable {
	return s.theirSignedPreKey
}

// TheirOneTimePreKey returns the receiver's one time prekey.
func (s *SenderParameters) TheirOneTimePreKey() ecc.ECPublicKeyable {
	return s.theirOneTimePreKey
}

// TheirRatchetKey returns the receiver's ratchet key.
func (s *SenderParameters) TheirRatchetKey() ecc.ECPublicKeyable {
	return s.theirRatchetKey
}

// SetOurIdentityKey sets the identity key pair of the sender.
func (s *SenderParameters) SetOurIdentityKey(ourIdentityKey *identity.KeyPair) {
	s.ourIdentityKeyPair = ourIdentityKey
}

// SetOurBaseKey sets the base ECC key pair of the sender.
func (s *SenderParameters) SetOurBaseKey(ourBaseKey *ecc.ECKeyPair) {
	s.ourBaseKey = ourBaseKey
}

// SetTheirIdentityKey sets the identity public key of the receiver.
func (s *SenderParameters) SetTheirIdentityKey(theirIdentityKey *identity.Key) {
	s.theirIdentityKey = theirIdentityKey
}

// SetTheirSignedPreKey sets the signed pre key of the receiver.
func (s *SenderParameters) SetTheirSignedPreKey(theirSignedPreKey ecc.ECPublicKeyable) {
	s.theirSignedPreKey = theirSignedPreKey
}

// SetTheirOneTimePreKey sets the receiver's one time prekey.
func (s *SenderParameters) SetTheirOneTimePreKey(theirOneTimePreKey ecc.ECPublicKeyable) {
	s.theirOneTimePreKey = theirOneTimePreKey
}

// SetTheirRatchetKey sets the receiver's ratchet key.
func (s *SenderParameters) SetTheirRatchetKey(theirRatchetKey ecc.ECPublicKeyable) {
	s.theirRatchetKey = theirRatchetKey
}