summaryrefslogtreecommitdiffstats
path: root/vendor/go.mau.fi/libsignal/state/record/UnacknowledgedPreKey.go
blob: 61fe064457709a910c75079c6147d66331158c90 (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
package record

import (
	"go.mau.fi/libsignal/ecc"
	"go.mau.fi/libsignal/util/optional"
)

// NewUnackPreKeyMessageItems returns message items that are unacknowledged.
func NewUnackPreKeyMessageItems(preKeyID *optional.Uint32, signedPreKeyID uint32,
	baseKey ecc.ECPublicKeyable) *UnackPreKeyMessageItems {

	return &UnackPreKeyMessageItems{
		preKeyID:       preKeyID,
		signedPreKeyID: signedPreKeyID,
		baseKey:        baseKey,
	}
}

// NewUnackPreKeyMessageItemsFromStruct will return a new unacknowledged prekey
// message items object from the given structure.
func NewUnackPreKeyMessageItemsFromStruct(structure *UnackPreKeyMessageItemsStructure) *UnackPreKeyMessageItems {
	baseKey, _ := ecc.DecodePoint(structure.BaseKey, 0)
	return NewUnackPreKeyMessageItems(
		structure.PreKeyID,
		structure.SignedPreKeyID,
		baseKey,
	)
}

// UnackPreKeyMessageItemsStructure is a serializable structure for unackowledged
// prekey message items.
type UnackPreKeyMessageItemsStructure struct {
	PreKeyID       *optional.Uint32
	SignedPreKeyID uint32
	BaseKey        []byte
}

// UnackPreKeyMessageItems is a structure for messages that have not been
// acknowledged.
type UnackPreKeyMessageItems struct {
	preKeyID       *optional.Uint32
	signedPreKeyID uint32
	baseKey        ecc.ECPublicKeyable
}

// PreKeyID returns the prekey id of the unacknowledged message.
func (u *UnackPreKeyMessageItems) PreKeyID() *optional.Uint32 {
	return u.preKeyID
}

// SignedPreKeyID returns the signed prekey id of the unacknowledged message.
func (u *UnackPreKeyMessageItems) SignedPreKeyID() uint32 {
	return u.signedPreKeyID
}

// BaseKey returns the ECC public key of the unacknowledged message.
func (u *UnackPreKeyMessageItems) BaseKey() ecc.ECPublicKeyable {
	return u.baseKey
}

// structure will return a serializable base structure
// for unacknowledged prekey message items.
func (u *UnackPreKeyMessageItems) structure() *UnackPreKeyMessageItemsStructure {
	return &UnackPreKeyMessageItemsStructure{
		PreKeyID:       u.preKeyID,
		SignedPreKeyID: u.signedPreKeyID,
		BaseKey:        u.baseKey.Serialize(),
	}
}